]> Untitled Git - bdk/log
bdk
16 months agofix(wallet)!: Change method `LoadParams::descriptors`
valued mammal [Fri, 9 Aug 2024 13:09:22 +0000 (09:09 -0400)]
fix(wallet)!: Change method `LoadParams::descriptors`

to just `descriptor` that takes a `KeychainKind` and optional
`D: IntoWalletDescriptor` representing the expected value of
the descriptor in the changeset.

Add method `LoadParams::extract_keys` that will use any private
keys in the provided descriptors to add a signer to the wallet.

16 months agoexample(wallet): simplify miniscript compiler example
valued mammal [Tue, 6 Aug 2024 17:25:25 +0000 (13:25 -0400)]
example(wallet): simplify miniscript compiler example

16 months agotest(wallet): Add tests for single descriptor wallet
valued mammal [Tue, 6 Aug 2024 17:24:42 +0000 (13:24 -0400)]
test(wallet): Add tests for single descriptor wallet

16 months agofix(wallet): Change FromSql type to `Option<_>`
valued mammal [Tue, 6 Aug 2024 18:52:14 +0000 (14:52 -0400)]
fix(wallet): Change FromSql type to `Option<_>`

when selecting a wallet row from sqlite. This is consistent with
the structure of the wallet `ChangeSet` where the fields
`descriptor`, `change_descriptor`, and `network` are all optional.

16 months agofeat(wallet): Add method `Wallet::create_single`
valued mammal [Tue, 6 Aug 2024 15:52:31 +0000 (11:52 -0400)]
feat(wallet): Add method `Wallet::create_single`

that allows creating a wallet with a single descriptor.

16 months agoMerge bitcoindevkit/bdk#1491: Enable selecting use-rustls-ring feature on electrum...
Steve Myers [Tue, 13 Aug 2024 20:20:18 +0000 (15:20 -0500)]
Merge bitcoindevkit/bdk#1491: Enable selecting use-rustls-ring feature on electrum client

f965f95721c719ac755da07aa997d9b858583856 feat: enable selecting use-rustls-ring feature on electrum client (thunderbiscuit)

