Skip to content

Commit 97d542c

Browse files
Merge #976: Reimplement Wallet, ElectrumExt and Esplora{Async}Ext with redesigned structures.
75f8b81 Update documentation (志宇) cff9211 [wallet_redesign] Clean up and document address methods (志宇) a7668a2 [wallet_redesign] Modified `insert_tx` to use lowest checkpoint (志宇) ac80829 Rename fields of `tx_graph::Additions` (Shourya742) 1c3cbef [chain_redesign] Remove old structures (志宇) 5860704 Implement redesigned versions of `EsploraExt` and `EsploraAsyncExt` (志宇) 2952341 Update the `wallet_electrum` example (志宇) 78a7920 `bdk_electrum` API improvements and simplifications (志宇) 92709d0 Various tweaks to code arrangement and documentation (志宇) 50425e9 Introduce `keychain::LocalChangeSet` (志宇) a78967e [example-cli] simplify new address logic (LLFourn) 6a1ac7f [examples_redesign] Implemented `example_electrum` (志宇) f55974a [examples_redesign] Introduce `example_cli` package (志宇) 2e3cee4 [electrum_redesign] Introduce redesigned `ElectrumExt` (志宇) 7261669 Add `last_seen` to the the `ConfirmationTime::Unconfirmed` variant (志宇) aba8813 [wallet_redesign] Move the majority of `Update` to `bdk_chain` (志宇) e69fccb [wallet_redesign] Update `Wallet` with redesigned structures (志宇) Pull request description: ### Description Closes #938 * Update `Wallet` to use redesigned structures. * Update `bdk_electrum::ElectrumExt` to produce updates for redesigned structures. * Update `bdk_esplora::EsploraExt` and `bdk_esplora::EsploraAsyncExt` to produce updates for redesigned structures. * Added `example-crates/example_cli` library for implementing examples with redesigned structures. * Added `example-crate/example_electrum` which is an electrum CLI wallet using the redesigned structures. * Updated `example-crate/{wallet_electrum|wallet_esplora|wallet_esplora_async}` examples to use redesigned structures. * Remove all old structures. ### Notes to the reviewers ~These changes bump our `all-features` MSRV to `1.60.0` because of the introduction of `bdk_esplora`. As long as the `bdk_chain` and `bdk_wallet` crates hit a MSRV of `1.48.0`, it will be fine (this work is done in #987).~ No longer needed due to #993 ~I had to comment out the examples that use `Wallet` with our chain sources. Once we update the helper-packages for those chain sources, we can also update the examples.~ Possible future improvements for `ElectrumExt`: * Remove requirement to retry obtaining ALL data after reorg is detected. Transactions can be anchored to a lower block (not block tip), and an `assume_final_depth` value can be used. * The logic to finalize an update with confirmation time can be improved during reorgs to not require returning an error. * Use the subscription model of electrum, as intended by the API. ### 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 #### New Features: * [x] I've added tests for the new feature * [x] I've added docs for the new feature ACKs for top commit: LLFourn: ACK 75f8b81 danielabrozzoni: Partial ACK 75f8b81 - the Wallet code looks good to me, I don't have a good enough understanding of the esplora/electrum code to confidently ACK it. Tree-SHA512: d1d2b79e3c28fbe826044a8b5ef9b122c2dcfc0d371f24cc4aac7f286500b587c2dc3b06ca6461c8721adbc29f56ca41e7566eace560b0a9c541604e6a225c61
2 parents 8641847 + 75f8b81 commit 97d542c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2393
-6810
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ members = [
44
"crates/chain",
55
"crates/file_store",
66
"crates/electrum",
7-
"example-crates/keychain_tracker_electrum",
8-
"example-crates/keychain_tracker_esplora",
9-
"example-crates/keychain_tracker_example_cli",
7+
"crates/esplora",
8+
"example-crates/example_cli",
9+
"example-crates/example_electrum",
1010
"example-crates/wallet_electrum",
1111
"example-crates/wallet_esplora",
1212
"example-crates/wallet_esplora_async",

crates/bdk/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![doc = include_str!("../README.md")]
22
#![no_std]
3+
#![warn(missing_docs)]
4+
35
#[cfg(feature = "std")]
46
#[macro_use]
57
extern crate std;

crates/bdk/src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ use serde::{Deserialize, Serialize};
2222
/// Types of keychains
2323
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
2424
pub enum KeychainKind {
25-
/// External
25+
/// External keychain, used for deriving recipient addresses.
2626
External = 0,
27-
/// Internal, usually used for change outputs
27+
/// Internal keychain, used for deriving change addresses.
2828
Internal = 1,
2929
}
3030

crates/bdk/src/wallet/coin_selection.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,13 @@ mod test {
722722

723723
fn get_test_utxos() -> Vec<WeightedUtxo> {
724724
vec![
725-
utxo(100_000, 0, ConfirmationTime::Unconfirmed),
726-
utxo(FEE_AMOUNT - 40, 1, ConfirmationTime::Unconfirmed),
727-
utxo(200_000, 2, ConfirmationTime::Unconfirmed),
725+
utxo(100_000, 0, ConfirmationTime::Unconfirmed { last_seen: 0 }),
726+
utxo(
727+
FEE_AMOUNT - 40,
728+
1,
729+
ConfirmationTime::Unconfirmed { last_seen: 0 },
730+
),
731+
utxo(200_000, 2, ConfirmationTime::Unconfirmed { last_seen: 0 }),
728732
]
729733
}
730734

@@ -780,7 +784,7 @@ mod test {
780784
time: rng.next_u64(),
781785
}
782786
} else {
783-
ConfirmationTime::Unconfirmed
787+
ConfirmationTime::Unconfirmed { last_seen: 0 }
784788
},
785789
}),
786790
});
@@ -803,7 +807,7 @@ mod test {
803807
keychain: KeychainKind::External,
804808
is_spent: false,
805809
derivation_index: 42,
806-
confirmation_time: ConfirmationTime::Unconfirmed,
810+
confirmation_time: ConfirmationTime::Unconfirmed { last_seen: 0 },
807811
}),
808812
};
809813
vec![utxo; utxos_number]
@@ -1091,7 +1095,11 @@ mod test {
10911095

10921096
let required = vec![utxos[0].clone()];
10931097
let mut optional = utxos[1..].to_vec();
1094-
optional.push(utxo(500_000, 3, ConfirmationTime::Unconfirmed));
1098+
optional.push(utxo(
1099+
500_000,
1100+
3,
1101+
ConfirmationTime::Unconfirmed { last_seen: 0 },
1102+
));
10951103

10961104
// Defensive assertions, for sanity and in case someone changes the test utxos vector.
10971105
let amount: u64 = required.iter().map(|u| u.utxo.txout().value).sum();

crates/bdk/src/wallet/export.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
use core::str::FromStr;
5757

5858
use alloc::string::{String, ToString};
59-
use bdk_chain::sparse_chain::ChainPosition;
6059
use serde::{Deserialize, Serialize};
6160

6261
use miniscript::descriptor::{ShInner, WshInner};
@@ -130,8 +129,10 @@ impl FullyNodedExport {
130129
wallet
131130
.transactions()
132131
.next()
133-
.and_then(|(pos, _)| pos.height().into())
134-
.unwrap_or(0)
132+
.map_or(0, |canonical_tx| match canonical_tx.observed_as {
133+
bdk_chain::ChainPosition::Confirmed(a) => a.confirmation_height,
134+
bdk_chain::ChainPosition::Unconfirmed(_) => 0,
135+
})
135136
} else {
136137
0
137138
};

0 commit comments

Comments
 (0)