]> Untitled Git - bdk/log
bdk
3 years agoFix wallet export rescan height
LLFourn [Wed, 26 Oct 2022 04:35:21 +0000 (12:35 +0800)]
Fix wallet export rescan height

It would return the latest transaction height rather than the earliest :S

3 years agoMerge bitcoindevkit/bdk#779: Add signature grinding for ECDSA signatures
Daniela Brozzoni [Mon, 17 Oct 2022 10:47:57 +0000 (11:47 +0100)]
Merge bitcoindevkit/bdk#779: Add signature grinding for ECDSA signatures

68dd6d20311b28f5c8e8c9657dce8cddae4f7aa3 Add signature grinding for ECDSA signatures (Vladimir Fomene)

Pull request description:

  ### Description

  This PR adds a new field called `allow_grinding`
  in the Signer's `SignOptions` struct that is used
  to determine whether or not to grind an ECDSA signature during the signing process.

  ### Changelog notice

  Breaking change: the BDK Signer now produces low-R signatures by default, saving one byte. If you want to preserve the original behavior, set `allow_grinding` in the `SignOptions` to `false`.

  ### Notes to the reviewers

  This PR resolves issue #695

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### New Features:

  * [ ] I've added tests for the new feature
  * [x] I've added docs for the new feature

  #### Bugfixes:

  * [ ] This pull request breaks the existing API
  * [ ] I've added tests to reproduce the issue which are now passing
  * [x] I'm linking the issue being fixed by this PR

ACKs for top commit:
  danielabrozzoni:
    ACK 68dd6d20311b28f5c8e8c9657dce8cddae4f7aa3
  rajarshimaitra:
    ACK 68dd6d20311b28f5c8e8c9657dce8cddae4f7aa3

Tree-SHA512: 6472338c611b4b32986cf66fcd313ef84f17f5b0ae9e7991ea7da47142641ab812f8b325d4d18314e1a58abe462683101160e62e2363a048fdab3f18aee4d699

3 years agoAdd signature grinding for ECDSA signatures
Vladimir Fomene [Thu, 6 Oct 2022 10:30:43 +0000 (13:30 +0300)]
Add signature grinding for ECDSA signatures

This PR adds a new field called `allow_grinding`
in the Signer's `SignOptions` struct that is used
to determine whether or not to grind an ECDSA signature
during the signing process.

3 years agoMerge bitcoindevkit/bdk#780: Update psbt_signer example to use descriptor! macro
Daniela Brozzoni [Wed, 12 Oct 2022 10:05:22 +0000 (11:05 +0100)]
Merge bitcoindevkit/bdk#780: Update psbt_signer example to use descriptor! macro

1331193800911bb8168e5d1c2689676af3c1fe86 Update psbt_signer example to use descriptor! macro (Steve Myers)

Pull request description:

  ### Description

  This is a small fix to the psbt_signer example to also use the `descriptor!` macro.

  ### Notes to the reviewers

  I also added more docs to at the beginning of the example.

  ### Changelog notice

  None

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### New Example:

  * [x] I've added docs for the new example

ACKs for top commit:
  danielabrozzoni:
    ACK 1331193800911bb8168e5d1c2689676af3c1fe86

Tree-SHA512: 602fa317313dea77bc4804abce500db33d5834625704019c6590ae6b80cf339cbaddffef667eaef2696e8e769756a2c2405c84109409ef33816db60d3df4d53d

3 years agoUpdate psbt_signer example to use descriptor! macro
Steve Myers [Mon, 10 Oct 2022 02:36:53 +0000 (21:36 -0500)]
Update psbt_signer example to use descriptor! macro

3 years agoAdd enhancement request github issue template
Steve Myers [Sat, 1 Oct 2022 15:06:34 +0000 (10:06 -0500)]
Add enhancement request github issue template

3 years agoBump version to 0.23.0
Alekos Filini [Thu, 29 Sep 2022 18:57:36 +0000 (20:57 +0200)]
Bump version to 0.23.0

3 years agoMerge bitcoindevkit/bdk#764: Use the esplora client crate
Steve Myers [Thu, 29 Sep 2022 16:42:48 +0000 (11:42 -0500)]
Merge bitcoindevkit/bdk#764: Use the esplora client crate

d7bfe68e2df270ab799d36ebf3563e178ae50c6e Fix broken nightly docs (Alekos Filini)
b11c86d074a8f56f99bd5f3af77d3b056af71de4 Rename internal esplora modules, fix docs (Alekos Filini)
b5b92248c76aeb42ac747931efd45bc2e7af5ebd Rename esplora features to -async and -blocking (Alekos Filini)
cf2bc388f22b069fc25fba482e59da6305207864 Re-export `esplora_client` (Elias Rohrer)
5baf46f84d41fb714f200a7b26170c9b77823dc1 Use the external esplora client library (Alekos Filini)

Pull request description:

  ### Description

  Use the external esplora client crate now that it's published

  ### Changelog notice

  - Start using the external esplora client crate
  - Deprecate the `use-esplora-reqwest` and `use-esplora-ureq` features in favor of `use-esplora-async` and `use-esplora-blocking`

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### New Features:

  * [ ] I've added tests for the new feature
  * [ ] I've added docs for the new feature

  #### Bugfixes:

  * [ ] This pull request breaks the existing API
  * [ ] I've added tests to reproduce the issue which are now passing
  * [ ] I'm linking the issue being fixed by this PR

ACKs for top commit:
  notmandatory:
    ACK d7bfe68e2df270ab799d36ebf3563e178ae50c6e

Tree-SHA512: 23bd47536fe6f723602cbcc51d909eb9aed28376430f4453eea832e30a587be3d312cdca993d114391132bfb39c48637030f974ab1a742f7defe44f40a82ef8b

3 years agoFix broken nightly docs
Alekos Filini [Wed, 28 Sep 2022 18:38:31 +0000 (20:38 +0200)]
Fix broken nightly docs

3 years agoRename internal esplora modules, fix docs
Alekos Filini [Thu, 29 Sep 2022 09:59:21 +0000 (11:59 +0200)]
Rename internal esplora modules, fix docs

3 years agoRename esplora features to -async and -blocking
Alekos Filini [Wed, 28 Sep 2022 17:33:22 +0000 (19:33 +0200)]
Rename esplora features to -async and -blocking

3 years agoRe-export `esplora_client`
Elias Rohrer [Wed, 10 Aug 2022 14:13:05 +0000 (16:13 +0200)]
Re-export `esplora_client`

3 years agoUse the external esplora client library
Alekos Filini [Tue, 9 Aug 2022 10:43:01 +0000 (12:43 +0200)]
Use the external esplora client library

3 years agoMerge bitcoindevkit/bdk#763: Fix `Wallet::descriptor_checksum` to actually return...
Daniela Brozzoni [Wed, 28 Sep 2022 13:20:46 +0000 (15:20 +0200)]
Merge bitcoindevkit/bdk#763: Fix `Wallet::descriptor_checksum` to actually return the checksum

af0b3698c691cd08ece9ae201cc9699f0d57acc8 Fix `Wallet::descriptor_checksum` to actually return the checksum (志宇)

Pull request description:

  ### Description

  `Wallet::descriptor_checksum` should return the checksum, not the descriptor without the checksum.

  ### Notes to the reviewers

  Please merge.

  ### Changelog notice

  Fix `Wallet::descriptor_checksum` to actually return the descriptor checksum.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### Bugfixes:

  ~* [ ] This pull request breaks the existing API~
  * [x] I've added tests to reproduce the issue which are now passing
  ~* [ ] I'm linking the issue being fixed by this PR~

ACKs for top commit:
  danielabrozzoni:
    ACK af0b3698c691cd08ece9ae201cc9699f0d57acc8 - I run the test you added with the old code, and verified that the bug was there. I then run the test (with a few more dbg!() expressions) and manually verified that the problem is fixed.
  notmandatory:
    ACK af0b3698c691cd08ece9ae201cc9699f0d57acc8

Tree-SHA512: 64a5b1f4708db6f6dcff2f6ef5e0a4c7d206e764d7602ea803c8cc002410326eb59eee770d9c91694dfbf07193ee3ff6bfe163bcbb3506cd7b2a6b59814a3e5c

3 years agoFix `Wallet::descriptor_checksum` to actually return the checksum
志宇 [Tue, 27 Sep 2022 13:56:25 +0000 (21:56 +0800)]
Fix `Wallet::descriptor_checksum` to actually return the checksum

3 years agoAdd vscode filter to gitignore
志宇 [Tue, 27 Sep 2022 12:39:23 +0000 (20:39 +0800)]
Add vscode filter to gitignore

3 years agoMerge bitcoindevkit/bdk#756: Remove genesis_block lazy initialization
Steve Myers [Mon, 26 Sep 2022 22:32:41 +0000 (17:32 -0500)]
Merge bitcoindevkit/bdk#756: Remove genesis_block lazy initialization

e6f2d029fa9708f98599c1bd4ef74d232b111c5a Remove genesis_block lazy initialization (Shobit Beltangdy)