Pull request description:

  This PR is a companion to bitcoindevkit/rust-electrum-client#135. It enables choosing the `ring` dependency on rustls instead of the new default (as of 0.23.0) `aws-lc-rs`. The AWS dependency breaks the Android and Swift builds. I wrote a more detailed explanation on [#135](https://github.com/bitcoindevkit/rust-electrum-client/pull/135).

  ### Notes to the reviewers

  Do not merge before:
  - [x] [#135](https://github.com/bitcoindevkit/rust-electrum-client/pull/135) is merged
  - [x] A new version of rust-electrum-client is released (will be 0.21.0)
  - [x] The dependency points to the new version of the client rather than my fork of it.

  ### Changelog notice

  ```md
  Added
      - bdk_electrum now enables choosing either the `use-rustls` or `use-rustls-ring` feature
  ```

  ### 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:
  LLFourn:
    ACK f965f95721c719ac755da07aa997d9b858583856
  notmandatory:
    utACK f965f95721c719ac755da07aa997d9b858583856
  oleonardolima:
    ACK f965f95721c719ac755da07aa997d9b858583856

Tree-SHA512: c82afa82ef8603bc8e6d024ee5030fa1ec6ab71fbce090182ce3a297ce1a788c1db48f593f05331b1de1931a731a5fc03f804cb1b17f8c7832286fda6c09aa4b

16 months agoMerge bitcoindevkit/bdk#1494: Add documentation for Electrum's full_scan/sync
志宇 [Tue, 13 Aug 2024 08:53:58 +0000 (08:53 +0000)]
Merge bitcoindevkit/bdk#1494: Add documentation for Electrum's full_scan/sync

7b5657e23e17c6934773dfdff0ed214ff3b8f110 docs(electrum): enhance API docs for fetch_prev_txouts argument (thunderbiscuit)

Pull request description:

  This PR also serves as an issue; it can't really be merged as is. I just didn't want to open an issue and just ask for better docs and instead decided to open a PR with some unfinished new API docs.

  I am working on a page for the Book of BDK that focuses on bdk_wallet + bdk_electrum syncing. A few things have been unclear to me, and I think slight additions to the API docs would fix that for others.

  ~~1. I was wondering what exactly this `confirmation_time` field on the `bdk_chain::ConfirmationTimeHeightAnchor` type represents. After digging into it (at least for the electrum client), it represents the timestamp specified by the block header where the tx was confirmed. _Question: I'd like to confirm that this always the case, e.g. that this is the timestamp used in cases where your client is an Esplora or bitcoind RPC node?_ If so, my addition to the sentence will make sense and is ready to go.~~ Edit: this is no longer a type after the rebase.
  2. I think it'd be great to add context to the `fetch_prev_txouts` argument on the full_scan and sync methods on the `BdkElectrumClient`. It says that this is necessary for "fee calculation". What does that mean? I assume it means "for calculating the fee rate on the given transactions"? (let me know if that's wrong). Even so, I'm left wondering what happens if I don't fetch them. Will my fee calculations be just plain wrong? Or will they be unavailable? A bit more context for the caller of the method would be great here. If someone knows the definite answer to this let me know and feel free to propose a doc line and I'll amend the commit!

  ### Checklists
  * [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:
  evanlinjin:
    re-ACK 7b5657e23e17c6934773dfdff0ed214ff3b8f110

Tree-SHA512: f0ac9ae4a116c9a3f5006d6a41f626ac36c3f8495204a9eaa06d2c8003cabe0005be33fcc810028d314c505c3385a5facd2bedb3b2218ddf272b0fa2220abd39

16 months agofeat: enable selecting use-rustls-ring feature on electrum client
thunderbiscuit [Wed, 26 Jun 2024 14:52:57 +0000 (10:52 -0400)]
feat: enable selecting use-rustls-ring feature on electrum client

16 months agodocs(electrum): enhance API docs for fetch_prev_txouts argument
thunderbiscuit [Fri, 28 Jun 2024 15:59:10 +0000 (11:59 -0400)]
docs(electrum): enhance API docs for fetch_prev_txouts argument

16 months agoMerge bitcoindevkit/bdk#1535: test(electrum): Test sync in reorg and no-reorg situations
志宇 [Mon, 12 Aug 2024 09:51:51 +0000 (09:51 +0000)]
Merge bitcoindevkit/bdk#1535: test(electrum): Test sync in reorg and no-reorg situations

2c0bc45ecf0241abc8bf9d72c8bbeded53d32a45 feat(testenv): Added `bdk_electrum` wait for Txid method (Wei Chen)
49e1a5e871de31e87cc9a4d329cd2b1477f32fd0 test(electrum): Test sync in reorg and no-reorg situations (Wei Chen)

Pull request description:

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

  ### Description

  <!-- Describe the purpose of this PR, what's being adding and/or fixed -->
  Add new test for `bdk_electrum` to make sure previously unconfirmed transactions get confirmed again in both reorg and no-reorg situations.

  ### Changelog notice

  <!-- Notice the release manager should include in the release tag message changelog -->
  <!-- See https://keepachangelog.com/en/1.0.0/ for examples -->
  * Added `wait_until_electrum_sees_txid` method to `TestEnv`.
  * `wait_until_electrum_sees_block` now has a `Duration` input for timeout.
  * Removed exponential polling delay in `wait_until_electrum_sees_block`.
  * Added `test_sync` to `bdk_electrum` to make sure previously unconfirmed transactions get confirmed in both reorg and no-org situations.

  ### 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:
  evanlinjin:
    ACK 2c0bc45ecf0241abc8bf9d72c8bbeded53d32a45

Tree-SHA512: 2218151267fe0a3dc3eefa1e7081902e25193f211b2624a3a9f2007b9b38eefb5b847754b9f8cbefba6be6a497cfbc85ac3e5a2db40f01fcc71a3c9d8427adf4

16 months agoMerge bitcoindevkit/bdk#1545: feat(testenv): Add method `new_with_config`
志宇 [Mon, 12 Aug 2024 09:35:06 +0000 (09:35 +0000)]
Merge bitcoindevkit/bdk#1545: feat(testenv): Add method `new_with_config`

b3b65514b7243664d24e4a9623d93ef619650d28 feat(testenv): Add method `new_with_config` (valued mammal)

Pull request description:

  I think this will be useful for passing a custom bitcoin config including e.g. `-blockfilterindex` that would not otherwise be included in the default config.

  ### Notes to the reviewers

  Any other suggestions let me know @LagginTimes

  ### Changelog notice

  * Added method `TestEnv::new_with_config` for passing custom `bitcoind::Conf`, `electrsd::Conf` config objects

  ### 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:
  LagginTimes:
    ACK b3b65514b7243664d24e4a9623d93ef619650d28
  evanlinjin:
    ACK b3b65514b7243664d24e4a9623d93ef619650d28

Tree-SHA512: f771505bc4e7096e89c697a18cfaa367e2ffa57616ca9f2d02d0ad7672c148bb0eb17f66b5e7ab2bbf16fcca4b7457c0c43d892119b0feb6c1462d4034a81a9b

16 months agofeat(testenv): Added `bdk_electrum` wait for Txid method
Wei Chen [Thu, 8 Aug 2024 14:17:01 +0000 (22:17 +0800)]
feat(testenv): Added `bdk_electrum` wait for Txid method

Added `wait_until_electrum_sees_txid` method to `TestEnv`. Both
`bdk_electrum` wait methods now have a `timeout` option. Removed
the exponential polling delay in lieu of a fixed delay inside the
`bdk_electrum` wait methods.

16 months agotest(electrum): Test sync in reorg and no-reorg situations
Wei Chen [Thu, 8 Aug 2024 14:18:28 +0000 (22:18 +0800)]
test(electrum): Test sync in reorg and no-reorg situations

Add test for `bdk_electrum` to make sure previously unconfirmed
transactions get confirmed again in both reorg and no-reorg
situations.

16 months agoMerge bitcoindevkit/bdk#1495: example: Update `example_cli` and retire old nursery...
志宇 [Mon, 12 Aug 2024 04:35:25 +0000 (04:35 +0000)]
Merge bitcoindevkit/bdk#1495: example: Update `example_cli` and retire old nursery crates

771f6b9c97a70be2e8d2da5216f3b686295861bd example: Update example_cli (valued mammal)

Pull request description:

  - Adds two commands `init` and `generate`. Loading database doesn't require descriptors
  - Replaces `send` command with `psbt` (new, sign, and extract). Supports tap key spend
  - Uses `bdk-coin-select` and miniscript `plan` module

  fixes #1469
  partially addresses #1462

  ### Notes to the reviewers

  Note the `example_cli` lib now defines the `ChangeSet` and `Anchor` type whereas before these were generic

  ### Changelog notice

  * Improvements to `example_cli` that include generating descriptors and creating PSBTs

  ### 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:
  evanlinjin:
    ACK 771f6b9c97a70be2e8d2da5216f3b686295861bd

Tree-SHA512: 93b9e38ec428c3ed5920e7632381dcf50e28a01ceb8e1438c87aa459563600cd79636bcf1179eefa763adce98239a60ad2894dfb2ba0f2700cc64e57ede75010

16 months agofeat(testenv): Add method `new_with_config`
valued mammal [Fri, 9 Aug 2024 02:43:29 +0000 (22:43 -0400)]
feat(testenv): Add method `new_with_config`

This allows passing a custom config for either `BitcoinD` or
`ElectrsD`. We also add a new `pub struct Config` for holding
each of `bitcoind::Conf` and `electrsd::Conf`.

16 months agoMerge bitcoindevkit/bdk#1544: Remove crate-renaming
志宇 [Fri, 9 Aug 2024 16:18:17 +0000 (16:18 +0000)]
Merge bitcoindevkit/bdk#1544: Remove crate-renaming

318ce095f2adec9d03077ddf65470ff475547f39 refactor(chain): remove crate-renaming (志宇)

Pull request description:

  ### Description

  [Rust 1.60 introduces *"namespaced features"*](https://blog.rust-lang.org/2022/04/07/Rust-1.60.0.html#new-syntax-for-cargo-features) so we can add a dependency without implicitly also defining a feature of the same name.

  We can now get rid of crate-renaming and use "namespaced features" instead.

  Thanks to @LLFourn for pointing this out.

  ### Changelog notice

  * Remove crate-renaming in `bdk_chain` and use "namespaced features" instead.

  ### 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:
  LLFourn:
    ACK 318ce095f2adec9d03077ddf65470ff475547f39

Tree-SHA512: 5e8f9002eda50dd73c6b38988d288f96d5c827d8e8ec6bdf6ad8da497cecd0f41e709158a96c9e9736a41b825a86ad2ed706b60eca0786976e551f6e25eb0c74

16 months agorefactor(chain): remove crate-renaming
志宇 [Fri, 9 Aug 2024 05:50:18 +0000 (05:50 +0000)]
refactor(chain): remove crate-renaming

16 months agoMerge bitcoindevkit/bdk#1523: bdk_wallet: Don't reimplement descriptor checksum,...
志宇 [Mon, 5 Aug 2024 05:25:48 +0000 (05:25 +0000)]
Merge bitcoindevkit/bdk#1523: bdk_wallet: Don't reimplement descriptor checksum, use the one from rust-miniscript

70c7d6b1c064103b359ad2e774a2648fbd85a414 bdk_wallet: remove unnecessary calls to calc_checksum (Antoine Poinsot)
8245fb7eabb3aa9747118cc871dca4646be4d6e8 bdk_wallet: don't reimplement checksum algorithm, use rust-miniscript (Antoine Poinsot)
a11ace20ce38c9753d7f58cd410da747f4e4fd00 bdk_wallet: descriptor: remove unnecessary call to calc_checksum_bytes (Antoine Poinsot)

Pull request description:

  Skimming through the BDK code today i noticed the descriptor checksum algorithm is re-implemented instead of using the implementation from rust-miniscript. Re-implementing it here is more code to review and maintain, more room for mistakes and overall less eyes over the code than centralizing a single implementation over at `rust-miniscript`.

  While doing this i noticed that one of the variants was completely unnecessary (`calc_checksum_bytes`), so i removed it. I realise it's breaking the API, so if we want to avoid that i can remove this part. I also added a commit to remove redundant calls to `calc_checsum`.

  Overall this is just a quick PoC as i noticed it i figured i'd send a PR, my bad if i missed anything!

ACKs for top commit:
  storopoli:
    utACK 70c7d6b1c064103b359ad2e774a2648fbd85a414
  evanlinjin:
    ACK 70c7d6b1c064103b359ad2e774a2648fbd85a414

Tree-SHA512: 89d0e582979c8260a97646abc3821a9ec1fd84b5ff1e9236efa87654bd31d5da654c9725f4e1c9871a28c9312c0cfe6e095e50742abe5fbd0490fc9a2e41c86b

16 months agoMerge bitcoindevkit/bdk#1530: chore: fix clippy lints
Steve Myers [Thu, 1 Aug 2024 04:02:59 +0000 (23:02 -0500)]
Merge bitcoindevkit/bdk#1530: chore: fix clippy lints

8bf8c7d080194872188e1ab7a6f14c06b121e371 chore: fix clippy lints (Jose Storopoli)

Pull request description:

  ### Description

  Fix some clippy CI lints

  ### Notes to the reviewers

  More caught by the Nix CI in #1320.

  ### Changelog notice

  chore: clippy lints

  ### 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 8bf8c7d080194872188e1ab7a6f14c06b121e371

Tree-SHA512: 6b53cb739e506d79106a2f42aa2b8fa28ef226543fbbf100225f10ed82257f6fd0218f09c0f1291803fbc9c1c88e32ba1c7e02fe3f601ccc9dc5be8a6efea6e1

16 months agoMerge bitcoindevkit/bdk#1529: fix: typos
Steve Myers [Thu, 1 Aug 2024 02:54:14 +0000 (21:54 -0500)]
Merge bitcoindevkit/bdk#1529: fix: typos

a8efeaa0fb83848a04e7324311ccaca4e2c4ab71 fix: typos (Jose Storopoli)

Pull request description:

  ### Description

  Needed for the typos nix check in #1320.

  ### Notes to the reviewers

  More typos that the Nix CI caught.

  ### Changelog notice

  - fix: typos

  ### 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 a8efeaa0fb83848a04e7324311ccaca4e2c4ab71

Tree-SHA512: 44a625bcf538acb7a766316f1d512ef3fd7cc14aae03f09b129229946ef156be35dff73dab3dc24fbc21137764b5707a2bd632bfb84b38dc9fe4d061659ac766

16 months agochore: fix clippy lints
Jose Storopoli [Tue, 30 Jul 2024 17:43:32 +0000 (14:43 -0300)]
chore: fix clippy lints

16 months agofix: typos
Jose Storopoli [Tue, 30 Jul 2024 16:35:23 +0000 (13:35 -0300)]
fix: typos

Needed for the typos nix check in #1320.

16 months agoexample: Update example_cli
valued mammal [Mon, 24 Jun 2024 15:59:22 +0000 (11:59 -0400)]
example: Update example_cli

16 months agobdk_wallet: remove unnecessary calls to calc_checksum
Antoine Poinsot [Thu, 25 Jul 2024 14:51:16 +0000 (16:51 +0200)]
bdk_wallet: remove unnecessary calls to calc_checksum

This code was:
1. Removing the checksum from the descriptor string, asserting it was
   present
2. Re-calculating the checksum on the descriptor string absent the
   checksum

Instead, just use the existing checksum? If we don't trust it we
probably shouldn't assert its presence in the first place.

16 months agobdk_wallet: don't reimplement checksum algorithm, use rust-miniscript
Antoine Poinsot [Thu, 25 Jul 2024 14:47:03 +0000 (16:47 +0200)]
bdk_wallet: don't reimplement checksum algorithm, use rust-miniscript

16 months agobdk_wallet: descriptor: remove unnecessary call to calc_checksum_bytes
Antoine Poinsot [Thu, 25 Jul 2024 14:36:55 +0000 (16:36 +0200)]
bdk_wallet: descriptor: remove unnecessary call to calc_checksum_bytes

It can just be a String.

16 months agoMerge bitcoindevkit/bdk#1524: ci: pin tokio to 1.38.1 to support MSRV 1.63
Steve Myers [Sat, 27 Jul 2024 13:10:31 +0000 (08:10 -0500)]
Merge bitcoindevkit/bdk#1524: ci: pin tokio to 1.38.1 to support MSRV 1.63

28d75304e1319f49ab72c582f03a916ee40463dd ci: pin tokio to 1.38.1 to support MSRV 1.63 (Steve Myers)

Pull request description:

  ### Description

  The latest tokio minor version update from 1.38.1 to 1.39.1 changed it's MSRV from 1.63.0 to 1.70.0, breaking our CI MSRV 1.63 testing. This PR pins `tokio` back to 1.38.1 for our CI MSRV testing.

  ### Notes to the reviewers

  https://github.com/tokio-rs/tokio/pull/6645

  https://crates.io/crates/tokio/versions

  ### 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:
  LagginTimes:
    ACK 28d75304e1319f49ab72c582f03a916ee40463dd
  ValuedMammal:
    ACK 28d75304e1319f49ab72c582f03a916ee40463dd
  oleonardolima:
    ACK 28d75304e1319f49ab72c582f03a916ee40463dd

Tree-SHA512: 9eef750422cb8c3faa15771438e790afae44362d7c77e1d36cf70816ac7dabdd2e408e14502836ec86f845a2f1fe82905000c681fb6b4e873b036a41a280abd9

16 months agoci: pin tokio to 1.38.1 to support MSRV 1.63
Steve Myers [Fri, 26 Jul 2024 03:15:49 +0000 (22:15 -0500)]
ci: pin tokio to 1.38.1 to support MSRV 1.63

17 months agoMerge bitcoindevkit/bdk#1522: Bump bdk version to 1.0.0-beta.1 v1.0.0-beta.1
Steve Myers [Mon, 22 Jul 2024 14:06:49 +0000 (09:06 -0500)]
Merge bitcoindevkit/bdk#1522: Bump bdk version to 1.0.0-beta.1

53bea0d902f49f8f01f164bddcbc21327e2c7032 Bump bdk version to 1.0.0-beta.1 (Steve Myers)

Pull request description:

  ### Description

  Bump bdk version to 1.0.0-beta.1

  bdk_chain to 0.17.0
  bdk_bitcoind_rpc to 0.13.0
  bdk_electrum to 0.16.0
  bdk_esplora to 0.16.0
  bdk_file_store to 0.14.0
  bdk_testenv to 0.7.0
  bdk_hwi to 0.4.0

  ### Notes to the reviewers

  This release completes the 1.0.0-alpha milestone and starts our new 1.0.0-beta milestone series of releases.

  The beta releases will maintain a stable `bdk_wallet` API and be focused on improving testing, docs, CI, and fixing any newly discovered bugs.

ACKs for top commit:
  LLFourn:
    ACK 53bea0d902f49f8f01f164bddcbc21327e2c7032
  LagginTimes:
    ACK 53bea0d902f49f8f01f164bddcbc21327e2c7032
  storopoli:
    ACK 53bea0d902f49f8f01f164bddcbc21327e2c7032

Tree-SHA512: cc2adbdeb7c2786659198da64e96fcb374833666e8d98c3f255e2de5f7283573efe3e3c53fd0c7b0e475fe3ac30d3c88169075e079d4d0b67496fc9a962b39db

17 months agoBump bdk version to 1.0.0-beta.1
Steve Myers [Mon, 22 Jul 2024 02:47:39 +0000 (21:47 -0500)]
Bump bdk version to 1.0.0-beta.1

bdk_chain to 0.17.0
bdk_bitcoind_rpc to 0.13.0
bdk_electrum to 0.16.0
bdk_esplora to 0.16.0
bdk_file_store to 0.14.0
bdk_testenv to 0.7.0
bdk_hwi to 0.4.0

17 months agoMerge bitcoindevkit/bdk#1506: Standardize API ownership in `KeychainTxOutIndex`
Steve Myers [Mon, 22 Jul 2024 02:29:41 +0000 (21:29 -0500)]
Merge bitcoindevkit/bdk#1506: Standardize API ownership in `KeychainTxOutIndex`

79262185d556009c3d3e918f886ba4a51a262351 refactor(chain)!: update KeychainTxOutIndex methods to use owned ScriptBuf (Steve Myers)
7c07b9de02edf9f2c2b8a153f7bc4c0ca0823b02 refactor(chain)!: update KeychainTxOutIndex methods to use owned K (Rob N)

Pull request description:

  ### Description

  Make all method signatures of `KeychainTxOutIndex` take owned `K` and use `ScriptBuf` instead of its borrowed counterpart `&Script`. Fixes #1482

  ### Notes to the reviewers

  Steve also added a CI fix as well

  ### Changelog notice

  - Make all method signatures of `KeychainTxOutIndex` take owned `K`
  - Update `KeychainTxOutIndex` methods to use `ScriptBuf`

  ### 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:

  * [x] 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

Top commit has no ACKs.

Tree-SHA512: 3cb7d627ef6f38e1eaf6b88174f143c42dfc4d34e3d3d56cc843c256b2f32360fd00fa9ee328d0a41dac1f46771ccae797a96d9e3cee6f5ac4ef63e27cf6b7b7

17 months agorefactor(chain)!: update KeychainTxOutIndex methods to use owned ScriptBuf
Steve Myers [Tue, 9 Jul 2024 21:51:12 +0000 (16:51 -0500)]
refactor(chain)!: update KeychainTxOutIndex methods to use owned ScriptBuf

17 months agorefactor(chain)!: update KeychainTxOutIndex methods to use owned K
Rob N [Mon, 8 Jul 2024 17:44:35 +0000 (07:44 -1000)]
refactor(chain)!: update KeychainTxOutIndex methods to use owned K

17 months agoMerge bitcoindevkit/bdk#1514: refactor(wallet)!: rework persistence, changeset, and...
Steve Myers [Mon, 22 Jul 2024 01:13:30 +0000 (20:13 -0500)]
Merge bitcoindevkit/bdk#1514: refactor(wallet)!: rework persistence, changeset, and construction

64eb5763487df3c6cbb626e51f96ab6e47c5de22 chore(wallet): Fix ChangeSet::merge (LLFourn)
8875c92ec114ba9ca0ea8402d65d7a236566b618 chore(wallet): Fix descriptor mismatch error keychain (LLFourn)
2cf07d686b19787b5e97e0d5ed0b4cce7f56549f refactor(chain,wallet)!: move rusqlite things into it's own file (志宇)
93f9b83e275e8ab67630c925a39de6c01611a01b chore(chain): rm unused `sqlite` types (志宇)
892b97d4416d9d38ebf3d7e0c52636f110042302 feat(chain,wallet)!: Change persist-traits to be "safer" (志宇)
3aed4cf1798d7bd0189de315f5d7eacf212edb40 test(wallet): ensure checks work when loading wallet (志宇)
af4ee0fa4b82ddafa10c6b7fc35a2532351cd003 refactor(wallet)!: Make `bdk_wallet::ChangeSet` non-exhaustive (志宇)
22d02ed3d19e763d1ff54e3ec3657ed39c4ad66c feat!: improve wallet building methods (志宇)
eb73f0659e0046f39f5bf6a07d4145a19f865794 refactor!: move `WalletChangeSet` to `bdk_wallet` and fix import paths (志宇)
6b43001951db7738f788bcdbb46c8c1cd3e24a66 feat!: Rework sqlite, changesets, persistence and wallet-construction (志宇)

Pull request description:

  Closes #1496
  Closes #1498
  Closes #1500

  ### Description

  Rework sqlite: Instead of only supported one schema (defined in `bdk_sqlite`), we have a schema per changeset type for more flexiblity.

  * rm `bdk_sqlite` crate (as we don't need `bdk_sqlite::Store` anymore).
  * add `sqlite` feature on `bdk_chain` which adds methods on each changeset type for initializing tables, loading the changeset and writing.

  Rework changesets: Some callers may want to use `KeychainTxOutIndex` where `K` may change per descriptor on every run. So we only want to persist the last revealed indices by `DescriptorId` (which uniquely-ish identifies the descriptor).

  * rm `keychain_added` field from `keychain_txout`'s changeset.
  * Add `keychain_added` to `CombinedChangeSet` (which is renamed to `WalletChangeSet`).

  Rework persistence: add back some safety and convenience when persisting our types. Working with changeset directly (as we were doing before) can be cumbersome.

  * Intoduce `struct Persisted<T>` which wraps a type `T` which stores staged changes to it. This adds safety when creating and or loading `T` from db.
  * `struct Persisted<T>` methods, `create`, `load` and `persist`, are available if `trait PersistWith<Db>` is implemented for `T`. `Db` represents the database connection and `PersistWith` should be implemented per database-type.
  * For async, we have `trait PersistedAsyncWith<Db>`.
  * `Wallet` has impls of `PersistedWith<rusqlite::Connection>`, `PersistedWith<rusqlite::Transaction>` and `PersistedWith<bdk_file_store::Store>` by default.

  Rework wallet-construction: Before, we had multiple methods for loading and creating with different input-counts so it would be unwieldly to add more parameters in the future. This also makes it difficult to impl `PersistWith` (which has a single method for `load` that takes in `PersistWith::LoadParams` and a single method for `create` that takes in `PersistWith::CreateParams`).

  * Introduce a builder pattern when constructing a `Wallet`. For loading from persistence or `ChangeSet`, we have `LoadParams`. For creating a new wallet, we have `CreateParams`.

  ### Notes to the reviewers

  TODO

  ### Changelog notice

  ```
  ### Added

  - Add `sqlite` feature to `bdk_chain` which introduces methods on changeset types that encode/decode changesets to SQLite database.
  * Introduce `PersistWith<Db>` and `PersistAsyncWith<Db>` traits and a `Persisted` wrapper. This ergonomically makes sure user inits the db before reading/writing to it.

  ### Changed

  - Moved `bdk_chain::CombinedChangeSet` to `bdk_wallet::ChangeSet` and added `keychain_added` field.
  - `bdk_wallet::Wallet` construction now uses a builder API using the newly introduced `CreateParams` and `LoadParams`.

  ### Removed

  - Remove `keychains_added` field from `bdk_chain::keychain_txout::ChangeSet`.

  ```
  ### 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

ACKs for top commit:
  LLFourn:
    ACK: 64eb5763487df3c6cbb626e51f96ab6e47c5de22
  notmandatory:
    Re ACK 64eb5763487df3c6cbb626e51f96ab6e47c5de22

Tree-SHA512: b8a1d48aea26d9fa293a8387a3533cd16c8ddae890f94d61fb91efa492fb05ac5e0a66200d64d7c857774368d5f0f8991a98684307029c25f50a1d8fceee8e67

17 months agochore(wallet): Fix ChangeSet::merge
LLFourn [Sun, 21 Jul 2024 17:01:52 +0000 (03:01 +1000)]
chore(wallet): Fix ChangeSet::merge

h/t @ValuedMammal

17 months agochore(wallet): Fix descriptor mismatch error keychain
LLFourn [Sun, 21 Jul 2024 16:57:00 +0000 (02:57 +1000)]
chore(wallet): Fix descriptor mismatch error keychain

17 months agorefactor(chain,wallet)!: move rusqlite things into it's own file
志宇 [Fri, 19 Jul 2024 11:20:34 +0000 (11:20 +0000)]
refactor(chain,wallet)!: move rusqlite things into it's own file

Also fix imports and rename `sqlite` module to `rusqlite_impl`.

17 months agochore(chain): rm unused `sqlite` types
志宇 [Fri, 19 Jul 2024 07:22:09 +0000 (07:22 +0000)]
chore(chain): rm unused `sqlite` types

17 months agofeat(chain,wallet)!: Change persist-traits to be "safer"
志宇 [Fri, 19 Jul 2024 07:05:38 +0000 (07:05 +0000)]
feat(chain,wallet)!: Change persist-traits to be "safer"

Previously, `Persist{Async}With::persist` can be directly called as a
method on the type (i.e. `Wallet`). However, the `db: Db` (which is an
input) may not be initialized. We want a design which makes it harder
for the caller to make this mistake.

We change `Persist{Async}With::persist` to be an "associated function"
which takes two inputs: `db: &mut Db` and `changeset`. However, the
implementer cannot take directly from `Self` (as it's no longer an
input). So we introduce a new trait `Staged` which defines the staged
changeset type and a method that gives us a `&mut` of the staged
changes.

17 months agotest(wallet): ensure checks work when loading wallet
志宇 [Thu, 18 Jul 2024 06:47:34 +0000 (06:47 +0000)]
test(wallet): ensure checks work when loading wallet

17 months agorefactor(wallet)!: Make `bdk_wallet::ChangeSet` non-exhaustive
志宇 [Thu, 18 Jul 2024 05:47:12 +0000 (05:47 +0000)]
refactor(wallet)!: Make `bdk_wallet::ChangeSet` non-exhaustive

17 months agofeat!: improve wallet building methods
志宇 [Thu, 18 Jul 2024 03:04:00 +0000 (03:04 +0000)]
feat!: improve wallet building methods

Remove returning `Result` for builder methods on `CreateParams` and
`LoadParams`.

17 months agorefactor!: move `WalletChangeSet` to `bdk_wallet` and fix import paths
志宇 [Wed, 17 Jul 2024 14:37:10 +0000 (14:37 +0000)]
refactor!: move `WalletChangeSet` to `bdk_wallet` and fix import paths

17 months agofeat!: Rework sqlite, changesets, persistence and wallet-construction
志宇 [Thu, 11 Jul 2024 04:49:01 +0000 (04:49 +0000)]
feat!: Rework sqlite, changesets, persistence and wallet-construction

Rework sqlite: Instead of only supported one schema (defined in
`bdk_sqlite`), we have a schema per changeset type for more flexiblity.

* rm `bdk_sqlite` crate (as we don't need `bdk_sqlite::Store` anymore).
* add `sqlite` feature on `bdk_chain` which adds methods on each
  changeset type for initializing tables, loading the changeset and
  writing.

Rework changesets: Some callers may want to use `KeychainTxOutIndex`
where `K` may change per descriptor on every run. So we only want to
persist the last revealed indices by `DescriptorId` (which uniquely-ish
identifies the descriptor).

* rm `keychain_added` field from `keychain_txout`'s changeset.
* Add `keychain_added` to `CombinedChangeSet` (which is renamed to
  `WalletChangeSet`).

Rework persistence: add back some safety and convenience when persisting
our types. Working with changeset directly (as we were doing before) can
be cumbersome.

* Intoduce `struct Persisted<T>` which wraps a type `T` which stores
  staged changes to it. This adds safety when creating and or loading
  `T` from db.
* `struct Persisted<T>` methods, `create`, `load` and `persist`, are
  avaliable if `trait PersistWith<Db>` is implemented for `T`. `Db`
  represents the database connection and `PersistWith` should be
  implemented per database-type.
* For async, we have `trait PersistedAsyncWith<Db>`.
* `Wallet` has impls of `PersistedWith<rusqlite::Connection>`,
  `PersistedWith<rusqlite::Transaction>` and
  `PersistedWith<bdk_file_store::Store>` by default.

Rework wallet-construction: Before, we had multiple methods for loading
and creating with different input-counts so it would be unwieldly to add
more parameters in the future. This also makes it difficult to impl
`PersistWith` (which has a single method for `load` that takes in
`PersistWith::LoadParams` and a single method for `create` that takes in
`PersistWith::CreateParams`).

* Introduce a builder pattern when constructing a `Wallet`. For loading
  from persistence or `ChangeSet`, we have `LoadParams`. For creating a
  new wallet, we have `CreateParams`.

17 months agoMerge bitcoindevkit/bdk#1489: feat(electrum)!: Update `bdk_electrum` to use merkle...
Steve Myers [Tue, 9 Jul 2024 18:56:15 +0000 (13:56 -0500)]
Merge bitcoindevkit/bdk#1489: feat(electrum)!: Update `bdk_electrum` to use merkle proofs

1a62488abfd6213c2780c1465aebe01dfbb6b20a feat(chain)!: Implement `ConfirmationBlockTime` (Wei Chen)
e761adf48178e2688a817a2b7466b0ebf7902eeb test(electrum): Imported `bdk_esplora` tests into `bdk_electrum` (Wei Chen)
d7f4ab71e22ca3e8868dae22add8839fc25aa7f3 feat(electrum)!: Update `bdk_electrum` to use merkle proofs (Wei Chen)

Pull request description:

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

  ### Description

  This PR is the first step in reworking `bdk_electrum` to use merkle proofs. When we fetch a transaction, we now also obtain the merkle proof and block header for verification. We then insert an anchor only after validation that the transaction exists in a confirmed block. The loop logic that previously existed in `full_scan` to account for re-orgs has also been removed as part of this rework.

  This is a breaking change because `graph_update`s now provide the full `ConfirmationTimeHeightAnchor` type. This removes the need for the `ElectrumFullScanResult` and `ElectrumSyncResult` structs that existed only to provide the option for converting the anchor type from `ConfirmationHeightAnchor` into `ConfirmationTimeHeightAnchor`.

  ### 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 -->

  ### Changelog notice

  <!-- Notice the release manager should include in the release tag message changelog -->
  <!-- See https://keepachangelog.com/en/1.0.0/ for examples -->
  * `ConfirmationTimeHeightAnchor` and `ConfirmationHeightAnchor` have been removed.
  * `ConfirmationBlockTime` has been introduced as a new anchor type.
  * `bdk_electrum`'s `full_scan` and `sync` now return `graph_update`s with `ConfirmationBlockTime`.

  ### 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

ACKs for top commit:
  ValuedMammal:
    ACK 1a62488abfd6213c2780c1465aebe01dfbb6b20a
  notmandatory:
    ACK 1a62488abfd6213c2780c1465aebe01dfbb6b20a

Tree-SHA512: 77af05bffcb9668ecb99b41abacc6b6aa503dc559226fa88c4cab6863e3af431b937706696ec765bb802c9c152333cd430c284d17a6cd190520e10b13d89e02f

17 months agofeat(chain)!: Implement `ConfirmationBlockTime`
Wei Chen [Mon, 1 Jul 2024 05:40:26 +0000 (13:40 +0800)]
feat(chain)!: Implement `ConfirmationBlockTime`

Both `bdk_electrum` and `bdk_esplora` now report the exact block
that the transaction is in, which removes the need for having the
old `ConfirmationTimeHeightAnchor` and `ConfirmationHeightAnchor`.
This PR introduces a new, simpler anchor type that can be modified
to support additional data in the future.

17 months agotest(electrum): Imported `bdk_esplora` tests into `bdk_electrum`
Wei Chen [Thu, 4 Jul 2024 10:28:01 +0000 (18:28 +0800)]
test(electrum): Imported `bdk_esplora` tests into `bdk_electrum`

17 months agofeat(electrum)!: Update `bdk_electrum` to use merkle proofs
Wei Chen [Tue, 25 Jun 2024 11:20:44 +0000 (19:20 +0800)]
feat(electrum)!: Update `bdk_electrum` to use merkle proofs

17 months agoMerge bitcoindevkit/bdk#1505: ci: pin cc dependency version to build with rust 1.63
Steve Myers [Mon, 8 Jul 2024 15:41:08 +0000 (10:41 -0500)]
Merge bitcoindevkit/bdk#1505: ci: pin cc dependency version to build with rust 1.63

3f9ed95e2e84ea1d938ecab406740d23cf25db1b ci: pin cc dependency version to build with rust 1.63 (Wei Chen)

Pull request description:

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

  ### Description

  <!-- Describe the purpose of this PR, what's being adding and/or fixed -->
  `cc` version 1.0.106 raised `msrv` to 1.67.
  The previous working version 1.0.105 was pinned for CI to continue working.

  ### 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 -->

  ### Changelog notice

  <!-- Notice the release manager should include in the release tag message changelog -->
  <!-- See https://keepachangelog.com/en/1.0.0/ for examples -->
  * Pinned cc dependency version to build with rust 1.63.

  ### 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:
  storopoli:
    ACK 3f9ed95e2e84ea1d938ecab406740d23cf25db1b
  notmandatory:
    ACK 3f9ed95e2e84ea1d938ecab406740d23cf25db1b

Tree-SHA512: 995786f214c06db278daa07643489cdae557c14ffda4b873d2951ca6b52de64630e39dafcbc43cecaede0911fd6d137b992a868478d4bae674e73b4ecc18650b

17 months agoci: pin cc dependency version to build with rust 1.63
Wei Chen [Mon, 8 Jul 2024 15:20:26 +0000 (23:20 +0800)]
ci: pin cc dependency version to build with rust 1.63

17 months agoMerge bitcoindevkit/bdk#1503: feat(wallet): simplify `public_descriptor` fn and...
Steve Myers [Mon, 8 Jul 2024 04:20:20 +0000 (23:20 -0500)]
Merge bitcoindevkit/bdk#1503: feat(wallet): simplify  `public_descriptor` fn and remove `get_descriptor_for_keych…

e7ec5a873328c9b68836306086bd9b021e9c952a refactor(wallet)!: remove redundant get_descriptor_for_keychain (Giovanni Napoli)

Pull request description:

  Fixes #1501

  ### Description

  Simplifies `public_descriptor` function by using `get_descriptor` and removes `get_descriptor_for_keychain`.

  ### Notes to the reviewers

  Tested with `cargo test --all-features`.

  ### Changelog notice

  - Simplifies `public_descriptor` function and removes `get_descriptor_for_keychain`

  ### 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 e7ec5a873328c9b68836306086bd9b021e9c952a
  storopoli:
    ACK https://github.com/bitcoindevkit/bdk/commit/e7ec5a873328c9b68836306086bd9b021e9c952a

Tree-SHA512: 5981190ac882e08e42b1be53c55afb70c4ba7e7a99a8ae2a4e05f0618d0eb23849ce544024bb406e6a6918d9e9757d9ff6ad5a701cd9814b686e36f1ea16b44a

17 months agoMerge bitcoindevkit/bdk#1502: chore(chain)!: Rename `Append` to `Merge`
Steve Myers [Mon, 8 Jul 2024 01:49:01 +0000 (20:49 -0500)]
Merge bitcoindevkit/bdk#1502: chore(chain)!: Rename `Append` to `Merge`

962305f41546613b5b41b4131d4a5594f01a2de0 chore(chain)!: Rename `Append` to `Merge` (Wei Chen)

Pull request description:

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

  ### Description

  <!-- Describe the purpose of this PR, what's being adding and/or fixed -->
  Renames the `Append` trait to `Merge`.

  ### 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 -->

  ### Changelog notice

  <!-- Notice the release manager should include in the release tag message changelog -->
  <!-- See https://keepachangelog.com/en/1.0.0/ for examples -->
  * Rename `bdk_chain::Append` to `bdk_chain::Merge`.

  ### 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 962305f41546613b5b41b4131d4a5594f01a2de0

Tree-SHA512: 2019d9ed631776850cda39c9a53bdd3660c7f4715d8c418824d8ad13718f2b2fd160159e03fd63743dbf0b9e91cfdfed7e4cd4a591636f67d2aaec419486d136

17 months agochore(chain)!: Rename `Append` to `Merge`
Wei Chen [Thu, 4 Jul 2024 14:09:04 +0000 (22:09 +0800)]
chore(chain)!: Rename `Append` to `Merge`

17 months agoMerge pull request #1493 from ValuedMammal/refactor/keychain-balance
Lloyd Fournier [Sat, 6 Jul 2024 12:37:02 +0000 (22:37 +1000)]
Merge pull request #1493 from ValuedMammal/refactor/keychain-balance

[chain] Create module `indexer`

17 months agorefactor(wallet)!: remove redundant get_descriptor_for_keychain
Giovanni Napoli [Sat, 6 Jul 2024 11:39:49 +0000 (13:39 +0200)]
refactor(wallet)!: remove redundant get_descriptor_for_keychain

Simplify Wallet::public_descriptor() and update Wallet internals to use
public_descriptor() instead of get_descriptor_for_keychain().

17 months agoMerge bitcoindevkit/bdk#1487: Add support for custom sorting and deprecate BIP69
Steve Myers [Fri, 5 Jul 2024 20:20:50 +0000 (15:20 -0500)]
Merge bitcoindevkit/bdk#1487: Add support for custom sorting and deprecate BIP69

3bee563c810ace941e0e80ee8e410d843a05f5d8 refactor(wallet)!: remove TxOrdering::Bip69Lexicographic (nymius)
e5cb7b206619f5f3437e5ee95ed3e53885b745e6 feat(wallet): add TxOrdering::Custom (FadedCoder)

Pull request description:

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

  ### Description

  Resolves https://github.com/bitcoindevkit/bdk/issues/534.

  Resumes from the work in https://github.com/bitcoindevkit/bdk/pull/556.

  Add custom sorting function for inputs and outputs through `TxOrdering::Custom` and deprecates `TxOrdering::Bip69Lexicographic`.

  <!-- Describe the purpose of this PR, what's being adding and/or fixed -->

  ### Notes to the reviewers

  I tried consider all discussions in https://github.com/bitcoindevkit/bdk/issues/534 while implementing some changes to the original PR. I created a summary of the considerations I had while implementing this:

  ##### Why use smart pointers?
  The size of enums and structs should be known at compilation time. A struct whose fields implements some kind of trait cannot be specified without using a smart pointer because the size of the implementations of the trait cannot be known beforehand.

  ##### Why `Arc` or `Rc` instead of `Box`?
  The majority of the useful smart pointers that I know (`Arc`, `Box`, `Rc`) for this case implement `Drop` which rules out the implementation of `Copy`, making harder to manipulate a simple enum like `TxOrdering`. `Clone` can be used instead, implemented by `Arc` and `Rc`, but not implemented by `Box`.

  #####  Why `Arc` instead of `Rc`?
  Multi threading I guess.

  ##### Why using a type alias like `TxVecSort`?
  cargo-clippy was accusing a too complex type if using the whole type inlined in the struct inside the enum.

  ##### Why `Fn` and not `FnMut`?
  `FnMut` is not allowed inside `Arc`. I think this is due to the `&mut self` ocupies the first parameter of the `call` method when desugared (https://rustyyato.github.io/rust/syntactic/sugar/2019/01/17/Closures-Magic-Functions.html), which doesn't respects `Arc` limitation of not having mutable references to data stored inside `Arc`:
  Quoting the [docs](https://doc.rust-lang.org/std/sync/struct.Arc.html):
  > you cannot generally obtain a mutable reference to something inside an `Arc`.

  `FnOnce` > `FnMut` > `Fn`, where `>` stands for "is supertrait of", so, `Fn` can be used everywhere `FnMut` is expected.

  ##### Why not `&'a dyn FnMut`?
  It needs to include a lifetime parameter in `TxOrdering`, which will force the addition of a lifetime parameter in `TxParams`, which will require the addition of a lifetime parameter in a lot of places more. **Which one is preferable?**

  <!-- 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 -->

  ### Changelog notice

  - Adds new `TxOrdering` variant: `TxOrdering::Custom`. A structure that stores the ordering functions to sort the inputs and outputs of a transaction.
  - Deprecates `TxOrdering::Bip69Lexicographic`.

  <!-- 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:

  * [ ] 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
  * [ ] I've added docs for the new feature

Top commit has no ACKs.

Tree-SHA512: 0d3e3ea9aee3a6c9e9d5e1ae93215be84bd1bd99907a319976517819aeda768a7166860a48a8d24abb30c516e0129decb6a6aebd8f24783ea2230143e6dcd72a

17 months agorefactor(wallet)!: remove TxOrdering::Bip69Lexicographic
nymius [Tue, 25 Jun 2024 23:20:54 +0000 (20:20 -0300)]
refactor(wallet)!: remove TxOrdering::Bip69Lexicographic

BIP 69 proposed a deterministic way to sort transaction inputs and
outputs with the idea of enhancing privacy. It was later discovered
there was no such enhancement but rather a decrement in privacy due to
this sorting.
To avoid the promotion of bad practices, the
TxOrdering::Bip69Lexicographic variant which implemented this BIP for
BDK is removed with this change.
Notice that you can still produce a BIP 69 compliant transaction
defining order functions for TxOrdering::Custom.

Signed-off-by: Steve Myers <steve@notmandatory.org>
17 months agofeat(wallet): add TxOrdering::Custom
FadedCoder [Sun, 27 Feb 2022 05:49:53 +0000 (11:19 +0530)]
feat(wallet): add TxOrdering::Custom

The deterministic sorting of transaction inputs and outputs proposed in
BIP 69 doesn't improve the privacy of transactions as originally
intended. In the search of not spreading bad practices but still provide
flexibility for possible use cases depending on particular order of the
inputs/outpus of a transaction, a new TxOrdering variant has been added
to allow the implementation of these orders through the definition of
comparison functions.

Signed-off-by: Steve Myers <steve@notmandatory.org>
17 months agoref(chain)!: create module `indexer`
valued mammal [Fri, 28 Jun 2024 13:07:36 +0000 (09:07 -0400)]
ref(chain)!: create module `indexer`

and replace keychain module with `balance.rs`

17 months agoMerge bitcoindevkit/bdk#1416: [chain] Change tx_last_seen to `Option<u64>`
Steve Myers [Tue, 2 Jul 2024 21:43:42 +0000 (16:43 -0500)]
Merge bitcoindevkit/bdk#1416: [chain] Change tx_last_seen to `Option<u64>`

af75817d4bedbb5e148812d1073fd0729a23358b ref(tx_graph): Change last_seen to `HashMap<Txid, u64>` (valued mammal)
6204d2c766f968af6b63c664dda61fa8fc897e85 feat(tx_graph): Add method `txs_with_no_anchor_or_last_seen` (valued mammal)
496601b8b148afd2199a530d40edeafcb7967d46 test(tx_graph): Add test for `list_canonical_txs` (valued mammal)
c4057297a96ccbd49d984b7139994b801c2120dc wallet: delete method `insert_anchor` (valued mammal)
b34790c6b6d612661a4595bf10910294af862323 ref(tx_graph)!: Rename `list_chain_txs` to `list_canonical_txs` (valued mammal)
2ce4bb4dfc4f7b779a815eca45a3f6cee3d6c4e0 test(indexed_tx_graph): Add test_get_chain_position (valued mammal)
36f58870cb6eb24fe8c50ba4cf3ede910dd11fe8 test(wallet): Add test_insert_tx_balance_and_utxos (valued mammal)
bbc19c3536b25c78be8b5f3fe0cd9810aa679742 fix(tx_graph)!: Change tx_last_seen to `Option<u64>` (valued mammal)
324eeb3eb4e5231c6a81e6d197df788ad08b23a8 fix(wallet)!: Rework `Wallet::insert_tx` to no longer insert anchors (valued mammal)

Pull request description:

  The PR changes the type of last_seen to `Option<u64>` for `txs` member of `TxGraph`.

  This fixes an issue where unbroadcast and otherwise non-canonical transactions were returned from methods `list_chain_txs` and `Wallet::transactions` because every new tx inserted had a last_seen of 0 making it appear unconfirmed.

  fixes #1446
  fixes #1396

  ### Notes to the reviewers

  ### Changelog notice

  Changed
  - Member `last_seen_unconfirmed` of `TxNode` is changed to `Option<u64>`
  - Renamed `TxGraph` method `list_chain_txs` to `list_canonical_txs`
  - Changed `Wallet::insert_tx` to take a single `tx: Transaction` as parameter

  Added
  - Add method `txs_with_no_anchor_or_last_seen` for `TxGraph`
  - Add method `unbroadcast_transactions` for `Wallet`

  ### 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:
  notmandatory:
    Re ACK af75817d4bedbb5e148812d1073fd0729a23358b

Tree-SHA512: e664b3b49e2f547873923f15dffbbc7fa032b6240e5b856b180e9e26123ca141864d10448912dc4a31bbb200c75bef4251a910a4330dac17ee6841b564612d13

17 months agoref(tx_graph): Change last_seen to `HashMap<Txid, u64>`
valued mammal [Sun, 30 Jun 2024 14:53:35 +0000 (10:53 -0400)]
ref(tx_graph): Change last_seen to `HashMap<Txid, u64>`

17 months agofeat(tx_graph): Add method `txs_with_no_anchor_or_last_seen`
valued mammal [Tue, 25 Jun 2024 16:46:53 +0000 (12:46 -0400)]
feat(tx_graph): Add method `txs_with_no_anchor_or_last_seen`

17 months agotest(tx_graph): Add test for `list_canonical_txs`
valued mammal [Tue, 25 Jun 2024 16:41:45 +0000 (12:41 -0400)]
test(tx_graph): Add test for `list_canonical_txs`

17 months agowallet: delete method `insert_anchor`
valued mammal [Tue, 25 Jun 2024 15:00:17 +0000 (11:00 -0400)]
wallet: delete method `insert_anchor`

17 months agoref(tx_graph)!: Rename `list_chain_txs` to `list_canonical_txs`
valued mammal [Tue, 4 Jun 2024 11:48:15 +0000 (07:48 -0400)]
ref(tx_graph)!: Rename `list_chain_txs` to `list_canonical_txs`

17 months agotest(indexed_tx_graph): Add test_get_chain_position
valued mammal [Mon, 3 Jun 2024 23:55:10 +0000 (19:55 -0400)]
test(indexed_tx_graph): Add test_get_chain_position

17 months agotest(wallet): Add test_insert_tx_balance_and_utxos
valued mammal [Mon, 3 Jun 2024 20:41:00 +0000 (16:41 -0400)]
test(wallet): Add test_insert_tx_balance_and_utxos

17 months agofix(tx_graph)!: Change tx_last_seen to `Option<u64>`
valued mammal [Thu, 23 May 2024 21:33:45 +0000 (17:33 -0400)]
fix(tx_graph)!: Change tx_last_seen to `Option<u64>`

Also fixup `test_list_owned_txouts` to check that the right
outputs, utxos, and balance are returned at different local
chain heights.

This fixes an issue where unbroadcast and otherwise non-canonical
transactions were returned from methods `list_chain_txs` and
`Wallet::transactions` because every tx inserted had a last_seen
of 0 making it appear unconfirmed.

Note this commit changes the way `Balance` is represented due to
new logic in `try_get_chain_position` that no longer considers
txs with non-canonical anchors. Before this change, a tx anchored
to a block that is reorged out had a permanent effect on the
pending balance, and now only txs with a last_seen time or an
anchor confirmed in the best chain will return a `ChainPosition`.

17 months agoMerge bitcoindevkit/bdk#1486: refactor(chain): calculate DescriptorId as the sha256...
Steve Myers [Fri, 28 Jun 2024 22:21:17 +0000 (17:21 -0500)]
Merge bitcoindevkit/bdk#1486: refactor(chain): calculate DescriptorId as the sha256 hash of the spk at index 0

8f5b172e59b4d5e199b98777855b0d9b46742f66 test(wallet): verify wallet panics in dev mode if using keychains with duplicate spks (Steve Myers)
46c6f18cc3ff71efda2b8547aa32854f9b88762e refactor(chain): calculate DescriptorId as sha256 hash of spk at index 0 (Steve Myers)

Pull request description:

  ### Description

  Rename `DescriptorId` to `KeychainId` and `descriptor_id()` to `keychain_id()`.

  Calculate keychain ids as the hash of the spk derived from its descriptor as index 0.

  Added docs to `Wallet` and `KeychainTxOutIndex::insert_descriptor()` explaining that it's the users responsibility not to use wildcard and non-wildcard descriptors that can derive the same script pubkey. I also recommended for `Wallet` that legacy non-wildcard descriptors be added to a temporary `Wallet` and swept into a modern wildcard descriptor.

  ### Notes to the reviewers

  fixes #1483

  ### Changelog notice

  changed

  - Renamed DescriptorId to KeychainId, DescriptorExt::descriptor_id() to keychain_id().

  ### 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
  * [x] I'm linking the issue being fixed by this PR

ACKs for top commit:
  LLFourn:
    ACK 8f5b172e59b4d5e199b98777855b0d9b46742f66
  oleonardolima:
    Concept ACK 8f5b172e59b4d5e199b98777855b0d9b46742f66

Tree-SHA512: 07defa208d9cfcd61bc6e31ded06a287c392c51bcc4949f601ecfac635c3443e7d08c62d92618ed894dc5ef13cdcf784771a6bf8904a5397110bedb1563f52d4

17 months agoMerge bitcoindevkit/bdk#1490: Remove usage of `blockdata::` from bitcoin paths
Steve Myers [Fri, 28 Jun 2024 20:54:47 +0000 (15:54 -0500)]
Merge bitcoindevkit/bdk#1490: Remove usage of `blockdata::` from bitcoin paths

cf7aca84d113e639441350651112e9e701364497 Remove usage of blockdata:: from bitcoin paths (Tobin C. Harding)

Pull request description:

  ### Description

  In `rust-bitcoin` the `blockdata` module is a code organisation thing, it should never have been public. One day those guys would like to remove it, so as not to be a PITA for `bdk` when they do lets remove all usage of `blockdata::` now.

  ### Changelog notice

  Internal change only, no externally visible changes.

  ### 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

Top commit has no ACKs.

Tree-SHA512: 4c5e54a2ac3f71835c25ce97ad0acd1859e5ae8d45ebfde087e19e9494754e0aa70a47ca5f3d6a3b509f27e28ef9d4a5269573c686250f43834d09378155681c

17 months agotest(wallet): verify wallet panics in dev mode if using keychains with duplicate...
Steve Myers [Wed, 26 Jun 2024 17:01:52 +0000 (12:01 -0500)]
test(wallet): verify wallet panics in dev mode if using keychains with duplicate spks

17 months agorefactor(chain): calculate DescriptorId as sha256 hash of spk at index 0
Steve Myers [Tue, 25 Jun 2024 15:51:51 +0000 (10:51 -0500)]
refactor(chain): calculate DescriptorId as sha256 hash of spk at index 0

Also update docs to explain how KeychainTxOutIndex handles descriptors that
generate the same spks.

17 months agoRemove usage of blockdata:: from bitcoin paths
Tobin C. Harding [Wed, 26 Jun 2024 04:33:00 +0000 (14:33 +1000)]
Remove usage of blockdata:: from bitcoin paths

In `rust-bitcoin` the `blockdata` module is a code organisation thing,
it should never have been public. One day those guys would like to
remove it, so as not to be a PITA for `bdk` when they do lets remove all
usage of `blockdata::` now.

Internal change only, no externally visible changes.

17 months agoMerge bitcoindevkit/bdk#1468: feat: use `Weight` type instead of `usize`
Steve Myers [Wed, 26 Jun 2024 22:34:52 +0000 (17:34 -0500)]
Merge bitcoindevkit/bdk#1468: feat: use `Weight` type instead of `usize`

438cd4682d14b5f4c6c9c653c9f05ccaaecb815d refactor(wallet)!: change WeightedUtxo to use Weight type (Leonardo Lima)

Pull request description:

  fixes #1466
  depends on #1448
  <!-- You can erase any parts of this template not applicable to your Pull Request. -->

  ### Description

  This PR is a follow-up on top of #1448, and should be rebased and merged after it, it uses the rust-bitcoin `Weight` type instead of the current `usize` usage.

  NOTE: ~~It also adds a new `MiniscriptError` variant, and remove the `.unwrap()` usage.~~ As suggested I'll address this on another issue #1485, trying to reproduce the error first.

  <!-- Describe the purpose of this PR, what's being adding and/or fixed -->

  ### Notes to the reviewers
  It should be ready to review after #1448 gets merged.
  <!-- 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 -->

  ### Changelog notice
  - Change `WeightedUtxo` `satisfaction_weight` has been changed to use `Weight` type.
  - Change `TxBuilder` methods `add_foreign_utxo` and `add_foreign_utxo_with_sequence` to expect `Weight` as `satisfaction_weight` type.

  <!-- 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:
  storopoli:
    Anyways, ACK 438cd4682d14b5f4c6c9c653c9f05ccaaecb815d
  notmandatory:
    ACK 438cd4682d14b5f4c6c9c653c9f05ccaaecb815d

Tree-SHA512: 1998fe659833da890ce07aa746572ae24d035e636732c1a11b7828ffed48e753adb4108f42d00b7cd05e6f45831a7a9840faa26f94058fc13760497837af002f

17 months agorefactor(wallet)!: change WeightedUtxo to use Weight type
Leonardo Lima [Fri, 7 Jun 2024 19:33:02 +0000 (16:33 -0300)]
refactor(wallet)!: change WeightedUtxo to use Weight type

17 months agoMerge bitcoindevkit/bdk#1424: Remove trait ComputeSighash
Steve Myers [Tue, 25 Jun 2024 19:15:12 +0000 (14:15 -0500)]
Merge bitcoindevkit/bdk#1424: Remove trait ComputeSighash

55a17293a455435c868f60f0c9f06ba80f2f0e4c ref(signer): Use `Psbt::sighash_ecdsa` for computing sighashes (valued mammal)
f2a2dae84cd04df4301f91745efa137975eeb8e4 refactor(signer): Remove trait ComputeSighash (valued mammal)

Pull request description:

  This PR does some cleanup of the `bdk_wallet` signer module most notably by removing the internal trait `ComputeSighash` and replacing old code for computing the sighash (for legacy and segwit context) with a single method [`Psbt::sighash_ecdsa`](https://docs.rs/bitcoin/0.31.2/bitcoin/psbt/struct.Psbt.html#method.sighash_ecdsa). The logic for computing the taproot sighash is unchanged and extracted to a new helper function `compute_tap_sighash`.

  - [x] Unimplement `ComputeSighash`
  - [x] Try de-duplicating code by using `Psbt::sighash_ecdsa`. see https://github.com/bitcoindevkit/bdk/pull/1023#discussion_r1263140218
  - Not done in this PR: Consider removing unused `SignerError` variants

  fixes #1038

  ### 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

Top commit has no ACKs.

Tree-SHA512: 56af3c9c463513ca3bae5480aa5b90d78de119c3c09c824a7220eb6832d5f403b172afc8168228918ea1adabb4bf8fca858790adfebf84fc334b4fc1cc99d3cd

17 months agoref(signer): Use `Psbt::sighash_ecdsa` for computing sighashes
valued mammal [Fri, 24 May 2024 23:20:31 +0000 (19:20 -0400)]
ref(signer): Use `Psbt::sighash_ecdsa` for computing sighashes

- Change param `hash` to `&Message` in `sign_psbt_ecdsa`
- Remove unused methods `compute_legacy_sighash`,
and `compute_segwitv0_sighash`.
- Match on `self.ctx` when signing for `SignerWrapper<PrivateKey>`

17 months agorefactor(signer): Remove trait ComputeSighash
valued mammal [Wed, 1 May 2024 18:47:20 +0000 (14:47 -0400)]
refactor(signer): Remove trait ComputeSighash

18 months agofix(wallet)!: Rework `Wallet::insert_tx` to no longer insert anchors
valued mammal [Mon, 20 May 2024 11:01:05 +0000 (07:01 -0400)]
fix(wallet)!: Rework `Wallet::insert_tx` to no longer insert anchors

since we'd be lacking context that should normally occur during
sync with a chain source. The logic for inserting a graph
anchor from a `ConfirmationTime` is moved to the wallet common
test module in order to simulate receiving new txs and
confirming them.

18 months agoMerge bitcoindevkit/bdk#1395: Remove `rand` dependency from `bdk`
Steve Myers [Sun, 23 Jun 2024 02:21:58 +0000 (21:21 -0500)]
Merge bitcoindevkit/bdk#1395: Remove `rand` dependency from `bdk`

4bddb0de6262fb4014d51baf8c9453eb45a3d0ef feat(wallet): add back TxBuilder finish() and sort_tx() with thread_rng() (Steve Myers)
45c0cae0a461232bf746375083e2005c5df5f913 fix(bdk): remove rand dependency (rustaceanrob)

Pull request description:

  ### Description

  WIP towards removing `rand` fixes #871

  The `rand` dependency was imported explicitly, but `rand` is also implicitly used through the `rand-std` feature flag on `bitcoin`.

  ### Notes to he reviewers

  **Updated:**

  `rand` was used primarily in two parts of `bdk`. Particularly in signing and in building a transaction.

  Signing:
  - Used implicitly in [`sign_schnorr`](https://docs.rs/bitcoin/latest/bitcoin/key/struct.Secp256k1.html#method.sign_schnorr), but nowhere else within `signer`.

  Transaction ordering:
  - Used to shuffle the inputs and outputs of a transaction, the default
  - Used in the single random draw __as a fallback__ to branch and bound during coin selection. Branch and bound is the default coin selection option.

  See conversation for proposed solutions.

  ### Changelog notice

  - Remove the `rand` dependency from `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

  #### New Features:

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

  #### 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:
  ValuedMammal:
    ACK 4bddb0de6262fb4014d51baf8c9453eb45a3d0ef
  notmandatory:
    ACK 4bddb0de6262fb4014d51baf8c9453eb45a3d0ef

Tree-SHA512: 662d9bcb1e02f8195d73df16789b8c2aba8ccd7b37ba713ebb0bfd19c66163acbcb6f266b64f88347cbb1f96b88c8a150581012cbf818d1dc8b4437b3e53fc62

18 months agoMerge bitcoindevkit/bdk#1476: fix(wallet)!: Simplify `SignOptions` and improve finali...
志宇 [Thu, 20 Jun 2024 04:40:24 +0000 (12:40 +0800)]
Merge bitcoindevkit/bdk#1476: fix(wallet)!: Simplify `SignOptions` and improve finalization logic

996605f2bf9440dd42647123a127c038253f0247 fix(wallet)!: Simplify `SignOptions` and improve finalization logic (valued mammal)

Pull request description:

  Rather than comingle various `SignOptions` with the finalization step, we simply clear all fields when finalizing as per the PSBT spec in BIPs 174 and 371 which is more in line with user expectations.

  ### Notes to the reviewers

  I chose to re-implement some parts of [`finalize_input`](https://docs.rs/miniscript/latest/src/miniscript/psbt/finalizer.rs.html#434) since it's fairly straightforward, see also https://github.com/bitcoindevkit/bdk/issues/1461#issuecomment-2171983426. I had to refactor some wallet tests but didn't go out of my way to add additional tests.

  closes #1461

  ### Changelog notice

  - Removed field `remove_partial_sigs` from `SignOptions`
  - Removed field `remove_taproot_extras` from `SignOptions`

  ### 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
  * [ ] 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:
  evanlinjin:
    re-ACK 996605f2bf9440dd42647123a127c038253f0247

Tree-SHA512: 63e78e75c22031424e87fcc26cd6b0015c626cd57c02680256bad9d1783cef71f4048b2d7ce5d0425cd4239351e37dd0e2a626dda7e8417af7fc52cb0afe6933

18 months agofeat(wallet): add back TxBuilder finish() and sort_tx() with thread_rng()
Steve Myers [Wed, 19 Jun 2024 21:35:04 +0000 (16:35 -0500)]
feat(wallet): add back TxBuilder finish() and sort_tx() with thread_rng()

18 months agofix(wallet)!: Simplify `SignOptions` and improve finalization logic
valued mammal [Tue, 11 Jun 2024 21:56:31 +0000 (17:56 -0400)]
fix(wallet)!: Simplify `SignOptions` and improve finalization logic

Rather than comingle various `SignOptions` with the finalization
step, we simply clear all fields when finalizing as per the PSBT
spec in BIPs 174 and 371 which is more in line with user
expectations.

18 months agofix(bdk): remove rand dependency
rustaceanrob [Wed, 3 Apr 2024 00:31:18 +0000 (14:31 -1000)]
fix(bdk): remove rand dependency

18 months agoMerge bitcoindevkit/bdk#1472: Bump bdk version to 1.0.0-alpha.13 v1.0.0-alpha.13
Steve Myers [Sat, 15 Jun 2024 02:38:04 +0000 (21:38 -0500)]
Merge bitcoindevkit/bdk#1472: Bump bdk version to 1.0.0-alpha.13

e21affdbbb9308bd6be38218ae5a26d9c800efe2 Bump bdk version to 1.0.0-alpha.13 (Steve Myers)

Pull request description:

  ### Description

  Bump bdk version to 1.0.0-alpha.13

  bdk_chain to 0.16.0
  bdk_bitcoind_rpc to 0.12.0
  bdk_electrum to 0.15.0
  bdk_esplora to 0.15.0
  bdk_file_store to 0.13.0
  bdk_sqlite keep at 0.2.0
  bdk_testenv to 0.6.0
  bdk_hwi to 0.3.0

  fixes #1471

Top commit has no ACKs.

Tree-SHA512: 987adf5084dc84261fb3767d8b1f8ebe3dd94a8a4eb30b8529b70c055e4f122cb48063d205e90831169c2d7b2a1509aef1966857bd6b67e78cfb0d52144822d9

18 months agoBump bdk version to 1.0.0-alpha.13
Steve Myers [Fri, 14 Jun 2024 02:20:05 +0000 (21:20 -0500)]
Bump bdk version to 1.0.0-alpha.13

bdk_chain to 0.16.0
bdk_bitcoind_rpc to 0.12.0
bdk_electrum to 0.15.0
bdk_esplora to 0.15.0
bdk_file_store to 0.13.0
bdk_sqlite keep at 0.2.0
bdk_testenv to 0.6.0
bdk_hwi to 0.3.0

18 months agoMerge bitcoindevkit/bdk#1473: Remove `persist` submodule
Steve Myers [Sat, 15 Jun 2024 02:07:51 +0000 (21:07 -0500)]
Merge bitcoindevkit/bdk#1473: Remove `persist` submodule

a0bf45bef1b53f8aec273f7fe89915f3d41974c0 docs: remove PersistBackend from docs, Cargo.toml and wallet README.md (Steve Myers)
feb27df180938759670afd2c9cd15529a22c4772 feat(chain)!: add `take` convenience method to `Append` trait (志宇)
1eca568be5bb0c234fa1cea2eb7f9424f60974eb feat!: rm `persist` submodule (志宇)

Pull request description:

  ### Description

  @LLFourn suggested these changes which greatly simplifies the amount of code we have to maintain and removes the `async-trait` dependency. We remove `PersistBackend`, `PersistBackendAsync`, `StageExt` and `StageExtAsync` completely. Instead, we introduce `Wallet::take_staged(&mut self) -> Option<ChangeSet>`.

  The original intention to keep a staging area (`StageExt`, `StageExtAsync`) is to enforce:
  1. The caller will not persist an empty changeset.
  2. The caller does not take the staged changeset if the database (`PersistBackend`) fails.

  We achieve `1.` by returning `None` if the staged changeset is empty.

  `2.` is not too important. The caller can try figure out what to do with the changeset if persisting to db fails.

  ### Notes to the reviewers

  I added a `take` convenience method to the `Append` trait. I thought it would be handy for the caller to do a staging area with this.

  ### Changelog notice

  * Remove `persist` submodule from `bdk_chain`.
  * Change `Wallet` to outsource it's persistence logic by introducing `Wallet::take_staged`.
  * Add `take` convenience method to `Append` trait.

  ### 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

ACKs for top commit:
  notmandatory:
    ACK a0bf45bef1b53f8aec273f7fe89915f3d41974c0
  evanlinjin:
    self-ACK a0bf45bef1b53f8aec273f7fe89915f3d41974c0

Tree-SHA512: 38939ab446c84d9baecd4cd36a7b66add5a121212ad5e06ade04a60f7903133dd9a20219e230ab8a40404c47e07b946ccd43085572d71c3a2a80240a2223a500

18 months agodocs: remove PersistBackend from docs, Cargo.toml and wallet README.md
Steve Myers [Fri, 14 Jun 2024 23:09:55 +0000 (18:09 -0500)]
docs: remove PersistBackend from docs, Cargo.toml and wallet README.md

18 months agofeat(chain)!: add `take` convenience method to `Append` trait
志宇 [Fri, 14 Jun 2024 15:21:19 +0000 (23:21 +0800)]
feat(chain)!: add `take` convenience method to `Append` trait

This is useful if the caller wishes to use the type as a staging area.

This is breaking as `Append` has a `Default` bound now.

18 months agofeat!: rm `persist` submodule
志宇 [Fri, 14 Jun 2024 12:42:25 +0000 (20:42 +0800)]
feat!: rm `persist` submodule

Remove `PersistBackend`, `PersistBackendAsync`, `StageExt` and
`StageExtAsync`. Remove `async` feature flag and dependency. Update
examples and wallet.

18 months agoMerge bitcoindevkit/bdk#1458: fix: typo on `SignedAmount` instead of `Amount`
Steve Myers [Fri, 14 Jun 2024 14:53:27 +0000 (09:53 -0500)]
Merge bitcoindevkit/bdk#1458: fix: typo on `SignedAmount` instead of `Amount`

20341a3ca1ab85ad77e022b5028136a635c3f42c fix: typo on `SignedAmount` instead of `Amount` (Leonardo Lima)

Pull request description:

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

  ### Description

  It fixes the typo on the `expect()` message introduced on #1426, noticed at https://github.com/bitcoindevkit/bdk/pull/1426#discussion_r1626761825

  <!-- Describe the purpose of this PR, what's being adding and/or fixed -->

  ### 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:
  storopoli:
    ACK 20341a3ca1ab85ad77e022b5028136a635c3f42c
  notmandatory:
    ACK 20341a3ca1ab85ad77e022b5028136a635c3f42c

Tree-SHA512: 62deb7308b2a6891eeb4598ebdf3c5ee1541fc52fd454bca2816b819bd7f6ab25c18e10c4166c80c4e553bcb3ce2207323376d260484a956837ac857854cbd6b

18 months agoMerge bitcoindevkit/bdk#1454: Refactor wallet and persist mod, remove bdk_persist...
Steve Myers [Thu, 13 Jun 2024 22:46:11 +0000 (17:46 -0500)]
Merge bitcoindevkit/bdk#1454: Refactor wallet and persist mod, remove bdk_persist crate

ec36c7eccacc8347568b77ed1dfc0c50a2524906 feat(example): use changeset staging with rpc polling example (志宇)
19328d4999c19557778b7b108f88f42b1258957e feat(wallet)!: change persist API to use `StageExt` and `StageExtAsync` (志宇)
2e40b0118cc88539f38420e347eb4d562b1be0b1 feat(chain): reintroduce a way to stage changesets before persisting (志宇)
36e82ec6869c5c5c5669d4d049636225f9a8e986 chore(chain): relax `miniscript` feature flag scope (志宇)
9e97ac03307f3194e043ef430e4bde2e5c25254c refactor(persist): update file_store, sqlite, wallet to use bdk_chain::persist (Steve Myers)
54b0c11cbe1d08eb955e50f0ac719a0b19e3032a feat(persist): add PersistAsync trait and StagedPersistAsync struct (Steve Myers)
aa640ab2770bea19259eedea6882b202a5845f35 refactor(persist): rename PersistBackend to Persist, move to chain crate (Steve Myers)

Pull request description:

  ### Description

  Sorry to submit another refactor PR for the persist related stuff, but I think it's worth revisiting. My primary motivations are:

  1. remove `db` from `Wallet` so users have the ability to use `async` storage crates, for example using `sqlx`. I updated docs and examples to let users know they are responsible for persisting changes.
  2. remove the `anyhow` dependency everywhere (except as a dev test dependency). It really doesn't belong in a lib and by removing persistence from `Wallet` it isn't needed.
  3. remove the `bdk_persist` crate and revert back to the original design with generic error types. I kept the `Debug` and `Display` constrains on persist errors so they could still be used with the `anyhow!` macro.

  ### Notes to the reviewers

  I also replaced/renamed old `Persist` with `StagedPersist` struct inspired by #1453, it is only used in examples. The `Wallet` handles it's own staging.

  ### Changelog notice

  Changed

  - Removed `db` from `Wallet`, users are now responsible for persisting changes, see docs and examples.
  - Removed the `bdk_persist` crate and moved logic back to `bdk_chain::persist` module.
  - Renamed `PersistBackend` trait to `Persist`
  - Replaced `Persist` struct with `StagedPersist`

  ### 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:
  ValuedMammal:
    ACK ec36c7eccacc8347568b77ed1dfc0c50a2524906

Tree-SHA512: 380b94ae42411ea174720b7c185493c640425f551742f25576a6259a51c1037b441a238c6043f4fdfbf1490aa15f948a34139f1850d0c18d285110f6a9f36018

18 months agofeat(example): use changeset staging with rpc polling example
志宇 [Thu, 13 Jun 2024 14:36:12 +0000 (22:36 +0800)]
feat(example): use changeset staging with rpc polling example

18 months agofeat(wallet)!: change persist API to use `StageExt` and `StageExtAsync`
志宇 [Thu, 13 Jun 2024 10:22:43 +0000 (18:22 +0800)]
feat(wallet)!: change persist API to use `StageExt` and `StageExtAsync`

18 months agofeat(chain): reintroduce a way to stage changesets before persisting
志宇 [Thu, 13 Jun 2024 08:02:43 +0000 (16:02 +0800)]
feat(chain): reintroduce a way to stage changesets before persisting

A staging area is helpful because we can contain logic to ignore empty
changesets and not clear staging area if the persistence backend fails.

18 months agochore(chain): relax `miniscript` feature flag scope
志宇 [Thu, 13 Jun 2024 06:13:46 +0000 (14:13 +0800)]
chore(chain): relax `miniscript` feature flag scope

Still enable the `persist` submodule without `miniscript` feature flag.
Only disable `CombinedChangeSet`.

Also stop `cargo clippy` from complaining about unused imports when
`miniscript` is disabled.

18 months agorefactor(persist): update file_store, sqlite, wallet to use bdk_chain::persist
Steve Myers [Sat, 1 Jun 2024 05:06:20 +0000 (00:06 -0500)]
refactor(persist): update file_store, sqlite, wallet to use bdk_chain::persist

Also update examples and remove bdk_persist crate.

18 months agofeat(persist): add PersistAsync trait and StagedPersistAsync struct
Steve Myers [Sun, 2 Jun 2024 03:45:11 +0000 (22:45 -0500)]
feat(persist): add PersistAsync trait and StagedPersistAsync struct

18 months agorefactor(persist): rename PersistBackend to Persist, move to chain crate
Steve Myers [Fri, 31 May 2024 19:27:32 +0000 (14:27 -0500)]
refactor(persist): rename PersistBackend to Persist, move to chain crate

Also add refactored StagedPersist to chain crate with tests.

18 months agoMerge bitcoindevkit/bdk#1463: No descriptor ids in spk txout index
志宇 [Thu, 13 Jun 2024 15:10:13 +0000 (23:10 +0800)]
Merge bitcoindevkit/bdk#1463: No descriptor ids in spk txout index

8dd174479f9719309663ed979a5b4b86aca0a6e9 refactor(chain): compute txid once for `KeychainTxOutIndex::index_tx` (志宇)
639d735ca0ae54d8b2c3bc28241032154b94d45e refactor(chain): change field names to be more sane (志宇)
5a02f40122f1bfa06c80bac93f68f5799225d133 docs(chain): fix docs (志宇)
c77e12bae7f465ec7fb08b8be16d99793c757cf0 refactor(chain): `KeychainTxOutIndex` use `HashMap` for fields (志宇)
4d3846abf4f59b4a97bb825281655a6b67275603 chore(chain): s/replenish_lookahead/replenish_inner_index/ (LLFourn)
8779afdb0bf4e9b1004f47f86a770d25938d206d chore(chain): document insert_descriptor invariants better (LLFourn)
69f2a695f7dc25478489080598fea0813ea7d93d refactor(chain): improve replenish lookeahd internals (LLFourn)
5a584d0fd8c138757a10c7af93ec9e09523317e1 chore(chain): Fix Indexed and KeychainIndexed documentaion (Lloyd Fournier)
b8ba5a02066fad7ab2ce276ba071385cd1dbbe3a chore(chain): Improve documentation of keychain::ChangeSet (LLFourn)
101a09a97fa5e8d675c13396b9a800665b1b6c22 chore(chain): Standardise KeychainTxOutIndex return types (LLFourn)
bce070b1d662db7ac120e1d236fdda51842ad738 chore(chain): add type IndexSpk, fix clippy type complexity warning (Steve Myers)
4d2442c37f5c1bd822795271a79676d1ffbe7916 chore(chain): misc docs and insert_descriptor fixes (LLFourn)
bc2a8be97919f0d09b61438527bda24796bcec94 refactor(keychain): Fix KeychainTxOutIndex range queries (LLFourn)
3b2ff0cc953204c9925ace8e2f0bbef409c63ad5 Write failing test for keychain range querying (LLFourn)

Pull request description:

  Fixes #1459

  This reverts part of the changes in #1203. There the `SpkTxOutIndex<(K,u32)>` was changed to `SpkTxOutIndex<(DescriptorId, u32>)`. This led to a complicated translation logic in  `KeychainTxOutIndex` (where the API is based on `K`) to transform calls to it to calls to the underlying `SpkTxOutIndex` (which now indexes by `DescriptorId`). The translation layer was broken when it came to translating range queries from the `KeychainTxOutIndex`. My solution was just to revert this part of the change and remove the need for a translation layer (almost) altogether. A thin translation layer remains to ensure that un-revealed spks are filtered out before being returned from the `KeychainTxOutIndex` methods.

  I feel like this PR could be extended to include a bunch of ergonomics improvements that are easier to implement now. But I think that's the point of https://github.com/bitcoindevkit/bdk/pull/1451 so I held off and should probably go and scope creep that one instead.

  ### 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:
  evanlinjin:
    ACK 8dd174479f9719309663ed979a5b4b86aca0a6e9

Tree-SHA512: 283e6b6d4218902298e2e848fe847a6c85e27af4eee3e4337e3dad6eacf9beaa08ac99b1dce7b6fb199ca53931e543ea365728a81c41567a2e510cce77b12ac0