]> Untitled Git - bdk/log
bdk
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 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

18 months agorefactor(chain): compute txid once for `KeychainTxOutIndex::index_tx`
志宇 [Thu, 13 Jun 2024 14:56:19 +0000 (22:56 +0800)]
refactor(chain): compute txid once for `KeychainTxOutIndex::index_tx`

18 months agorefactor(chain): change field names to be more sane
志宇 [Wed, 12 Jun 2024 14:19:54 +0000 (22:19 +0800)]
refactor(chain): change field names to be more sane

18 months agodocs(chain): fix docs
志宇 [Wed, 12 Jun 2024 13:50:03 +0000 (21:50 +0800)]
docs(chain): fix docs

18 months agorefactor(chain): `KeychainTxOutIndex` use `HashMap` for fields
志宇 [Wed, 12 Jun 2024 11:10:52 +0000 (19:10 +0800)]
refactor(chain): `KeychainTxOutIndex` use `HashMap` for fields

Instead of `BTreeMap` which is less performant.

18 months agochore(chain): s/replenish_lookahead/replenish_inner_index/
LLFourn [Tue, 11 Jun 2024 04:55:06 +0000 (14:55 +1000)]
chore(chain): s/replenish_lookahead/replenish_inner_index/

18 months agochore(chain): document insert_descriptor invariants better
LLFourn [Tue, 11 Jun 2024 04:29:26 +0000 (14:29 +1000)]
chore(chain): document insert_descriptor invariants better

18 months agorefactor(chain): improve replenish lookeahd internals
LLFourn [Tue, 11 Jun 2024 01:48:32 +0000 (11:48 +1000)]
refactor(chain): improve replenish lookeahd internals

see: https://github.com/bitcoindevkit/bdk/pull/1463/files/4eb1e288a9362803b034590e0c56c8cf9cf8b0c2#r1630943639

18 months agochore(chain): Fix Indexed and KeychainIndexed documentaion
Lloyd Fournier [Tue, 11 Jun 2024 01:12:51 +0000 (11:12 +1000)]
chore(chain): Fix Indexed and KeychainIndexed documentaion

Co-authored-by: ValuedMammal <valuedmammal@protonmail.com>
18 months agochore(chain): Improve documentation of keychain::ChangeSet
LLFourn [Fri, 7 Jun 2024 06:08:59 +0000 (16:08 +1000)]
chore(chain): Improve documentation of keychain::ChangeSet

18 months agochore(chain): Standardise KeychainTxOutIndex return types
LLFourn [Fri, 7 Jun 2024 02:29:58 +0000 (12:29 +1000)]
chore(chain): Standardise KeychainTxOutIndex return types

The previous commit b9c5b9d08b040faf6c6b2d9b3745918031555b72 added
IndexSpk. This goes further and adds `Indexed` and `KeychainIndexed`
type alises (IndexSpk is Indexed<ScriptBuf>) and attempts to standardize
the structure of return types more generally.

18 months agochore(chain): add type IndexSpk, fix clippy type complexity warning
Steve Myers [Thu, 6 Jun 2024 19:10:20 +0000 (14:10 -0500)]
chore(chain): add type IndexSpk, fix clippy type complexity warning

18 months agochore(chain): misc docs and insert_descriptor fixes
LLFourn [Thu, 6 Jun 2024 03:12:38 +0000 (13:12 +1000)]
chore(chain): misc docs and insert_descriptor fixes

18 months agorefactor(keychain): Fix KeychainTxOutIndex range queries
LLFourn [Thu, 6 Jun 2024 00:17:55 +0000 (10:17 +1000)]
refactor(keychain): Fix KeychainTxOutIndex range queries

The underlying SpkTxOutIndex should not use DescriptorIds to index
because this loses the ordering relationship of the spks so queries on
subranges of keychains work.

Along with that we enforce that there is a strict 1-to-1 relationship
between descriptors and keychains. Violating this leads to an error in
insert_descriptor now.

In general I try to make the translation layer between the SpkTxOutIndex
and the KeychainTxOutIndex thinner. Ergonomics of this will be improved
in next commit.

The test from the previous commit passes.

18 months agoWrite failing test for keychain range querying
LLFourn [Wed, 5 Jun 2024 06:39:50 +0000 (16:39 +1000)]
Write failing test for keychain range querying

18 months agoMerge bitcoindevkit/bdk#1448: bump(deps): upgrade rust `bitcoin` to `0.32.0`, `minisc...
Steve Myers [Thu, 13 Jun 2024 04:05:27 +0000 (23:05 -0500)]
Merge bitcoindevkit/bdk#1448: bump(deps): upgrade rust `bitcoin` to `0.32.0`, `miniscript` to `0.12.0` and others

11200810d048abb8deb3c7961ca93c68011d41fd chore(wallet): rm dup code (志宇)
2a4564097bd70905ed9fa21b92cdf074a72f878e deps(bdk): bump `bitcoin` to `0.32.0`, miniscript to `12.0.0` (Leonardo Lima)