Pull request description:

  ### Description

  This commit contains a change to address issue #752

  cargo test runs successfully.

  ### Notes to the reviewers

  Hi, newbie here learning Rust and BDK!  I've removed the lazy_static block in this commit, and when learning about lazy_static also came across something called [once_cell](https://doc.rust-lang.org/std/cell/struct.OnceCell.html), [soon to be available in stdlib](https://github.com/rust-lang/rust/issues/74465).  It's like lazy_static but faster and is not a macro.  Shall I keep the lazy_static and create an issue to switch to once_cell in the future, or remove the lazy_static (as I've done) and create an issue anyway?

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  notmandatory:
    ACK e6f2d029fa9708f98599c1bd4ef74d232b111c5a

Tree-SHA512: 528f5fdfb0d7d1f7a83869b7a0de1b25dfcfafae2671c9229cdb4e5d80d11e5578d9325b3d95555e59f5dfb4ed6304c0c112a01a56b6a596e50dd62e310c516e

3 years agoRemove genesis_block lazy initialization
Shobit Beltangdy [Sun, 18 Sep 2022 19:50:24 +0000 (12:50 -0700)]
Remove genesis_block lazy initialization

This commit contains a change to address issue #752

cargo test runs successfully.

3 years agoMerge bitcoindevkit/bdk#754: Fix the release process
Steve Myers [Mon, 26 Sep 2022 16:44:32 +0000 (11:44 -0500)]
Merge bitcoindevkit/bdk#754: Fix the release process

e1fa0b66954cc56dae055464ab5bb40b7a5043be Fix the new release process (Alekos Filini)

Pull request description:

  ### Description

  A few things I noticed while doing the 0.22 release.

  Follow-up of #544

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)

ACKs for top commit:
  notmandatory:
    ACK e1fa0b66954cc56dae055464ab5bb40b7a5043be

Tree-SHA512: 5e60e73ba1f820fc39f62b75583e1125f911e578ab7263a20636e2a995d0efa10ba1b3b66a1e03d8a2ed61e32c00b53de9d6bbdb31de94db37c79fa5acdbf483

3 years agoMerge bitcoindevkit/bdk#761: Remove redundant duplicated keys check
Daniela Brozzoni [Mon, 26 Sep 2022 12:45:28 +0000 (14:45 +0200)]
Merge bitcoindevkit/bdk#761: Remove redundant duplicated keys check

e2bf9734b16f5a0f419f1c1fc39c9773fd7e1128 Remove redundant duplicated keys check (Alekos Filini)

Pull request description:

  ### Description

  This check is redundant since it's already performed by miniscript (see https://docs.rs/miniscript/7.0.0/miniscript/miniscript/analyzable/enum.AnalysisError.html#variant.RepeatedPubkeys) and it was incorrectly failing on tr descriptors that contain duplicated keys across different taproot leaves

  Fixes #760

  ### Changelog notice

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### Bugfixes:

  * [x] This pull request breaks the existing API
  * [x] I've added tests to reproduce the issue which are now passing
  * [x] I'm linking the issue being fixed by this PR

ACKs for top commit:
  danielabrozzoni:
    Code review ACK e2bf9734b16f5a0f419f1c1fc39c9773fd7e1128 - the code looks good to me, but I didn't test manually

Tree-SHA512: 3c557d741e34abf6336c7e257867f2c6f91a4be0024317af834f08ba7c0c64557bd74b643005254c9f04e953350b104b0d4d287f0d0528134b357a4adf580f87

3 years agoMerge bitcoindevkit/bdk#730: Update compiler example to a Policy example
Alekos Filini [Mon, 26 Sep 2022 12:13:40 +0000 (14:13 +0200)]
Merge bitcoindevkit/bdk#730: Update compiler example to a Policy example

97b6fb06aa6d95d1c8cf1498cc4478d0f27423e4 Add a policy example (rajarshimaitra)
da7670801b81e3e67ff776444afc6e6b48fc10bb Update compiler example. (rajarshimaitra)

Pull request description:

  ### Description

  Fixes #729.

  There is an "unmaintained" warning in a old version of clap, which triggered the issue.

  Ideally, we should not have clap in bdk's dependency. It was only used for the `compiler.rs` example, which was a very tiny clap app compiling miniscript policies, and it wasn't really an example for bdk.

  This PR rewrites the example as a `policy.rs` which demos the BDK's Policy module and policy structures.

   - Use a `wsh(multi(2, Privkey, Pubkey))` descriptor, which has only one part private and other part public.
   - use `into_wallet_descriptor()` to turn that into a `Descriptor` and `KeyMap`.
   - Use the `KeyMap` to create a custom signer.
   - Extract the descriptor `Policy` structure from the given keymap.

   I am not very sure on how much this example is helpful. I still find it hard to read the Policy structure visually. But if Policy is something we want the user to know about descriptors and bdk wallets, this shows how to extract it for a simple multisig condition.

  Note: There is no use of `bdk::wallet` in the example. BDK uses the Policy extraction internally while transaction creation. But all these are exposed publicly, so can be used independently too.

  ### Questions:

  - Should we still have a `minscript::policy::compile()` example?  Which IIUC is very different from `bdk::policy:Policy`.  I didn't include it in this PR, because I am not sure if it fits inside bdk example categories.

   - Should we expose `extract_policy` as an wallet API? All though its possible to get policy without creating a wallet, why not let the wallet also spit one out for itself, if its useful?

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  afilini:
    ACK 97b6fb06aa6d95d1c8cf1498cc4478d0f27423e4

Tree-SHA512: 8e3719fdad308a347d22377050b2f29e02a884ff7d4e57a05a06d078de0709b5bf70bbcb1a696d1e1cdfe02cdb470e5af643da7c775b67fe318046bd6b80f440

3 years agoRemove redundant duplicated keys check
Alekos Filini [Sat, 24 Sep 2022 11:48:05 +0000 (13:48 +0200)]
Remove redundant duplicated keys check

This check is redundant since it's already performed by miniscript (see
https://docs.rs/miniscript/7.0.0/miniscript/miniscript/analyzable/enum.AnalysisError.html#variant.RepeatedPubkeys)
and it was incorrectly failing on tr descriptors that contain duplicated
keys across different taproot leaves

Fixes #760

3 years agoMerge bitcoindevkit/bdk#713: Add datatype for is_spent sqlite column
Alekos Filini [Fri, 23 Sep 2022 10:08:06 +0000 (12:08 +0200)]
Merge bitcoindevkit/bdk#713: Add datatype for is_spent sqlite column

54d768412abf218d2646aba211bb79b9dd287118 Sqlite migrations should either succeed or fail (Vladimir Fomene)
369e17b8012df56587c10cd9ce6651908d6a4be9 Add datatype for is_spent sqlite column (Vladimir Fomene)

Pull request description:

  ### Description

  During table creation, Sqlite does not throw an error when a column datatype is not defined. In addition, the datatype provided during table creation does not put a constraint on the type of data that can be put in that column. So you can easily put a string value in an integer column. Despite this, I think it is important for us to add the datatype for clarity.

  ### Notes to the reviewers

  You can read more about how Sqlite dynamic typing [here](https://www.sqlite.org/faq.html). I have amended our `migrate` code with a new commit. The idea is to run migrations in a transaction so that they either succeed or fail. This prevents us from having the database in an inconsistent state at any point in time.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### Bugfixes:

  * [ ] This pull request breaks the existing API
  * [ ] I've added tests to reproduce the issue which are now passing
  * [ ] I'm linking the issue being fixed by this PR

ACKs for top commit:
  rajarshimaitra:
    tACK 54d768412abf218d2646aba211bb79b9dd287118
  afilini:
    ACK 54d768412abf218d2646aba211bb79b9dd287118

Tree-SHA512: bb6c0467f799ca917f8d45c6495b766352b3177fc81952fcdd678208abf092fdeae966686528a5dcb3f342d7171783274df6312a08cbef3580063e059f5f7254

3 years agoMerge bitcoindevkit/bdk#757: Enable signing taproot transactions with only `non_witne...
Alekos Filini [Fri, 23 Sep 2022 09:52:06 +0000 (11:52 +0200)]
Merge bitcoindevkit/bdk#757: Enable signing taproot transactions with only `non_witness_utxos`

5e9965fca7fb50708af0d293a9f6cd27d0c85fed Enable signing taproot transactions with only `non_witness_utxos` (Alekos Filini)

Pull request description:

  ### Description

  Some wallets may only specify the `non_witness_utxo` for a PSBT input. If that's the case, BDK should still be able to sign.

  This was pointed out in the discussion of #734

  ### Changelog notice

  - Enable signing taproot transactions that only specify the `non_witness_utxo`

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### Bugfixes:

  * [ ] This pull request breaks the existing API
  * [x] I've added tests to reproduce the issue which are now passing
  * [x] I'm linking the issue being fixed by this PR

ACKs for top commit:
  danielabrozzoni:
    tACK 5e9965fca7fb50708af0d293a9f6cd27d0c85fed - the code looks good to me, I played around with the test you provided (inspecting the PSBT, adding/removing the witness and non-witness utxos, etc) and everything works as expected.

Tree-SHA512: 2f205286263bfee4c76de8e8c81ae1349b1c3b255b72045488f8d629c05cab64c6f775307e831674dc036e5a3a760f95d9cdc1beaf48afb4c475aee838131a33

3 years agoMerge bitcoindevkit/bdk#745: Add tests to improve coverage
Daniela Brozzoni [Thu, 22 Sep 2022 11:02:18 +0000 (13:02 +0200)]
Merge bitcoindevkit/bdk#745: Add tests to improve coverage

e65edbf53cb14e273ff99ed0576843dd3367385d Change parameter name of database in test funcs (Vladimir Fomene)
88307045b0f049b7f6b9c0cdc577c4a4bb3a041e Add more test to the database module (Vladimir Fomene)
e06c3f945ca5de4ce4f78bc2179c00e42d0bb4e5 Set tx field to none if `include_raw` is false (Vladimir Fomene)

Pull request description:

  ### Description

  This PR add more test to the database module and also fixes certain bugs discovered by the written test. I also amended the name used for the database parameter in the test functions.

  ### Notes to the reviewers

  This contributes to fixing #699

  ### Changelog notice

  <!-- Notice the release manager should include in the release tag message changelog -->
  <!-- See https://keepachangelog.com/en/1.0.0/ for examples -->

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  rajarshimaitra:
    tACK e65edbf53cb14e273ff99ed0576843dd3367385d
  danielabrozzoni:
    Code review ACK e65edbf53cb14e273ff99ed0576843dd3367385d

Tree-SHA512: 1ac1475f7d63f25e94ef21342e6f6e243c34c8c9208d11a5492f224026055da2a96f20be83497c1ba361effff9861f4e68920f98feebaf4b201d205c7030c282

3 years agoEnable signing taproot transactions with only `non_witness_utxos`
Alekos Filini [Mon, 19 Sep 2022 08:54:55 +0000 (10:54 +0200)]
Enable signing taproot transactions with only `non_witness_utxos`

Some wallets may only specify the `non_witness_utxo` for a PSBT input.
If that's the case, BDK should still be able to sign.

This was pointed out in the discussion of #734

3 years agoSqlite migrations should either succeed or fail
Vladimir Fomene [Thu, 1 Sep 2022 10:27:09 +0000 (13:27 +0300)]
Sqlite migrations should either succeed or fail

The current implementation of the `migrate` method for
Sqlite database does not rollback changes when there is
an error while running one of the migration scripts. This
can leave the database in an inconsistent state. This
change ensures that migrations either succeed completely
or fail.

3 years agoAdd a policy example
rajarshimaitra [Fri, 2 Sep 2022 09:56:21 +0000 (15:26 +0530)]
Add a policy example

Add a new policy example demonstrating the bdk's policy structure
and how to derive it for any descriptor without creating a bdk wallet.

3 years agoUpdate compiler example.
rajarshimaitra [Sun, 21 Aug 2022 12:13:14 +0000 (17:43 +0530)]
Update compiler example.

Change the compiler clap app into a specific example. Add comment docs
and example description. Remove clap from dependency.

3 years agoFix the new release process
Alekos Filini [Thu, 1 Sep 2022 13:53:08 +0000 (15:53 +0200)]
Fix the new release process

3 years agoMerge bitcoindevkit/bdk#753: Improve docs regarding PSBT finalization
Alekos Filini [Thu, 15 Sep 2022 14:16:09 +0000 (16:16 +0200)]
Merge bitcoindevkit/bdk#753: Improve docs regarding PSBT finalization

8963e8c9f445f4069262edffd15cbd971c0adc6b Improve docs w.r.t. PSBT finalization (Elias Rohrer)

Pull request description:

  ### Description

  This PR includes just a few tiny changes to the docs trying to make it a bit more clear what PSBT finalization is and what to expect.

  ### Notes to the reviewers

  ### Changelog notice

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  afilini:
    ACK 8963e8c9f445f4069262edffd15cbd971c0adc6b

Tree-SHA512: ea1a6c715c2832cdf3a428654fb8fad08a0549e46a808ca7a424590145fc2c40164ea08eb636ce5cd648dd6335480accd1d91f9e37e9397feaf0dac2015e8baa

3 years agoImprove docs w.r.t. PSBT finalization
Elias Rohrer [Thu, 15 Sep 2022 12:32:10 +0000 (14:32 +0200)]
Improve docs w.r.t. PSBT finalization

3 years agoMerge bitcoindevkit/bdk#728: Add fee_amount() and fee_rate() functions to PsbtUtils...
Alekos Filini [Tue, 13 Sep 2022 16:30:44 +0000 (18:30 +0200)]
Merge bitcoindevkit/bdk#728: Add fee_amount() and fee_rate() functions to PsbtUtils trait

ab41679368be79e8645915b40be554cc07557931 Add fee_amount() and fee_rate() functions to PsbtUtils trait (Steve Myers)

Pull request description:

  ### Description

  The purpose of the PR is to provide a more convenient way to calculate the transaction fee amount and fee rate for a PSBT. This PR adds `fee_amount` and `fee_rate` functions to the existing `PsbtUtils` trait and implements them for `PartiallySignedBitcoinTransaction`. The `fee_rate` value is only valid if the PSBT it is called on is fully signed and finalized.

  See related discussion: https://github.com/bitcoindevkit/bdk-ffi/issues/179

  ### Changelog

  Added
  - PsbtUtils.fee_amount(), calculates the PSBT total transaction fee amount in Sats.
  - PsbtUtils.fee_rate(), calculates the PSBT FeeRate, the value is only accurate AFTER the PSBT is finalized.

  ### Notes to the reviewers

  Ideally I'd like `fee_rate` to return an `Option` and return `None` if the PSBT isn't finalized. But I'm not quite sure how to determine if a PSBT is finalized without having a `Wallet` and running it through the finalize code first. Or there might be a way to fill in missing signatures with properly sized fake data prior to calculating the fee rate. For now I think it's enough to do this simple approach with usage warning in the rust docs.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### New Features:

  * [x] I've added tests for the new feature
  * [x] I've added docs for the new feature

ACKs for top commit:
  afilini:
    ACK ab41679368be79e8645915b40be554cc07557931

Tree-SHA512: 5386109c9ffcf63160f18b4c51eb2c582f4121b669c7276aaba489d186cf9b97343d46f887469b1407ccd7a24448b5e7aee4c6832d86768239b21f4e68054a0f

3 years agoMerge bitcoindevkit/bdk#744: Add psbt_signer.rs example
Alekos Filini [Tue, 13 Sep 2022 16:24:21 +0000 (18:24 +0200)]
Merge bitcoindevkit/bdk#744: Add psbt_signer.rs example

fa998de4b1849adcf43351dbec05b3de43e6694e Add psbt_signer.rs example (Steve Myers)

Pull request description:

  ### Description

  Adding a simple example of how to create a PSBT with a watch only wallet and then sign it with a signing wallet.

  ### Notes to the reviewers

  This example was inspired by a question from a user.

  ### Changelog notice

  none.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### New Features:

  * [ ] I've added tests for the new feature
  * [ ] I've added docs for the new feature

  #### Bugfixes:

  * [ ] This pull request breaks the existing API
  * [ ] I've added tests to reproduce the issue which are now passing
  * [ ] I'm linking the issue being fixed by this PR

ACKs for top commit:
  danielabrozzoni:
    ACK fa998de4b1849adcf43351dbec05b3de43e6694e
  afilini:
    ACK fa998de4b1849adcf43351dbec05b3de43e6694e

Tree-SHA512: 2e178ee59ce94eb1e9b5616a499e106e1d2843589036bdb6cff2c987e280588ad9989b026cdbf01290cc60f02eccbc410a3e1d1cd45eb4b8ff04353ae31b23ea

3 years agoChange parameter name of database in test funcs
Vladimir Fomene [Tue, 13 Sep 2022 12:50:24 +0000 (15:50 +0300)]
Change parameter name of database in test funcs

Change parameter name in database test functions
from `tree` to `db`.

3 years agoAdd more test to the database module
Vladimir Fomene [Wed, 7 Sep 2022 17:45:22 +0000 (20:45 +0300)]
Add more test to the database module

This PR aims to add more test to database
code so that we can catch bugs as soon
as they occur. Contributing to fixing
issue #699.

3 years agoSet tx field to none if `include_raw` is false
Vladimir Fomene [Tue, 13 Sep 2022 08:08:03 +0000 (11:08 +0300)]
Set tx field to none if `include_raw` is false

`del_tx` pulls the TransactionDetails object using
`select_transaction_details_by_txid` method which gets the transaction
details' data with a non-None transaction field even if the
`include_raw` argument is `false`. So it becomes necessary to Set
the transaction field in transactiondetails to None in `del_tx`, when
we make a call to it with `include_raw=false`.

3 years agoAdd fee_amount() and fee_rate() functions to PsbtUtils trait
Steve Myers [Sun, 21 Aug 2022 01:54:46 +0000 (20:54 -0500)]
Add fee_amount() and fee_rate() functions to PsbtUtils trait

PsbtUtils.fee_amount(), calculates the PSBT total transaction fee amount in Sats.
PsbtUtils.fee_rate(), calculates the PSBT FeeRate, the value is only accurate AFTER the PSBT is finalized.

3 years agoMerge bitcoindevkit/bdk#747: Run code coverage on every PR
Alekos Filini [Mon, 12 Sep 2022 14:39:21 +0000 (16:39 +0200)]
Merge bitcoindevkit/bdk#747: Run code coverage on every PR

aa0ea6aeff474a9934d4e9eb6e14ea1667573fc5 codecov: warn about missing features (Daniela Brozzoni)
c3a7bbb3ff936031200a7b70d5d9287f7f242513 codecov: slightly change the test features (Daniela Brozzoni)
1c4d47825b0ebc6027f04b8672ccabe83cbd8cee Run code coverage on every PR (Daniela Brozzoni)

Pull request description:

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  notmandatory:
    ACK aa0ea6aeff474a9934d4e9eb6e14ea1667573fc5
  afilini:
    ACK aa0ea6aeff474a9934d4e9eb6e14ea1667573fc5

Tree-SHA512: c2d0d9ad1e956f1c1808b46394f810939154442534241f9a023f18173910339ac236a5b6c66f78207dd2cb90a8f18000fc057b960e3354e2882c627fe1ef2c9f

3 years agocodecov: warn about missing features
Daniela Brozzoni [Sat, 10 Sep 2022 13:19:08 +0000 (15:19 +0200)]
codecov: warn about missing features

3 years agocodecov: slightly change the test features
Daniela Brozzoni [Sat, 10 Sep 2022 13:12:59 +0000 (15:12 +0200)]
codecov: slightly change the test features

- Remove default and minimal, as they are redundant
- Use lexicographic order

3 years agoRun code coverage on every PR
Daniela Brozzoni [Fri, 9 Sep 2022 13:27:31 +0000 (15:27 +0200)]
Run code coverage on every PR

In this way we can check how much of a PR is covered by the tests,
making the review process slightly easier.

3 years agoAdd psbt_signer.rs example
Steve Myers [Fri, 2 Sep 2022 15:38:19 +0000 (10:38 -0500)]
Add psbt_signer.rs example

3 years agoMerge bitcoindevkit/bdk#708: Change configs for source-base code coverage
Alekos Filini [Fri, 2 Sep 2022 14:57:14 +0000 (16:57 +0200)]
Merge bitcoindevkit/bdk#708: Change configs for source-base code coverage

0010ecd94aae49f389093cd3e8983c405049dbf5 Add badge to README (wszdexdrf)
690411722e2131f69a605a6f3b5e97911778e9ed Change configs for source-base code coverage (wszdexdrf)

Pull request description:

  ### Description

  This also changes the code coverage front end to coveralls instead of codecov, which had some issues with other changes in the PR. This will provide better and more accurate code coverage reports.

  ### Notes to the reviewers

  The tests run before generating the report are not exhaustive (not exhaustive earlier too, but I added as many as I could), and hence the report won't be 100% accurate.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  danielabrozzoni:
    ACK 0010ecd94aae49f389093cd3e8983c405049dbf5

Tree-SHA512: 04a21b7481b80287cf8a31276238b0a5958871310664363f54d53779bb2dda6f49198baaf3b5471667fa6131443b022aabd86f2e3b1cfcf5d4aacadf137a166e

3 years agoMerge bitcoindevkit/bdk#737: Update electrum-client to 0.11.0
Alekos Filini [Fri, 2 Sep 2022 14:53:08 +0000 (16:53 +0200)]
Merge bitcoindevkit/bdk#737: Update electrum-client to 0.11.0

d7163c3a976daf1b6a38884d77546a745805bd3c Update electrum-client to 0.11.0 (Alekos Filini)

Pull request description:

  ### Description

  Update electrum-client to 0.11.0

  ### Changelog notice

  - Updated `electrum-client` to `0.11.0`

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### New Features:

  * [ ] I've added tests for the new feature
  * [ ] I've added docs for the new feature
  * [x] I've updated `CHANGELOG.md`

ACKs for top commit:
  danielabrozzoni:
    utACK d7163c3a976daf1b6a38884d77546a745805bd3c

Tree-SHA512: 3be61935e2bebfc5e4b530d17b9900e3c1bd2ef377fdd18df4303de713b124d51555f48f7aff5f4c2579105e86f52480e6b3f2af9c7494cbdb1dd2a2c5b4e0da

3 years agoAdd badge to README
wszdexdrf [Mon, 29 Aug 2022 09:18:19 +0000 (14:48 +0530)]
Add badge to README

3 years agoChange configs for source-base code coverage
wszdexdrf [Sun, 7 Aug 2022 13:48:35 +0000 (19:18 +0530)]
Change configs for source-base code coverage

Also add cacheing to code coverage workflow

3 years agoBump version to 0.22.0
Alekos Filini [Thu, 1 Sep 2022 13:46:44 +0000 (15:46 +0200)]
Bump version to 0.22.0

3 years agoMerge bitcoindevkit/bdk#738: Fix docs.rs features
Alekos Filini [Wed, 31 Aug 2022 13:57:40 +0000 (15:57 +0200)]
Merge bitcoindevkit/bdk#738: Fix docs.rs features

3451d1c12e4271b6067ff246d095eb9fb1ca3bd5 Fix docs.rs features (Alekos Filini)

Pull request description:

  ### Description

  Fix docs.rs features

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### New Features:

  * [ ] I've added tests for the new feature
  * [ ] I've added docs for the new feature
  * [ ] I've updated `CHANGELOG.md`

ACKs for top commit:
  danielabrozzoni:
    utACK 3451d1c12e4271b6067ff246d095eb9fb1ca3bd5
  notmandatory:
    ACK 3451d1c12e4271b6067ff246d095eb9fb1ca3bd5

Tree-SHA512: 96dc4f816b21cf20fc2828dcfd56865f3f9add8e4aa643205879c810d09e6f2e73d6643061bf3ca98145b37e726907dedd31a145f92d6646c172a43ae2285aa8

3 years agoUpdate electrum-client to 0.11.0
Alekos Filini [Wed, 31 Aug 2022 09:21:13 +0000 (11:21 +0200)]
Update electrum-client to 0.11.0

3 years agoMerge bitcoindevkit/bdk#544: Update DEVELOPMENT_CYCLE.md to work with [patch.crates-io]
Alekos Filini [Wed, 31 Aug 2022 13:18:05 +0000 (15:18 +0200)]
Merge bitcoindevkit/bdk#544: Update DEVELOPMENT_CYCLE.md to work with [patch.crates-io]

7c57965999ca4a3d640d1dc11d7e10401abcabbf Bump version before making release branch, separate patch_release template (Steve Myers)
3d69f1c291b8d595399bfcb3ce202dca77a3f474 Update DEVELOPMENT_CYCLE.md to work with [patch.crates-io] (Steve Myers)

Pull request description:

  ### Description

  Update DEVELOPMENT_CYCLE and release instructions to make [overriding dependencies] possible for downstream projects with unreleased `bdk` versions for development and testing. Also simplifies the release process by capturing changelog information in the `pull_request_template` and recording release changelog information in the release tag message instead of in a `CHANGELOG.md` file which causes too many merge conflicts and complicates the release process.

  Fixes #536
  Fixes #496

  ### Notes to the reviewers

  The primary changes to our current release process are:

  1. Don't add `-dev` or `-rc.x` to unreleased `bdk` cargo versions because those extensions do not work with [overriding dependencies].
  2. Increment the `master` branch version as soon as a `release/MAJOR.MINOR` branch is created, the next release `release/MAJOR.MINOR` branch version with be **MAJOR.MINOR.PATCH**, and the `master` branch development version will be **MAJOR.MINOR+1.0**; either version can be used with [overriding dependencies].
  4. Remove the `bdk` version from the `src/lib.rs` file so that it doesn't need to be changed on every release, because it isn't needed in the rust docs for most developers and removing it will help simplify the release process.
  5. The new release process is now documented as a checklist in a new `release.md` github issue template.
  6. Putting changelog information in the release tag message is how the tokio project does it. ~~After this PR is merged I will replace old tags with new ones containing changelog information and then do a new PR to remove the CHANGELOG.md file.~~ After this PR is merged I don't think we need to update old tags, only rename the CHANGELOG.md file to CHANGELOG-OLD.md with a note to check tags for future change log info.

  [overriding dependencies]: https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  afilini:
    ACK 7c57965999ca4a3d640d1dc11d7e10401abcabbf

Tree-SHA512: 818e2f9bc7a629cbbb190a83b9743e8f4de49a4093beae83ed0b9c506f33e6f96b2c1e376f788536d58c46908d278bde08140f43a625515401ea1f9efdb9153f

3 years agoBump version before making release branch, separate patch_release template
Steve Myers [Tue, 30 Aug 2022 18:38:52 +0000 (13:38 -0500)]
Bump version before making release branch, separate patch_release template

3 years agoUpdate DEVELOPMENT_CYCLE.md to work with [patch.crates-io]
Steve Myers [Sat, 19 Mar 2022 02:21:09 +0000 (21:21 -0500)]
Update DEVELOPMENT_CYCLE.md to work with [patch.crates-io]

3 years agoFix docs.rs features
Alekos Filini [Mon, 29 Aug 2022 14:16:56 +0000 (16:16 +0200)]
Fix docs.rs features

3 years agoMerge bitcoindevkit/bdk#689: Add allow_dust method to TxBuilder
Daniela Brozzoni [Wed, 31 Aug 2022 08:30:48 +0000 (10:30 +0200)]
Merge bitcoindevkit/bdk#689: Add allow_dust method to TxBuilder

bfd7b2f65debe57edc5d563c071f0bfce592a8d2 Allow creating transactions with dust outputs (Liam)

Pull request description:

  We needed this for testing our wallet with dust, does this look like a reasonable feature? If so, I'll go ahead and add a test, update the changelog, etc.

ACKs for top commit:
  danielabrozzoni:
    tACK bfd7b2f65debe57edc5d563c071f0bfce592a8d2

Tree-SHA512: b467b365d8a68f5a868cc5cc88387677533e8fb0bf543bf4c7a5b984f8b28972281029a3be8d2c92cee7d6ee05c243d12af0841e7a7e1d652745567557f2bede

3 years agoAllow creating transactions with dust outputs
Liam [Fri, 29 Jul 2022 19:30:43 +0000 (15:30 -0400)]
Allow creating transactions with dust outputs

Add TxBuilder::allow_dust() that skips checking the dust limit

3 years agoMerge bitcoindevkit/bdk#682: Add a custom signer for hardware wallets
Alekos Filini [Mon, 29 Aug 2022 14:14:33 +0000 (16:14 +0200)]
Merge bitcoindevkit/bdk#682: Add a custom signer for hardware wallets

138acc3b7d137788d0518182e2167504e58ebc48 Change `populate_test_db` to not return empty input (wszdexdrf)
d6e1dd104063075f49b617786d82d29c1f9c6a0a Change CI to add test using ledger emulator (wszdexdrf)
76034772cba4d3d6fa1bdcb08977c2b9d7a157c2 Add a custom signer for hardware wallets (wszdexdrf)

Pull request description:

  Also adds a new test in CI for building and testing on a virtual
  hardware wallet.

  ### Description

  This PR would enable BDK users to sign transactions using a hardware wallet. It is just the beginning hence there are no complex features, but I hope not for long.
  I have added a test in CI for building a ledger emulator and running the new test on it. The test is similar to the one on bitcoindevkit/rust-hwi.

  ### Notes to the reviewers
  The PR is incomplete (and wouldn't work, as the rust-hwi in `cargo.toml` is pointing to a local crate, temporarily) as a small change is required in rust-hwi (https://github.com/bitcoindevkit/rust-hwi/pull/42).

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### New Features:

  * [x] I've added tests for the new feature
  * [x] I've added docs for the new feature
  * [x] I've updated `CHANGELOG.md`

ACKs for top commit:
  afilini:
    ACK 138acc3b7d137788d0518182e2167504e58ebc48

Tree-SHA512: 54337f06247829242b4dc60f733346173d957de8e9f8b80beb91304d679cfb4e0e4db722c967469265a5b6ede2bd641ba5c089760391c671995dc30de37897de

3 years agoAdd datatype for is_spent sqlite column
Vladimir Fomene [Fri, 12 Aug 2022 13:13:00 +0000 (16:13 +0300)]
Add datatype for is_spent sqlite column

Although, Sqlite column accepts
values of any type, it is
important to annotate this column
to make it easy to reason about.

3 years agoMerge bitcoindevkit/bdk#726: [bug-fix] Set the db sync height
Alekos Filini [Mon, 29 Aug 2022 08:24:33 +0000 (10:24 +0200)]
Merge bitcoindevkit/bdk#726: [bug-fix] Set the db sync height

08668ac46247d527cc53af5b6f359b1fa4e3b6aa Set the db sync height (rajarshimaitra)

Pull request description:

  <!-- You can erase any parts of this template not applicable to your Pull Request. -->

  ### Description

  Fixes #719

  Previously we weren't setting the db sync height in populate_test_db
  macro even when current height is provided.. This creates a bug that
  get_funded_wallet will return 0 balance.

  This PR fixes the populate_test_db macro and updates tests which were
  previously dependent on the unsynced wallet behavior.

  ### Notes to the reviewers

  <!-- In this section you can include notes directed to the reviewers, like explaining why some parts
  of the PR were done in a specific way -->

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### Bugfixes:

  * [x] I've added tests to reproduce the issue which are now passing
  * [x] I'm linking the issue being fixed by this PR

ACKs for top commit:
  afilini:
    ACK 08668ac46247d527cc53af5b6f359b1fa4e3b6aa

Tree-SHA512: 1dcc968e4b3551e916b450c5ff2fab6636083f104cc982eb3f7602c624382434e0170d9f0c0a356e6c9c5f834eebe5cb1365b37ef73d7b4ef15d652a364dc2ab

3 years agoChange `populate_test_db` to not return empty input
wszdexdrf [Thu, 25 Aug 2022 17:29:59 +0000 (22:59 +0530)]
Change `populate_test_db` to not return empty input

3 years agoChange CI to add test using ledger emulator
wszdexdrf [Mon, 25 Jul 2022 18:37:56 +0000 (00:07 +0530)]
Change CI to add test using ledger emulator

3 years agoAdd a custom signer for hardware wallets
wszdexdrf [Mon, 25 Jul 2022 18:37:04 +0000 (00:07 +0530)]
Add a custom signer for hardware wallets

Also add function to get funded wallet with coinbase

3 years agoMerge bitcoindevkit/bdk#678: Implement conversion for Lightning fee rate
Daniela Brozzoni [Mon, 29 Aug 2022 07:59:25 +0000 (09:59 +0200)]
Merge bitcoindevkit/bdk#678: Implement conversion for Lightning fee rate

de358f8cdc97bf685ba46cf6751443d007b9f58e Implement conversion for Lightning fee rate (Vladimir Fomene)

Pull request description:

  This PR fixes #608.

  ### Description

  Lightning denotes transaction fee rate sats / 1000 weight units and sats / 1000 vbytes.
  Here we add support for creating BDK FeeRate from lightning fee rate. We also move all FeeRate tests to
  types.rs and rename as_sat_vb to as_sat_per_vb.

  ### Notes to the reviewers

  Matt was concerned that we might round down value in fee calculation in such a way that a transaction may not be relayed because it is below Bitcoin Core's min relay fee (1 sat/vbyte). I don't think we need to worry about that because we [round up(ceil)](https://github.com/bitcoindevkit/bdk/blob/master/src/types.rs#L91) during fee calculation, we don't round down. I will love to hear what you think. Is there something I'm missing? @johncantrell97, I will appreciate your review on this one.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### New Features:

  * [x] I've added tests for the new feature
  * [x] I've added docs for the new feature
  * [x] I've updated `CHANGELOG.md`

  #### Bugfixes:

  * [ ] This pull request breaks the existing API
  * [ ] I've added tests to reproduce the issue which are now passing
  * [x] I'm linking the issue being fixed by this PR

ACKs for top commit:
  danielabrozzoni:
    ACK de358f8cdc97bf685ba46cf6751443d007b9f58e

Tree-SHA512: aaa7da8284b668d15ad9c92168c149c4b3ee0f8faee9b7eb159745d23e38835189eaf5c336da14ba9272ee07cd366718eefb8365da9ddf53014e122b6393a087

3 years agoImplement conversion for Lightning fee rate
Vladimir Fomene [Thu, 21 Jul 2022 11:58:30 +0000 (12:58 +0100)]
Implement conversion for Lightning fee rate

Lightning denotes transaction fee rate
sats / 1000 weight units and sats / 1000 vbytes.
Here we add support for creating BDK fee rate from
lightning fee rate. We also move all FeeRate test to
types.rs and rename as_sat_vb to as_sat_per_vb.

3 years agoSet the db sync height
rajarshimaitra [Thu, 25 Aug 2022 12:20:27 +0000 (17:50 +0530)]
Set the db sync height

Previously we weren't setting the db sync height in populate_test_db
macro even when current height is provided.. This creates a bug that
get_funded_wallet will return 0 balance.

This PR fixes the populate_test_db macro and updates tests which were
previously dependent on the unsynced wallet behavior.

3 years agoMerge bitcoindevkit/bdk#718: Verify signatures after signing
Alekos Filini [Thu, 25 Aug 2022 10:21:33 +0000 (12:21 +0200)]
Merge bitcoindevkit/bdk#718: Verify signatures after signing

7b1ad1b62914a26d6f445364ace4e784bb2901c2 Verify signatures after signing (Scott Robinson)

Pull request description:

  ### Description

  Verify signatures after signing

  As per [BIP-340, footnote 14][fn]:
  > Verifying the signature before leaving the signer prevents random or
  > attacker provoked computation errors. This prevents publishing invalid
  > signatures which may leak information about the secret key. It is
  > recommended, but can be omitted if the computation cost is prohibitive.

  [fn]: https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#cite_note-14

  ### Notes to the reviewers

  How do we test this?

  ### Checklists

  #### All Submissions:

  * [ ] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  afilini:
    re-ACK 7b1ad1b62914a26d6f445364ace4e784bb2901c2

Tree-SHA512: 7319db1f8cec2fcfe4ac443ab5728893f9fb6133b33331b35ec6910662c45de8a7cdcf80ac1f3bb435815e914ccf639682a5c07ff0baef42605bf044a34a8232

3 years agoMerge bitcoindevkit/bdk#722: Implement Deref<Target=UrlClient> for EsploraBlockchain
Alekos Filini [Thu, 25 Aug 2022 10:20:04 +0000 (12:20 +0200)]
Merge bitcoindevkit/bdk#722: Implement Deref<Target=UrlClient> for EsploraBlockchain

baf7eaace66edcae8bf3252a962b9417b704ba26 Implement Deref<Target=UrlClient> for EsploraBlockchain (Vladimir Fomene)

Pull request description:

  ### Description

  There is currently no way to access the client from the EsploraBlockchain. This makes it difficult for users to extend it's functionality. This PR exposes both the reqwest and ureq clients. This PR is related to PR #705.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  rajarshimaitra:
    tACK baf7eaace66edcae8bf3252a962b9417b704ba26

Tree-SHA512: e2f530058c88e06fc2972edfcd2df1b534d43b0214d710b62e4d5200ac0e38dad6a9f8db1e0c7a7ed19892e59411dcc07f3f6dc8ad58afae9d677169ca98bb38

3 years agoMerge bitcoindevkit/bdk#705: Implement `Deref<Target=Client>` for `ElectrumBlockchain`
Alekos Filini [Thu, 25 Aug 2022 10:19:14 +0000 (12:19 +0200)]
Merge bitcoindevkit/bdk#705: Implement `Deref<Target=Client>` for `ElectrumBlockchain`

c5952dd09a61b1cd2185c273e0b8bcb3fd6ed2dd Implement `Deref<Target=Client>` for `ElectrumBlockchain` (Alekos Filini)

Pull request description:

  ### Description

  As pointed out in https://github.com/bitcoindevkit/rust-electrum-client/pull/58#issuecomment-1207890096 there was no way to keep using the client once it was given to BDK.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  rajarshimaitra:
    ACK c5952dd09a61b1cd2185c273e0b8bcb3fd6ed2dd

Tree-SHA512: fbfbada51c9426266c8960da5508ee07b196808f0d670a09a51962bd6eda9ccf585e209f5b99b5ab78a3d17af774bdb3e33ef36ac4f4d1ce7f2c3398ae4f6d0c

3 years agoMerge bitcoindevkit/bdk#731: Implement Deref<Target=Client> for RpcBlockchain
Alekos Filini [Thu, 25 Aug 2022 10:06:43 +0000 (12:06 +0200)]
Merge bitcoindevkit/bdk#731: Implement Deref<Target=Client> for RpcBlockchain

a8f9f6c43adb90c9ceced21da6b6bafaa90d7af9 RpcBlockchain derefs to the underlying RPC Client (rajarshimaitra)

Pull request description:

  <!-- You can erase any parts of this template not applicable to your Pull Request. -->

  ### Description

  For the same reason as #705  and #722 ..

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  afilini:
    ACK a8f9f6c43adb90c9ceced21da6b6bafaa90d7af9

Tree-SHA512: 81e596fe451c275ca0ce27ee7ac9cf7e88433775603021c2dd1cd26a26558531cf74f81ef05d0ae9d5d0e59e91196e3ac6d38c0f4853b1889ddf822d8e63e178

3 years agoVerify signatures after signing
Scott Robinson [Mon, 15 Aug 2022 05:07:14 +0000 (15:07 +1000)]
Verify signatures after signing

As per [BIP-340, footnote 14][fn]:
> Verifying the signature before leaving the signer prevents random or
> attacker provoked computation errors. This prevents publishing invalid
> signatures which may leak information about the secret key. It is
> recommended, but can be omitted if the computation cost is prohibitive.

[fn]: https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#cite_note-14

3 years agoRpcBlockchain derefs to the underlying RPC Client
rajarshimaitra [Tue, 23 Aug 2022 16:14:38 +0000 (21:44 +0530)]
RpcBlockchain derefs to the underlying RPC Client

3 years agoMerge bitcoindevkit/bdk#723: Fix P2WPKH_SATISFACTION_SIZE in CS tests
Alekos Filini [Wed, 17 Aug 2022 11:46:39 +0000 (13:46 +0200)]
Merge bitcoindevkit/bdk#723: Fix P2WPKH_SATISFACTION_SIZE in CS tests

cd078903a7108f86fdd9557b206f25c9611d07d3 Fix P2WPKH_SATISFACTION_SIZE in CS tests (Daniela Brozzoni)

Pull request description:

  Our costant for the P2WPKH satisfaction size was wrong: in
  7ac87b8f99fc0897753ce57d48ea24adf495a633 we added 1 WU for the script
  sig len - but actually, that's 4WU! This resulted in
  P2WPKH_SATISFACTION_SIZE being equal to 109 instead of 112.
  This also adds a comment for better readability.

  ### Description

  ### Notes to the reviewers

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### New Features:

  * [ ] I've added tests for the new feature
  * [ ] I've added docs for the new feature
  * [ ] I've updated `CHANGELOG.md`

  #### Bugfixes:

  * [ ] This pull request breaks the existing API
  * [ ] I've added tests to reproduce the issue which are now passing
  * [ ] I'm linking the issue being fixed by this PR

ACKs for top commit:
  csralvall:
    utACK cd078903a7108f86fdd9557b206f25c9611d07d3
  afilini:
    ACK cd078903a7108f86fdd9557b206f25c9611d07d3

Tree-SHA512: 3e39735505e411392cf01885b5920443d23fa21d9c20cc7c8fdeaa2698df8bc2da86241b6c20f5e3f5941fe1a0aebe8f957d8145d4f9e7ad3f213e4658d6ea68

3 years agoFix P2WPKH_SATISFACTION_SIZE in CS tests
Daniela Brozzoni [Tue, 16 Aug 2022 16:37:03 +0000 (17:37 +0100)]
Fix P2WPKH_SATISFACTION_SIZE in CS tests

Our costant for the P2WPKH satisfaction size was wrong: in
7ac87b8f99fc0897753ce57d48ea24adf495a633 we added 1 WU for the script
sig len - but actually, that's 4WU! This resulted in
P2WPKH_SATISFACTION_SIZE being equal to 109 instead of 112.
This also adds a comment for better readability.

3 years agoMerge bitcoindevkit/bdk#711: Release/0.21.0
Alekos Filini [Tue, 16 Aug 2022 11:39:37 +0000 (13:39 +0200)]
Merge bitcoindevkit/bdk#711: Release/0.21.0

8026bd9476fc5a89baa86ea2a8707a9d341d3743 Bump version to 0.21.1-dev (Alekos Filini)
e2bd96012a08137e4f6776c9192d5247ae20df0b Bump version to 0.21.0 (Alekos Filini)
2c01b6118f3291c2918a60cac635f26df1780dac Bump version to 0.21.0-rc.1 (Alekos Filini)

Pull request description:

  ### Description

  Merge the release branch back into master

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### New Features:

  * [ ] I've added tests for the new feature
  * [ ] I've added docs for the new feature
  * [ ] I've updated `CHANGELOG.md`

  #### Bugfixes:

  * [ ] This pull request breaks the existing API
  * [ ] I've added tests to reproduce the issue which are now passing
  * [ ] I'm linking the issue being fixed by this PR

ACKs for top commit:
  danielabrozzoni:
    ACK 8026bd9476fc5a89baa86ea2a8707a9d341d3743

Tree-SHA512: a2a924a60d551a823de035b609d4d51652a165a0695212af76dea87706919c8929dba977bb297f4787708470bf075d14dd0a37657bd3a76e7d44a746fb5439df

3 years agoImplement Deref<Target=UrlClient> for EsploraBlockchain
Vladimir Fomene [Mon, 15 Aug 2022 16:31:35 +0000 (19:31 +0300)]
Implement Deref<Target=UrlClient> for EsploraBlockchain

There is currently no way to access the client
from the EsploraBlockchain. This makes it difficult
for users to extend it's functionality. This PR exposes
both the reqwest and ureq clients. This PR is related to
PR #705.

3 years agoBump version to 0.21.1-dev github/release/0.21.0
Alekos Filini [Thu, 11 Aug 2022 18:56:03 +0000 (20:56 +0200)]
Bump version to 0.21.1-dev

3 years agoBump version to 0.21.0
Alekos Filini [Thu, 11 Aug 2022 12:39:18 +0000 (14:39 +0200)]
Bump version to 0.21.0

3 years agoMerge commit 'refs/pull/703/head' of github.com:bitcoindevkit/bdk into release/0...
Alekos Filini [Tue, 9 Aug 2022 10:06:13 +0000 (12:06 +0200)]
Merge commit 'refs/pull/703/head' of github.com:bitcoindevkit/bdk into release/0.21.0

3 years agoMerge bitcoindevkit/bdk#703: Fix minor typos in docs
Alekos Filini [Tue, 9 Aug 2022 10:05:24 +0000 (12:05 +0200)]
Merge bitcoindevkit/bdk#703: Fix minor typos in docs

134b19a9cb127989402fe331f48a1e37eb3cdcad Fix minor typos in docs (thunderbiscuit)

Pull request description:

  ### Description
  This PR fixes:
  1. The use of "i.e." in docs, sometimes spelled as "ie."
  2. A small typo in the sentence "Note that this methods only operate on the internal database..."
  3. A small typo in the sentence "Finish the building the transaction"

  I came across these while building docs for bdk-kotlin.

  ### Notes to the reviewers

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  danielabrozzoni:
    ACK 134b19a9cb127989402fe331f48a1e37eb3cdcad

Tree-SHA512: 67296999eba8ffe1fe64756fa023d85064774cb9d4c26e99054d467b5024baea4138f11d602d04e695412c61625ee4f5b4687b75f177cfec2604a6c61a5a6216

3 years agoMerge branch 'release/0.21.0', commit 'refs/pull/704/head' of github.com:bitcoindevki...
Alekos Filini [Tue, 9 Aug 2022 09:54:23 +0000 (11:54 +0200)]
Merge branch 'release/0.21.0', commit 'refs/pull/704/head' of github.com:bitcoindevkit/bdk into release/0.21.0

3 years agoMerge bitcoindevkit/bdk#704: Fix `rpc::CoreTxIter` logic.
Alekos Filini [Tue, 9 Aug 2022 09:49:26 +0000 (11:49 +0200)]
Merge bitcoindevkit/bdk#704: Fix `rpc::CoreTxIter` logic.

74e2c477f124489a2357921ca879cc82e24da5fd Replace `rpc::CoreTxIter` with `list_transactions` fn. (志宇)

Pull request description:

  ### Description

  This fixes a bug where `CoreTxIter` attempts to call `listtransactions` immediately after a tx result is filtered (instead of being returned), when in fact, the correct logic will be to pop another tx result.

  The new logic also ensures that tx results are returned in chonological order. The test `test_list_transactions` verifies this. We also now ensure that `page_size` is between the range `[0 to 1000]` otherwise an error is returned.

  Some needless cloning is removed from `from_config` as well as logging improvements.

  ### Notes to the reviewers

  This is an oversight by me (sorry) for PR #683

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### Bugfixes:

  ~* [ ] This pull request breaks the existing API~
  * [x] I've added tests to reproduce the issue which are now passing
  * [x] I'm linking the issue being fixed by this PR

ACKs for top commit:
  afilini:
    ACK 74e2c477f124489a2357921ca879cc82e24da5fd

Tree-SHA512: f32314a9947067673d19d95da8cde36b350c0bb0ebe0924405ad50602c14590f7ccb09a3e03cdfdd227f938dccd0f556f3a2b4dd7fdd6eba1591c0f8d3e65182

3 years agoReplace `rpc::CoreTxIter` with `list_transactions` fn.
志宇 [Sat, 6 Aug 2022 02:58:04 +0000 (10:58 +0800)]
Replace `rpc::CoreTxIter` with `list_transactions` fn.

This fixes a bug where `CoreTxIter` attempts to call `listtransactions`
immediately after a tx result is filtered (instead of being returned),
when in fact, the correct logic will be to pop another tx result.

The new logic also ensures that tx results are returned in chonological
order. The test `test_list_transactions` verifies this. We also now
ensure that `page_size` is between the range `[0 to 1000]` otherwise an
error is returned.

Some needless cloning is removed from `from_config` as well as logging
improvements.

3 years agoImplement `Deref<Target=Client>` for `ElectrumBlockchain`
Alekos Filini [Mon, 8 Aug 2022 10:03:35 +0000 (12:03 +0200)]
Implement `Deref<Target=Client>` for `ElectrumBlockchain`

As pointed out in https://github.com/bitcoindevkit/rust-electrum-client/pull/58#issuecomment-1207890096
there was no way to keep using the client once it was given to BDK.

3 years agoFix minor typos in docs
thunderbiscuit [Fri, 5 Aug 2022 15:39:50 +0000 (11:39 -0400)]
Fix minor typos in docs

3 years agoBump version to 0.21.0-rc.1
Alekos Filini [Thu, 4 Aug 2022 09:59:56 +0000 (11:59 +0200)]
Bump version to 0.21.0-rc.1

3 years agoMerge bitcoindevkit/bdk#640: Get balance in categories
Alekos Filini [Thu, 4 Aug 2022 09:43:34 +0000 (11:43 +0200)]
Merge bitcoindevkit/bdk#640: Get balance in categories

0f03831274d3aa69da6e89729c65d66530bbd752 Change get_balance to return in categories. (wszdexdrf)

Pull request description:

  ### Description
  This changes `get_balance()` function so that it returns balance separated in 4 categories:
  - available
  - trusted-pending
  - untrusted-pending
  - immature

  Fixes #238

  ### Notes to the reviewers
  Based on #614

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### New Features:

  * [x] I've updated tests for the new feature
  * [x] I've added docs for the new feature
  * [x] I've updated `CHANGELOG.md`

ACKs for top commit:
  afilini:
    ACK 0f03831274d3aa69da6e89729c65d66530bbd752

Tree-SHA512: 39f02c22c61b6c73dd8e6d27b1775a72e64ab773ee67c0ad00e817e555c52cdf648f482ca8be5fcc2f3d62134c35b720b1e61b311cb6debb3ad651e79c829b93

3 years agoChange get_balance to return in categories.
wszdexdrf [Wed, 22 Jun 2022 09:07:29 +0000 (14:37 +0530)]
Change get_balance to return in categories.

Add type balance with add, display traits. Change affected tests.
Update `CHANGELOG.md`

3 years agoMerge bitcoindevkit/bdk#683: Fix wallet sync for `RpcBlockchain`
Alekos Filini [Thu, 4 Aug 2022 08:22:50 +0000 (10:22 +0200)]
Merge bitcoindevkit/bdk#683: Fix wallet sync for `RpcBlockchain`

5eeba6cced9a6fa0ad8ee4f64d04e1948620eac8 Various `RpcBlockchain` improvements (志宇)
5eb74af41494b7ec4894d7da3015da2981639228  Rpc: Manually add immature coinbase utxos (志宇)
ac19c19f21fce43a99ecf0c4f95ae818b620558c New `RpcBlockchain` implementation with various fixes (志宇)

Pull request description:

  Fixes #677

  ### Description

  Unfortunately to fix all the problems, I had to do a complete re-implementation of `RpcBlockchain`.

  **The new implementation fixes the following:**
  * We can track more than 100 scriptPubKeys
  * We can obtain more than 1000 transactions per sync
  * Transaction "metadata" for already-syned transactions are updated when we introduce new scriptPubKeys

  **`RpcConfig` changes:**
  * Introduce `RpcSyncParams`.
  * Remove `RpcConfig::skip_blocks` (this is replaced by `RpcSyncParams::start_time`).

  ### Notes to the reviewers

  * The `RpcConfig` structure is changed. It will be good to confirm whether this is an okay change.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### New Features:

  ~* [ ] I've added tests for the new feature~
  * [x] I've added docs for the new feature
  * [x] I've updated `CHANGELOG.md`

  #### Bugfixes:

  * [x] This pull request breaks the existing API
  * [x] I've added tests to reproduce the issue which are now passing
  * [x] I'm linking the issue being fixed by this PR

ACKs for top commit:
  afilini:
    ACK 5eeba6cced9a6fa0ad8ee4f64d04e1948620eac8

Tree-SHA512: 7e0c9cfc4ef10fb07e4ac7f6fbf30cf28ca6395495c0237fa5bfa9a2fcbbd4d8ff980ffcf71ddd10bc052e4c07bc2c27f093dd3cd1c69cb29141455c693f2386

3 years agoVarious `RpcBlockchain` improvements
志宇 [Sat, 30 Jul 2022 13:12:18 +0000 (21:12 +0800)]
Various `RpcBlockchain` improvements

These are as suggested by @danielabrozzoni and @afilini

Also introduced `RpcSyncParams::force_start_time` for users who
prioritise reliability above all else.

Also improved logging.

3 years ago Rpc: Manually add immature coinbase utxos
志宇 [Sat, 30 Jul 2022 11:47:33 +0000 (19:47 +0800)]
 Rpc: Manually add immature coinbase utxos

Before this commit, the rpc backend would not notice immature utxos
(`listunspent` does not return them), making the rpc balance different
to other blockchain implementations.

Co-authored-by: Daniela Brozzoni <danielabrozzoni@protonmail.com>
3 years agoNew `RpcBlockchain` implementation with various fixes
志宇 [Fri, 22 Jul 2022 23:44:39 +0000 (07:44 +0800)]
New `RpcBlockchain` implementation with various fixes

The new implementation fixes the following:
* We can track more than 100 scriptPubKeys
* We can obtain more than 1000 transactions per sync
* `TransactionDetails` for already-synced transactions are updated when
  new scriptPubKeys are introduced (fixing the missing balance/coins
      issue of supposedly tracked scriptPubKeys)

`RpcConfig` changes:
* Introduce `RpcSyncParams`.
* Remove `RpcConfig::skip_blocks` (this is replaced by
  `RpcSyncParams::start_time`).

3 years agoMerge bitcoindevkit/bdk#693: Fix the early InsufficientFunds error in the branch...
Daniela Brozzoni [Wed, 3 Aug 2022 17:53:53 +0000 (19:53 +0200)]
Merge bitcoindevkit/bdk#693: Fix the early InsufficientFunds error in the branch and bound

9d85c9667f7d12902afef3ba08ea7231f6868a78 Fix the early InsufficientFunds error in the branch and bound (Alekos Filini)

Pull request description:

  ### Description

  We were wrongly considering the sum of "effective value" (i.e. value -
  fee cost) when reporting an early "insufficient funds" error in the
  branch and bound coin selection.

  This commit fixes essentially two issues:
  - Very high fee rates could cause a panic during the i64 -> u64
    conversion because we assumed the sum of effective values would never
    be negative
  - Since we were comparing the sum of effective values of *all* the UTXOs
    (even the optional UTXOs with negative effective value) with the target
    we'd like to reach, we could in some cases error and tell the user we
    don't have enough funds, while in fact we do! Since we are not required
    to spend any of the optional UTXOs, so we could just ignore the ones
    that *cost us* money to spend and excluding them could potentially
    allow us to reach the target.

  There's a third issue that was present before and remains even with this
  fix: when we report the "available" funds in the error, we are ignoring
  UTXOs with negative effective value, so it may look like there are less
  funds in the wallet than there actually are.

  I don't know how to convey the right message the user: if we actually
  consider them we just make the "needed" value larger and larger (which
  may be confusing, because if the user asks BDK to send 10k satoshis, why
  do we say that we actually need 100k?), while if we don't we could report
  an incorrect "available" value.

  ### Notes to the reviewers

  I'm opening this as a draft before adding tests because I want to gather some feedback on the available vs needed error reporting. I personally think reporting a reasonable "needed" value is more important than the "available", because in a wallet app I would expect this is the value that would be shown to the user.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### Bugfixes:

  * [ ] This pull request breaks the existing API
  * [ ] I've added tests to reproduce the issue which are now passing
  * [ ] I'm linking the issue being fixed by this PR

ACKs for top commit:
  danielabrozzoni:
    utACK 9d85c9667f7d12902afef3ba08ea7231f6868a78

Tree-SHA512: 9a06758cba61ade73198f35b08070987d5eb065e01750ce62409f86b37cd0b0894640e9f75c8b2c26543c0da04e3f77bd397fab540e789f221661aae828db224

3 years agoFix the early InsufficientFunds error in the branch and bound
Alekos Filini [Tue, 26 Jul 2022 15:27:40 +0000 (17:27 +0200)]
Fix the early InsufficientFunds error in the branch and bound

We were wrongly considering the sum of "effective value" (i.e. value -
fee cost) when reporting an early "insufficient funds" error in the
branch and bound coin selection.

This commit fixes essentially two issues:
- Very high fee rates could cause a panic during the i64 -> u64
  conversion because we assumed the sum of effective values would never
  be negative
- Since we were comparing the sum of effective values of *all* the UTXOs
  (even the optional UTXOs with negative effective value) with the target
  we'd like to reach, we could in some cases error and tell the user we
  don't have enough funds, while in fact we do! Since we are not required
  to spend any of the optional UTXOs, so we could just ignore the ones
  that *cost us* money to spend and excluding them could potentially
  allow us to reach the target.

There's a third issue that was present before and remains even with this
fix: when we report the "available" funds in the error, we are ignoring
UTXOs with negative effective value, so it may look like there are less
funds in the wallet than there actually are.

I don't know how to convey the right message the user: if we actually
consider them we just make the "needed" value larger and larger (which
may be confusing, because if the user asks BDK to send 10k satoshis, why
do we say that we actually need 100k?), while if we don't we could report
an incorrect "available" value.

3 years agoMerge bitcoindevkit/bdk#686: doc: Document that list_transactions() might return...
Daniela Brozzoni [Wed, 3 Aug 2022 15:17:16 +0000 (17:17 +0200)]
Merge bitcoindevkit/bdk#686: doc: Document that list_transactions() might return unsorted txs

7fdacdbad40f4e9f6726b064d8eb4d93789e9990 doc: Document that list_transactions() might return unsorted txs, show how to sort them if needed (w0xlt)

Pull request description:

  This PR documents that `list_transactions()` might return unsorted transaction and shows how to sort them if needed.

  Closes #518.

ACKs for top commit:
  danielabrozzoni:
    re-ACK 7fdacdbad40f4e9f6726b064d8eb4d93789e9990

Tree-SHA512: 83bec98e1903d6dc6b8933e8994cb9d04aad059cee8a7b8e1e3a322cf52511364b36d0cd6be1c8cb1fd82c67f8be5a262bbd2c76e30b24eb4097c30f38aa8b10

3 years agodoc: Document that list_transactions() might return unsorted txs, show how to sort...
w0xlt [Wed, 3 Aug 2022 15:08:50 +0000 (12:08 -0300)]
doc: Document that list_transactions() might return unsorted txs, show how to sort them if needed

3 years agoMerge bitcoindevkit/bdk#662: Consolidate `fee_amount` and `amount_needed`
Alekos Filini [Wed, 3 Aug 2022 10:32:30 +0000 (12:32 +0200)]
Merge bitcoindevkit/bdk#662: Consolidate `fee_amount` and `amount_needed`

e8df3d2d91927edb9a339c664f0603c47622e4b0 Consolidate `fee_amount` and `amount_needed` (Cesar Alvarez Vallero)

Pull request description:

  ### Description

  Before this commit `fee_amount` and `amount_needed` were passed as independent
  parameters. From the perspective of coin selection algorithms, they are always
  used jointly for the same purpose, to create a coin selection with a total
  effective value greater than it's summed values.

  This commit removes the abstraction that the use of the two parameter
  introduced by consolidating both into a single parameter, `target_amount`, who
  carries their values added up.

  Resolves: #641

  ### Notes to the reviewers

  I just updated old tests and didn't create new ones because almost all changes
  are renames and "logic changes" (like the addition of the selection fee) are
  tested in the modified tests.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### New Features:

  * [ ] I've added tests for the new feature
  * [x] I've added docs for the new feature
  * [x] I've updated `CHANGELOG.md`

  #### Bugfixes:

  * [x] This pull request breaks the existing API
  * [x] I'm linking the issue being fixed by this PR

ACKs for top commit:
  danielabrozzoni:
    re-ACK e8df3d2d91927edb9a339c664f0603c47622e4b0 - I tested with the fuzzer, run it for 13,000,000 iterations, couldn't find any crash :)

Tree-SHA512: 64b46473799352c06cc554659e4b159a33812b3d3793c9d436bd1e46b65edd085d71b219f6a0474f6836979ca608aa019a72bdc6915a2cc2d744a76e2a28b889

3 years agoMerge bitcoindevkit/bdk#681: Add `electrsd/bitcoind_22_0` to `example\rpcwallet`...
Alekos Filini [Wed, 3 Aug 2022 10:31:05 +0000 (12:31 +0200)]
Merge bitcoindevkit/bdk#681: Add `electrsd/bitcoind_22_0` to `example\rpcwallet` target

a63c51f35dc392bfcd390cbda0eb40205b78ac8e Add `electrsd/bitcoind_22_0` to `example\rpcwallet` target (w0xlt)

Pull request description:

  On master branch, `example\rpcwallet` fails.

  ```
  $ cargo run --features="keys-bip39 key-value-db rpc" --example rpcwallet
     Compiling bitcoin_hashes v0.9.7
     Compiling bip39 v1.0.1
     Compiling bdk v0.20.1-dev (/home/node01/Dev/wbdk)
      Finished dev [unoptimized + debuginfo] target(s) in 19.64s
       Running `target/debug/examples/rpcwallet`
  >> Setting up bitcoind
  thread 'main' panicked at 'We should always have downloaded path: Called a method requiring a feature to be set, but it's not', examples/rpcwallet.rs:56:51
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
  ```

  This PR adds `electrsd/bitcoind_22_0` to `required-features`, making clear that this lib is needed to run this example..

  ```
  $ cargo run --features="keys-bip39 key-value-db rpc electrsd/bitcoind_22_0" --example rpcwallet
      Blocking waiting for file lock on package cache
     Compiling electrsd v0.19.1
     Compiling bdk v0.20.1-dev (/home/node01/Dev/wbdk)
      Finished dev [unoptimized + debuginfo] target(s) in 10.27s
       Running `target/debug/examples/rpcwallet`
  >> Setting up bitcoind
  >> bitcoind setup complete
  Available coins in Core wallet : 50.00000000 BTC

  >> Setting up BDK wallet
  >> BDK wallet setup complete.
  Available initial coins in BDK wallet : 0 sats

  >> Sending coins: Core --> BDK, 10 BTC
  >> Received coins in BDK wallet
  Available balance in BDK wallet: 1000000000 sats

  >> Sending coins: BDK --> Core, 5 BTC
  >> Coins sent to Core wallet
  Remaining BDK wallet balance: 499999859 sats

  Congrats!! you made your first test transaction with bdk and bitcoin core.
  ```

ACKs for top commit:
  afilini:
    reACK a63c51f35dc392bfcd390cbda0eb40205b78ac8e

Tree-SHA512: ef13d5e001121c8b1ff6436f9e95b656737bee6692e9b18c4012846a2d2e9e9ad7e6b5cd87cebf4a873335e92a524694e684567a1268f5f0705156659fd9a916

3 years agoConsolidate `fee_amount` and `amount_needed`
Cesar Alvarez Vallero [Sun, 10 Jul 2022 22:57:44 +0000 (19:57 -0300)]
Consolidate `fee_amount` and `amount_needed`

Before this commit `fee_amount` and `amount_needed` were passed as independent
parameters. From the perspective of coin selection algorithms, they are always
used jointly for the same purpose, to create a coin selection with a total
effective value greater than it's summed values.

This commit removes the abstraction that the use of the two parameter
introduced by consolidating both into a single parameter, `target_amount`, who
carries their values added up.

3 years agoAdd `electrsd/bitcoind_22_0` to `example\rpcwallet` target
w0xlt [Mon, 25 Jul 2022 05:19:41 +0000 (02:19 -0300)]
Add `electrsd/bitcoind_22_0` to `example\rpcwallet` target

3 years agoMerge bitcoindevkit/bdk#666: Various fixes to the `fee_amount` calculation in `create_tx`
Alekos Filini [Wed, 3 Aug 2022 09:40:17 +0000 (11:40 +0200)]
Merge bitcoindevkit/bdk#666: Various fixes to the `fee_amount` calculation in `create_tx`

419dc248b667db05295cd4c68347c4ef51f51023 test: Document `test_bump_fee_add_input_change_dust` (Daniela Brozzoni)
632dabaa07ef9c58926facf0af5190f62bb65d12 test: Check tx feerate with longer signatures (Daniela Brozzoni)
2756411ef7cf0415baf2f2401e2d5a78481d0aa1 test: Reproduce #660 conditions (Daniela Brozzoni)
50af51da5a5c906d8bf660d35a4f922ceb996068 test: Fix P2WPKH_FAKE_WITNESS_SIZE (Daniela Brozzoni)
ae919061e2b341ae74c90f0133ba392e835cb4e1 Take into account the segwit tx header when... ...selecting coins (Daniela Brozzoni)
7ac87b8f99fc0897753ce57d48ea24adf495a633 TXIN_BASE_WEIGHT shouldn't include the script len (Daniela Brozzoni)
ac051d7ae9512883e11a89ab002ad2d2c3c55c19 Calculate fee amount after output addition (Daniela Brozzoni)
00d426b88546a346820c102386cd1bfff82ca8f6 test: Check that the feerate is never below... ...the requested one in assert_fee_rate (Daniela Brozzoni)
42fde6d4575b4aea121286f884f712b1c1cf64be test: Check fee_amount in assert_fee_rate (Daniela Brozzoni)

Pull request description:

  ### Description

  This PR mainly fixes two bugs:
  1. TXIN_BASE_WEIGHT wrongly included the `script_len` (Fixes #160)
  2. We wouldn't take into account the segwit header in the fee calculation, which could have resulted in a transaction with a lower feerate than the requested one
  3. In tests we used to push 108 bytes on the witness as a fake signature, but we should have pushed 106 instead

  I also add a test to reproduce the conditions of #660, to check if it's solved. Turns out it's been solved already in #630, but if you're curious about what the bug was, here it is: https://github.com/bitcoindevkit/bdk/issues/660#issuecomment-1196436776
  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### Bugfixes:

  * [ ] This pull request breaks the existing API
  * [x] I've added tests to reproduce the issue which are now passing
  * [x] I'm linking the issue being fixed by this PR

ACKs for top commit:
  afilini:
    ACK 419dc248b667db05295cd4c68347c4ef51f51023

Tree-SHA512: c7b55342eac440a3607a16b94560cb9c08c4805c853432adfda8e21c5177f85d5a8afe0e7e61140e92c8f10934332459c6234fc5f1509ea699d97b1d04f030c6