Pull request description:

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

  ### Description

  This PR focuses on upgrading the `rust-bitcoin` and `miniscript` versions, to `0.32.0` and `0.12.0`, respectively. It also bumps the versions of other BDK ecosystem crates that also rely on both `rust-bitcoin` and `miniscript`, being:

  - electrum-client https://github.com/bitcoindevkit/rust-electrum-client/pull/133
  - esplora-client https://github.com/bitcoindevkit/rust-esplora-client/pull/85
  - hwi https://github.com/bitcoindevkit/rust-hwi/pull/99

  <ins>I structured the PR in multiple commits, with closed scope, being one for each BDK crate being upgraded, and one for each kind of fix and upgrade required, it seems like a lot of commits (**that should be squashed before merging**), but I think it'll make it easier during review phase.</ins>

  In summary I can already mention some of the main changes:
  - using `compute_txid()` instead of deprecated `txid()`
  - using `minimal_non_dust()` instead of `dust_value()`
  - using the renamed `signature` and `sighash_type` fields
  - using proper `sighash::P2wpkhError`,  `sighash::TaprootError` instead of older `sighash::Error`
  - conversion from `Network` to new expected `NetworkKind` #1465
  - conversion from the new `Weight` type to current expected `usize` #1466
  - using `.into()` to convert from AbsLockTime and `RelLockTime` to `absolute::LockTime` and `relative::LockTime`
  - using Message::from_digest() instead of relying on deprecated `ThirtyTwoByteHash` trait.
  - updating the miniscript policy and dsl to proper expect and handle new `Threshold` type, instead of the previous two parameters.

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

  ### Notes to the reviewers
  <ins>Again, I structured the PR in multiple commits, with closed scope, being one for each BDK crate being upgraded, and one for each kind of fix and upgrade required, it seems like a lot of commits (**that should be squashed before merging**), but I think it'll make it easier during review phase.</ins>

  It should definitely be carefully reviewed, especially the last commits for the wallet crate scope, the ones with the semantic `fix(wallet)`.

  I would also appreciate if @tcharding reviewed it, as he gave a try in the past (#1400 ), and I relied on some of it for the  policy part of it, other rust-bitcoin maintainers reviews are a definitely welcome 😁

  <!-- 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
  > // TODO(@oleonardolima): Do another pass and double check the changes
  - Use `compute_txid()` instead of deprecated `txid()`
  - Use `minimal_non_dust()` instead of `dust_value()`
  - Use `signature` and `sighash_type` fields, instead of previous `sig` and `hash_type`
  - Use `sighash::P2wpkhError`,  and `sighash::TaprootError` instead of older `sighash::Error`
  - Converts from `Network` to `NetworkKind`, where expected
  - Converts from `Weight` type to current used `usize`
  - Use `.into()` to convert from `AbsLockTime` and `RelLockTime` to `absolute::LockTime` and `relative::LockTime`
  - Remove use of  deprecated `ThirtyTwoByteHash` trait, use `Message::from_digest()`
  - Update the miniscript policy and dsl macros to proper expect and handle new `Threshold` type, instead of the previous two parameters.

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

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

Tree-SHA512: ba1ab64603b41014d3f0866d846167f77d31959ca6f1d9c3181d5e543964f5d772e05651d63935ba7bbffeba41a66868d27de4c32129739b9ca50f3bbaf9f2a1

18 months agochore(wallet): rm dup code
志宇 [Thu, 13 Jun 2024 03:47:01 +0000 (11:47 +0800)]
chore(wallet): rm dup code

Methods `make_multi` and `make_multi_a` were essentially the same thing
except for a different const generic param on `Threshold`. So we rm
`make_multi_a` and put a const generic param on `make_multi`.

18 months agodeps(bdk): bump `bitcoin` to `0.32.0`, miniscript to `12.0.0`
Leonardo Lima [Wed, 22 May 2024 21:34:30 +0000 (18:34 -0300)]
deps(bdk): bump `bitcoin` to `0.32.0`, miniscript to `12.0.0`

deps(chain): bump `bitcoin` to `0.32.0`, miniscript to `12.0.0`

fix(chain): use `minimal_non_dust()` instead of `dust_value()`

fix(chain): use `compute_txid()` instead of `txid`

deps(testenv): bump `electrsd` to `0.28.0`

deps(electrum): bump `electrum-client` to `0.20.0`

fix(electrum): use `compute_txid()` instead of `txid`

deps(esplora): bump `esplora-client` to `0.8.0`

deps(bitcoind_rpc): bump `bitcoin` to `0.32.0`, `bitcoincore-rpc` to
`0.19.0`

fix(bitcoind_rpc): use `compute_txid()` instead of `txid`

fix(nursery/tmp_plan): use proper `sighash` errors, and fix the expected
`Signature` fields

fix(sqlite): use `compute_txid()` instead of `txid`

deps(hwi): bump `hwi` to `0.9.0`

deps(wallet): bump `bitcoin` to `0.32.0`, miniscript to `12.0.0`

fix(wallet): use `compute_txid()` and `minimal_non_dust()`

- update to use `compute_txid()` instead of deprecated `txid()`
- update to use `minimal_non_dust()` instead of `dust_value()`
- remove unused `bitcoin::hex::FromHex`.

fix(wallet): uses `.into` conversion on `Network` for `NetworkKind`

- uses `.into()` when appropriate, otherwise use the explicit
  `NetworkKind`, and it's `.is_mainnet()` method.

fix(wallet): add P2wpkh, Taproot, InputsIndex errors to `SignerError`

fix(wallet): fields on taproot, and ecdsa `Signature` structure

fix(wallet/wallet): convert `Weight` to `usize` for now

- converts the `bitcoin-units::Weight` type to `usize` with help of
  `to_wu()` method.
- it should be updated/refactored in the future to handle the `Weight`
  type throughout the code instead of current `usize`, only converting
  it for now.
- allows the usage of deprecated `is_provably_unspendable()`, needs
  further discussion if suggested `is_op_return` is suitable.
- update the expect field to `signature`, as it was renamed from `sig`.

fix(wallet/wallet): use `is_op_return` instead of
`is_provably_unspendable`

fix(wallet/wallet): use `relative::Locktime` instead of `Sequence`

fix(wallet/descriptor): use `ParsePublicKeyError`

fix(wallet/descriptor): use `.into()` to convert from `AbsLockTime` and
`RelLockTime` to `absolute::LockTime` and `relative::LockTime`

fix(wallet/wallet): use `Message::from_digest()` instead of relying on
deprecated `ThirtyTwoByteHash` trait.

fix(wallet/descriptor+wallet): expect `Threshold` type, and handle it
internally

fix(wallet/wallet): remove `0x` prefix from expected `TxId` display

fix(examples): use `compute_txid()` instead of `txid`

fix(ci): remove usage of `bitcoin/no-std` feature

- remove comment: `# The `no-std` feature it's implied when the `std` feature is disabled.`

18 months agoMerge pull request #1470 from notmandatory/ci/pin_url_dep
Lloyd Fournier [Wed, 12 Jun 2024 00:36:54 +0000 (10:36 +1000)]
Merge pull request #1470 from notmandatory/ci/pin_url_dep

ci: pin url dependency version to build with rust 1.63

18 months agoci: pin url dependency version to build with rust 1.63
Steve Myers [Tue, 11 Jun 2024 21:00:47 +0000 (16:00 -0500)]
ci: pin url dependency version to build with rust 1.63

18 months agoMerge bitcoindevkit/bdk#1441: Remove duplicated InsufficientFunds error member
志宇 [Thu, 6 Jun 2024 04:17:19 +0000 (12:17 +0800)]
Merge bitcoindevkit/bdk#1441: Remove duplicated InsufficientFunds error member

29c8a00b435bdf2fa1d7c707ad09c1a47edc07b3 chore(wallet): remove duplicated InsufficientFunds error member from CreateTxError (e1a0a0ea)

Pull request description:

  closes #1440

  ### Description

  - Replace `CreateTxError::InsufficientFunds` use by `coin_selection::Error::InsufficientFunds`
  - Remove `InsufficientFunds` member from `CreateTxError` enum
  - Rename `coin_selection::Error` to `coin_selection::CoinSelectionError`

  ### Notes to the reviewers

  - We could also keep both members but rename one of them to avoid confusion

  ### 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 29c8a00b435bdf2fa1d7c707ad09c1a47edc07b3
  notmandatory:
    ACK 29c8a00b435bdf2fa1d7c707ad09c1a47edc07b3

Tree-SHA512: a1132d09929f99f0a5e82d3ccfaa85695ae50d7d4d5d9e8fd9ef847313918ed8c7a01005f45483fef6aeae36730a0da2fed9a9f10c3ce2f0a679527caf798bfe

18 months agoMerge bitcoindevkit/bdk#1390: Make Wallet require a change descriptor
Steve Myers [Thu, 6 Jun 2024 04:05:19 +0000 (23:05 -0500)]
Merge bitcoindevkit/bdk#1390: Make Wallet require a change descriptor

8bc3d35f6c83d078551c4bc57f72f13324865486 fix(wallet): `LoadError::MissingDescriptor` includes the missing KeychainKind (valued mammal)
412dee1f5b027af7800ee155717d47f4ab4b60e0 ref(wallet)!: Make `Wallet::public_descriptor` infallible (valued mammal)
c2513e1090374d7871a8623845bd10757e6ab0b3 test(wallet): Clarify docs for get_funded_wallet (valued mammal)
9d954cf7d25d43c77115cd931407005a09365389 refactor(wallet)!: Make Wallet require a change descriptor (valued mammal)

Pull request description:

  All `Wallet` constructors are modified to require a change descriptor, where previously it was optional. Additionally we enforce uniqueness of the change descriptor to avoid ambiguity when deriving scripts and ensure the wallet will always have two distinct keystores.

  Notable changes

  * Add error `DescriptorError::ExternalAndInternalAreTheSame`
  * Remove error `CreateTxError::ChangePolicyDescriptor`
  * No longer rely on `map_keychain`

  fixes #1383

  ### Notes to the reviewers

  ### Changelog notice

  Changed:

  Constructing a Wallet now requires two distinct descriptors.

  ### 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:
    re-ACK 8bc3d35f6c83d078551c4bc57f72f13324865486

Tree-SHA512: f0621deb75d8e1e484b18b40d850f64e26314e39c4778f56c627763ddbffd376288bf6f0f37b61ba2ba744c7083683497d2dfef42bc4ef7d3ed7b374a54d813a

18 months agochore(wallet): remove duplicated InsufficientFunds error member from CreateTxError
e1a0a0ea [Mon, 13 May 2024 07:28:43 +0000 (09:28 +0200)]
chore(wallet): remove duplicated InsufficientFunds error member from CreateTxError

review: move back to old error naming

18 months agofix(wallet): `LoadError::MissingDescriptor` includes the missing KeychainKind
valued mammal [Tue, 4 Jun 2024 21:53:41 +0000 (17:53 -0400)]
fix(wallet): `LoadError::MissingDescriptor` includes the missing KeychainKind

18 months agoref(wallet)!: Make `Wallet::public_descriptor` infallible
valued mammal [Tue, 4 Jun 2024 15:59:25 +0000 (11:59 -0400)]
ref(wallet)!: Make `Wallet::public_descriptor` infallible

18 months agotest(wallet): Clarify docs for get_funded_wallet
valued mammal [Wed, 27 Mar 2024 17:34:18 +0000 (13:34 -0400)]
test(wallet): Clarify docs for get_funded_wallet

18 months agorefactor(wallet)!: Make Wallet require a change descriptor
valued mammal [Wed, 27 Mar 2024 01:57:10 +0000 (21:57 -0400)]
refactor(wallet)!: Make Wallet require a change descriptor

All `Wallet` constructors are modified to require a change
descriptor, where previously it was optional. Additionally
we enforce uniqueness of the change descriptor to avoid
ambiguity when deriving scripts and ensure the wallet will
always have two distinct keystores.

Notable changes

* Add error DescriptorError::ExternalAndInternalAreTheSame
* Remove error CreateTxError::ChangePolicyDescriptor
* No longer rely on `map_keychain`

18 months agoMerge bitcoindevkit/bdk#1453: refactor(electrum) put the tx cache in electrum
志宇 [Wed, 5 Jun 2024 02:18:36 +0000 (10:18 +0800)]
Merge bitcoindevkit/bdk#1453: refactor(electrum) put the tx cache in electrum

2d2656acfa83ab4c4846c0aab14072efb64c5cc3 feat(electrum): re-export `transaction_broadcast` method (志宇)
53fa35096fbeea2b82b28987e8ef6f7d39ffc80b refactor(electrum)!: put the tx cache in electrum (LLFourn)

Pull request description:

  Previously there was a `TxCache` that you passed in as part of the sync request. There are lots of downsides to this:

  1. If the user forgets to do this you cache nothing
  2. where are you meant to keep this cache? The example shows it being recreated every time which seems very suboptimal.
  3. More API and documentation surface area.

  Instead just do a plain old simple cache inside the electrum client. This way at least you only download transactions once. You can pre-populate the cache with a method also and I did this in the examples.

  * [x] This pull request breaks the existing API

ACKs for top commit:
  evanlinjin:
    self-ACK 2d2656acfa83ab4c4846c0aab14072efb64c5cc3
  notmandatory:
    ACK 2d2656acfa83ab4c4846c0aab14072efb64c5cc3

Tree-SHA512: 6c29fd4f99ea5bd66234d5cdaf4b157a192ddd3baacc91076e402d8df0de7010bc482e24895e85fcb2f805ec6d1ce6cdb7654f8f552c90ba75ed35f80a00b856

18 months agofix: typo on `SignedAmount` instead of `Amount`
Leonardo Lima [Wed, 5 Jun 2024 00:53:08 +0000 (21:53 -0300)]
fix: typo on `SignedAmount` instead of `Amount`

18 months agoMerge bitcoindevkit/bdk#1455: refactor(wallet): rename get_balance() to balance()
Steve Myers [Tue, 4 Jun 2024 22:07:13 +0000 (17:07 -0500)]
Merge bitcoindevkit/bdk#1455: refactor(wallet): rename get_balance() to balance()

50137b0425fe9c9aac8caaacf099bfe6c69859c2 refactor(wallet): rename get_balance() to balance() (Steve Myers)

Pull request description:

  ### Description

  fixes #1221

  ### Notes to the reviewers

  See discussion in #1221.

  ### Changelog notice

  Changed

  - Wallet::get_balance() renamed to Wallet::balance()

  ### 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 50137b0425fe9c9aac8caaacf099bfe6c69859c2
  oleonardolima:
    ACK 50137b0425fe9c9aac8caaacf099bfe6c69859c2
  evanlinjin:
    ACK 50137b0425fe9c9aac8caaacf099bfe6c69859c2

Tree-SHA512: 20d188a32c79eca37b4f269e5bcdb8c2ecd595911558cb74812a37da13a4f39b603deed3bc11356aa6523b16417a2a025046b3dd4df5bd7247f39c29d7f48ac2

18 months agoMerge bitcoindevkit/bdk#1426: feat: add further `bitcoin::Amount` usage on public...
Steve Myers [Tue, 4 Jun 2024 21:07:12 +0000 (16:07 -0500)]
Merge bitcoindevkit/bdk#1426: feat: add further `bitcoin::Amount` usage on public APIs

a03949adb0c38ba4c2f44b497871070c1a2170d2 feat: use `Amount` on `calculate_fee`, `fee_absolute`, `fee_amount` and others (Leonardo Lima)

Pull request description:

  builds on top of #1411, further improves #823

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

  ### Description

  It further updates and adds the usage of `bitcoin::Amount` instead of `u64`.

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

  ### Notes to the reviewers

  Open for comments and discussions.

  <!-- 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
  - Updated `CreateTxError::FeeTooLow` to use `bitcoin::Amount`.
  - Updated `Wallet::calculate_fee()`. to use `bitcoin::Amount`
  - Updated `TxBuilder::fee_absolute()`. to use `bitcoin::Amount`.
  - Updated `CalculateFeeError::NegativeFee` to use `bitcoin::SignedAmount`.
  - Updated `TxGraph::calculate_fee()`. to use `bitcoin::Amount`.
  - Updated `PsbUtils::fee_amount()` to use `bitcoin::Amount`.

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

  #### New Features:

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

ACKs for top commit:
  storopoli:
    ACK a03949adb0c38ba4c2f44b497871070c1a2170d2

Tree-SHA512: abfbf7d48ec004eb448ed0a928e7e64b5f82a2ab51ec278fede4ddbff4eaba16469a7403f78dfeba1aba693b0132a528bc7c4ef072983cbbcc2592993230e40f

18 months agofeat(electrum): re-export `transaction_broadcast` method
志宇 [Tue, 4 Jun 2024 03:59:39 +0000 (11:59 +0800)]
feat(electrum): re-export `transaction_broadcast` method

Also: update `wallet_electrum` example to use the method.

18 months agorefactor(electrum)!: put the tx cache in electrum
LLFourn [Fri, 31 May 2024 03:52:49 +0000 (13:52 +1000)]
refactor(electrum)!: put the tx cache in electrum

Previously there was a tx cache that you passed in as part of the sync
request. This seems bad and the example show'd that you should copy all
your transactions from the transaction graph into the sync request every
time you sync'd. If you forgot to do this then you would always download everything.

Instead just do a plain old simple cache inside the electrum client.
This way at least you only download transactions once. You can
pre-populate the cache with a method also and I did this in the examples.

18 months agofeat: use `Amount` on `calculate_fee`, `fee_absolute`, `fee_amount` and others
Leonardo Lima [Sun, 5 May 2024 20:41:31 +0000 (17:41 -0300)]
feat: use `Amount` on `calculate_fee`, `fee_absolute`, `fee_amount` and others

- update to use `bitcoin::Amount` on `CreateTxError::FeeTooLow` variant.
- update to use `bitcoin::Amount` on `Wallet::calculate_fee()`.
- update to use `bitcoin::Amount` on `FeePolicy::fee_absolute()`.
- update to use `bitcoin::SignedAmount` on
  `CalculateFeeError::NegativeFee` variant.
- update to use `bitcoin::Amount` on `TxGraph::calculate_fee()`.
- update to use `bitcoin::Amount` on `PsbUtils::fee_amount()`

18 months agorefactor(wallet): rename get_balance() to balance()
Steve Myers [Sat, 1 Jun 2024 22:46:24 +0000 (17:46 -0500)]
refactor(wallet): rename get_balance() to balance()

19 months agoMerge bitcoindevkit/bdk#1450: Bump bdk version to 1.0.0-alpha.12 v1.0.0-alpha.12
Steve Myers [Thu, 23 May 2024 22:33:27 +0000 (17:33 -0500)]
Merge bitcoindevkit/bdk#1450: Bump bdk version to 1.0.0-alpha.12

108061dddbba99f03d7416a673135211ef94043b Bump bdk version to 1.0.0-alpha.12 (Steve Myers)

Pull request description:

  ### Description

  fixes #1449

  bdk_chain to 0.15.0
  bdk_bitcoind_rpc to 0.11.0
  bdk_electrum to 0.14.0
  bdk_esplora to 0.14.0
  bdk_persist to 0.3.0
  bdk_file_store to 0.12.0
  bdk_sqlite keep at 0.1.0
  bdk_testenv to 0.5.0
  bdk_hwi to 0.1.0
  bdk_wallet to 1.0.0-alpha.12

  ### Notes to the reviewers

  I also (hopefully) fixed the `bdk_hwi` crate so it can be published.

ACKs for top commit:
  ValuedMammal:
    ACK 108061dddbba99f03d7416a673135211ef94043b
  storopoli:
    ACK 108061dddbba99f03d7416a673135211ef94043b

Tree-SHA512: 2a80c51e254ca011b8e9bb72ad3d720dd8d09a3142e85cf230ffffad747257d91c45950cce64b049bab91f21c70c622f14d46def24ea78459497b42472a1fe48

19 months agoBump bdk version to 1.0.0-alpha.12
Steve Myers [Thu, 23 May 2024 16:15:30 +0000 (11:15 -0500)]
Bump bdk version to 1.0.0-alpha.12

bdk_chain to 0.15.0
bdk_bitcoind_rpc to 0.11.0
bdk_electrum to 0.14.0
bdk_esplora to 0.14.0
bdk_persist to 0.3.0
bdk_file_store to 0.12.0
bdk_sqlite keep at 0.1.0
bdk_testenv to 0.5.0
bdk_hwi to 0.1.0
bdk_wallet to 1.0.0-alpha.12

19 months agoMerge bitcoindevkit/bdk#1393: fix(export): add tr descriptor
Steve Myers [Thu, 23 May 2024 15:12:56 +0000 (10:12 -0500)]
Merge bitcoindevkit/bdk#1393: fix(export): add tr descriptor

1b7c6df569a0ff9324bbda1f066938490109481d fix(export): add tr descriptor (rustaceanrob)

Pull request description:

  ### Description

  Resolves #860 by adding export of taproot descriptors

  ### Notes to the reviewers

  Allows export as Core accepts taproot.

  ### Changelog notice

  - Export taproot descriptors

  ### 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
  * [ ] 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:
  notmandatory:
    ACK 1b7c6df569a0ff9324bbda1f066938490109481d

Tree-SHA512: 80bee93a1ec531717e79a5e7a91e840532ae4d3daf677a207bc53162c69410e47db4893024b3eccfd848f1628062e7c49f0e92ebeb7230e2ebb9b47eb84b9e56

19 months agoMerge bitcoindevkit/bdk#1386: Remove TxBuilder allow_shrinking() and unneeded context...
Steve Myers [Thu, 23 May 2024 15:01:44 +0000 (10:01 -0500)]
Merge bitcoindevkit/bdk#1386: Remove TxBuilder allow_shrinking() and unneeded context param

096b8ef781b21e7da690b9ca2e4b326880d6ac0b fix(wallet): remove TxBuilder::allow_shrinking function and TxBuilderContext (Steve Myers)

Pull request description:

  ### Description

  Remove wallet::TxBuilder::allow_shrinking() and unneeded TxBuilder context param.

  Fixes #1374

  ### Notes to the reviewers

  The allow_shrinking function was the only one using the TxBuilder FeeBump context and it's useful to have CreateTx context  functions available for building FeeBump transactions, see updated tests.

  ### Changelog notice

  Changed

  - Removed TxBuilder::allow_shrinking() function.

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

Top commit has no ACKs.

Tree-SHA512: f4f05ce4cfaced9e61eebc0ebfe77a299fae13df4459fc26c90657297a1347a5d16f22b4e1c8b9b10458cfec80ca3b5d698eee11c7a560fd83f94a1ac7101a86

19 months agofix(wallet): remove TxBuilder::allow_shrinking function and TxBuilderContext
Steve Myers [Fri, 17 May 2024 02:47:56 +0000 (21:47 -0500)]
fix(wallet): remove TxBuilder::allow_shrinking function and TxBuilderContext

19 months agoMerge bitcoindevkit/bdk#1128: feat: add bdk_sqlite crate implementing PersistBackend
志宇 [Thu, 23 May 2024 14:33:05 +0000 (22:33 +0800)]
Merge bitcoindevkit/bdk#1128: feat: add bdk_sqlite crate implementing PersistBackend

475c5024ecc5d288f35fabb8fab2b62dbf67653b feat(sqlite): add bdk_sqlite crate implementing PersistBackend backed by a SQLite database (Steve Myers)
b8aa76cd050bc3c2eac776ecbd9b4e2ab3e2590e feat(wallet): use the new `CombinedChangeSet` of `bdk_persist` (志宇)
0958ff56b20c1325a7da5d5f21e7ac836c601f1f feat(persist): introduce `CombinedChangeSet` (志宇)
54942a902d3203ee59731f35d2a1c402ac626878 ci: bump build_docs rust version to nightly-2024-05-12 (Steve Myers)
d975a48e7c519a703441e74058321021957b177f docs: update README MSRV pinning to match CI (Steve Myers)

Pull request description:

  ### Description

  Add "bdk_sqlite_store" crate implementing `PersistBackend` backed by a SQLite database.

  ### Notes to the reviewers

  In addition to adding a SQLite based `PersistenceBackend` this PR also:

  * add  `CombinedChangeSet` in `bdk_persist` and update `wallet` crate to use it.
  * updates the `wallet/tests` to also use this new sqlite store crate.
  * updates `example-crates/wallet_esplora_async` to use this new sqlite store crate.
  * fixes out of date README instructions for MSRV.
  * bumps the ci `build_docs` job to rust `nightly-2024-05-12`.

  ### Changelog notice

  Changed

  - Update Wallet to use CombinedChangeSet for persistence.

  Added

  - Add  CombinedChangeSet in bdk_persist crate.
  - Add bdk_sqlite crate implementing SQLite based PersistenceBackend storage for CombinedChangeSet.

  ### 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:
  evanlinjin:
    ACK 475c5024ecc5d288f35fabb8fab2b62dbf67653b

Tree-SHA512: 72565127994fbfff34d7359e1d36d6f13e552995bb7ea61dd38ba5329b0d15e500fa106214a83fd870f1017dc659ff1bb8fc71bc6aad0a793730ec7f23179d8c

19 months agofeat(sqlite): add bdk_sqlite crate implementing PersistBackend backed by a SQLite...
Steve Myers [Tue, 19 Sep 2023 22:29:23 +0000 (17:29 -0500)]
feat(sqlite): add bdk_sqlite crate implementing PersistBackend backed by a SQLite database

19 months agofeat(wallet): use the new `CombinedChangeSet` of `bdk_persist`
志宇 [Tue, 21 May 2024 14:30:07 +0000 (22:30 +0800)]
feat(wallet): use the new `CombinedChangeSet` of `bdk_persist`

19 months agofeat(persist): introduce `CombinedChangeSet`
志宇 [Tue, 21 May 2024 13:08:40 +0000 (21:08 +0800)]
feat(persist): introduce `CombinedChangeSet`

It is a good idea to have common changeset types stored in
`bdk_persist`. This will make it convenient for persistence crates and
`bdk_wallet` interaction.

19 months agoci: bump build_docs rust version to nightly-2024-05-12
Steve Myers [Tue, 14 May 2024 15:15:51 +0000 (10:15 -0500)]
ci: bump build_docs rust version to nightly-2024-05-12

19 months agodocs: update README MSRV pinning to match CI
Steve Myers [Thu, 9 May 2024 00:13:03 +0000 (19:13 -0500)]
docs: update README MSRV pinning to match CI

19 months agoMerge bitcoindevkit/bdk#1443: fix(electrum): Fix `fetch_prev_txout`
志宇 [Wed, 15 May 2024 12:34:47 +0000 (20:34 +0800)]
Merge bitcoindevkit/bdk#1443: fix(electrum): Fix `fetch_prev_txout`

af15ebba94f6d96a4d266fbbdee7c49150f80b96 fix(electrum): Fix `fetch_prev_txout` (valued mammal)

Pull request description:

  Previously we inserted every `TxOut` of a previous tx at the same outpoint, which is incorrect because an outpoint only points to a single `TxOut`. Now just get the `TxOut` corresponding to the txin prevout and insert it with its outpoint.

  ### Notes to the reviewers

  The bug in question was demonstrated in a discord comment https://discord.com/channels/753336465005608961/1239693193159639073/1239704153400414298 but I don't think we've opened an issue yet. Essentially, because of a mismatch between the outpoint and txout stored in TxGraph, we weren't summing the inputs correctly which caused `calculate_fee` to fail with `NegativeFee` error.

  fixes #1419

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

  * [ ] I've added tests to reproduce the issue which are now passing

ACKs for top commit:
  LagginTimes:
    ACK af15ebba94f6d96a4d266fbbdee7c49150f80b96
  evanlinjin:
    ACK af15ebba94f6d96a4d266fbbdee7c49150f80b96

Tree-SHA512: c3a2c374069b0863076784856d90c7760b8f411e4881c3e42367015542b02ea6010c37745fb6dde95422af7222b7939ec51bc0fd1f63f816813c2159a17e08e5

19 months agofix(electrum): Fix `fetch_prev_txout`
valued mammal [Tue, 14 May 2024 14:43:19 +0000 (10:43 -0400)]
fix(electrum): Fix `fetch_prev_txout`

Previously we inserted every TxOut of a previous tx
at the same outpoint, which is incorrect because an outpoint
only points to a single TxOut. Now just get the TxOut
corresponding to the txin prevout and insert it with
its outpoint.

19 months agofix(export): add tr descriptor
rustaceanrob [Wed, 27 Mar 2024 21:02:50 +0000 (11:02 -1000)]
fix(export): add tr descriptor

19 months agoMerge bitcoindevkit/bdk#1326: chore: rename bdk crate to bdk_wallet
Steve Myers [Mon, 13 May 2024 17:17:46 +0000 (12:17 -0500)]
Merge bitcoindevkit/bdk#1326: chore: rename bdk crate to bdk_wallet

f6781652b7a4833b220e0853cd6e290bb5fc0136 chore: rename bdk crate to bdk_wallet (Steve Myers)

Pull request description:

  ### Description

  Fixes #1305 .

  ### Notes to the reviewers

  Once this properly builds, even before all reviews is done, I will publish it to crates.io to reserve the name.

  ### Changelog notice

  Changed

  - Renamed `bdk` crate to `bdk_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

Top commit has no ACKs.

Tree-SHA512: 437c79d9d41721bc9cffd3be81e898068378803dcde6b4106d33bf34ffa756d090dce36d15d4ecd232e5b55ce09c393e6956fc0af4b8477886dabb506b679256

19 months agochore: rename bdk crate to bdk_wallet
Steve Myers [Tue, 6 Feb 2024 14:56:31 +0000 (08:56 -0600)]
chore: rename bdk crate to bdk_wallet

19 months agoMerge bitcoindevkit/bdk#1437: Bump bdk version to 1.0.0-alpha.11 v1.0.0-alpha.11
Steve Myers [Fri, 10 May 2024 22:16:37 +0000 (17:16 -0500)]
Merge bitcoindevkit/bdk#1437: Bump bdk version to 1.0.0-alpha.11

db9fdccc18c418cbbdf39ef4e912416796d63860 Bump bdk version to 1.0.0-alpha.11 (Steve Myers)

Pull request description:

  ### Description

  fixes #1435

  bdk_chain to 0.14.0
  bdk_bitcoind_rpc to 0.10.0
  bdk_electrum to 0.13.0
  bdk_esplora to 0.13.0
  bdk_file_store to 0.11.0
  bdk_testenv to 0.4.0
  bdk_persist to 0.2.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

ACKs for top commit:
  ValuedMammal:
    ACK db9fdccc18c418cbbdf39ef4e912416796d63860
  storopoli:
    ACK db9fdccc18c418cbbdf39ef4e912416796d63860

Tree-SHA512: 804475927461a4bcf37786313123a0a0cc68390af6c556111551dc126a06614296eb657a8a5662a36cf4569ab332f5f9285c99c5f1992d93f43568e881961895

19 months agoBump bdk version to 1.0.0-alpha.11
Steve Myers [Fri, 10 May 2024 00:15:33 +0000 (19:15 -0500)]
Bump bdk version to 1.0.0-alpha.11

bdk_chain to 0.14.0
bdk_bitcoind_rpc to 0.10.0
bdk_electrum to 0.13.0
bdk_esplora to 0.13.0
bdk_file_store to 0.11.0
bdk_testenv to 0.4.0
bdk_persist to 0.2.0

19 months agoMerge bitcoindevkit/bdk#1403: Update `bdk_electrum` crate to use sync/full-scan structs
Steve Myers [Fri, 10 May 2024 17:22:13 +0000 (12:22 -0500)]
Merge bitcoindevkit/bdk#1403: Update `bdk_electrum` crate to use sync/full-scan structs

b45897e6fe2f7e67f5d75ec6f983757b28c5ec19 feat(electrum): update docs and simplify logic of `ElectrumExt` (志宇)
92fb6cb37387fb0b9fe5329e772f0d928a33e116 chore(electrum): do not use `anyhow::Result` directly (志宇)
b2f3cacce6081f3bf6e103d1d2ca0707c545a67e feat(electrum): include option for previous `TxOut`s for fee calculation (Wei Chen)
c0d7d60a582b939324bb48ec8c5035020ec90699 feat(chain)!: use custom return types for `ElectrumExt` methods (志宇)
2945c6be88b3bf5105afeb8addff4861f0458b41 fix(electrum): fixed `sync` functionality (Wei Chen)
9ed33c25ea01278b0a47c8ecd5ea6fa33119a977 docs(electrum): fixed `full_scan`, `sync`, and crate documentation (Wei Chen)
b1f861b932afd5e490c0814b1921b97cc2f1d912 feat: update logging of electrum examples (志宇)
a6fdfb2ae4caa1cdd23aa5e5ffaf02716473a98e feat(electrum)!: use new sync/full-scan structs for `ElectrumExt` (志宇)
653e4fed6d16698bc5859c1e4afdcee7b3d83dad feat(wallet): cache txs when constructing full-scan/sync requests (志宇)
58f27b38eb2093bb9b715b7e0ebd1619ecad74ee feat(chain): introduce `TxCache` to `SyncRequest` and `FullScanRequest` (志宇)
721bb7f519131ca295a00efa2d242b4923e2bddd fix(chain): Make `Anchor` type in `FullScanResult` generic (志宇)
e3cfb84898cfa79d4903cf276fc69ffb0605b4d4 feat(chain): `TxGraph::insert_tx` reuses `Arc` (志宇)
2ffb65618afb7382232a3c08a077dd1109005071 refactor(electrum): remove `RelevantTxids` and track txs in `TxGraph` (Wei Chen)

Pull request description:

  Fixes #1265
  Possibly fixes #1419

  ### Context

  Previous changes such as

  * Universal structures for full-scan/sync (PR #1413)
  * Making `CheckPoint` linked list query-able (PR #1369)
  * Making `Transaction`s cheaply-clonable (PR #1373)

  has allowed us to simplify the interaction between chain-source and receiving-structures (`bdk_chain`).

  The motivation is to accomplish something like this ([as mentioned here](https://github.com/bitcoindevkit/bdk/issues/1153#issuecomment-1752263555)):
  ```rust
  let things_I_am_interested_in = wallet.lock().unwrap().start_sync();
  let update = electrum_or_esplora.sync(things_i_am_interested_in)?;
  wallet.lock().unwrap().apply_update(update)?:
  ```

  ### Description

  This PR greatly simplifies the API of our Electrum chain-source (`bdk_electrum`) by making use of the aforementioned changes. Instead of referring back to the receiving `TxGraph` mid-sync/scan to determine which full transaction to fetch, we provide the Electrum chain-source already-fetched full transactions to start sync/scan (this is cheap, as transactions are wrapped in `Arc`s since #1373).

  In addition, an option has been added to include the previous `TxOut` for transactions received from an external wallet for fee calculation.

  ### Changelog notice

  * Change `TxGraph::insert_tx` to take in anything that satisfies `Into<Arc<Transaction>>`. This allows us to reuse the `Arc` pointer of what is being inserted.
  * Add `tx_cache` field to `SyncRequest` and `FullScanRequest`.
  * Make `Anchor` type in `FullScanResult` generic for more flexibility.
  * Change `ElectrumExt` methods to take in `SyncRequest`/`FullScanRequest` and return `SyncResult`/`FullScanResult`. Also update electrum examples accordingly.
  * Add `ElectrumResultExt` trait which allows us to convert the update `TxGraph` of `SyncResult`/`FullScanResult` for `bdk_electrum`.
  * Added an option for `full_scan` and `sync` to also fetch previous `TxOut`s to allow for fee calculation.

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

Tree-SHA512: 1e274546015e7c7257965b36079ffe0cb3c2c0b7c2e0c322bcf32a06925a0c3e1119da1c8fd5318f1dbd82c2e952f6a07f227a9b023c48f506a62c93045d96d3

19 months agofeat(electrum): update docs and simplify logic of `ElectrumExt`
志宇 [Fri, 10 May 2024 08:40:55 +0000 (16:40 +0800)]
feat(electrum): update docs and simplify logic of `ElectrumExt`

Helper method docs are updated to explain what they are updating. Logic
is simplified as we do not need to check whether a tx exists already in
`update_graph` before inserting it.

19 months agochore(electrum): do not use `anyhow::Result` directly
志宇 [Thu, 9 May 2024 08:38:56 +0000 (16:38 +0800)]
chore(electrum): do not use `anyhow::Result` directly

19 months agofeat(electrum): include option for previous `TxOut`s for fee calculation
Wei Chen [Tue, 7 May 2024 11:57:11 +0000 (19:57 +0800)]
feat(electrum): include option for previous `TxOut`s for fee calculation

The previous `TxOut` for transactions received from an external
wallet may be optionally added as floating `TxOut`s to `TxGraph`
to allow for fee calculation.