Skip to content

Commit db25555

Browse files
committed
deps!: Update bdk_chain to 0.23.0
feat(params): Add options to `{Create,Load}Params` to enable a persistent cache of script pubkeys. feat: Update code to account for `first_seen`. examples: Update example crates dependencies Note: This change also extends the wallet ChangeSet type by adding `first_seen` to the tx_graph member, and adding `spk_cache` to the indexer.
1 parent f0840c0 commit db25555

File tree

9 files changed

+65
-22
lines changed

9 files changed

+65
-22
lines changed

examples/example_wallet_electrum/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ edition = "2021"
55

66
[dependencies]
77
bdk_wallet = { path = "../../wallet", features = ["file_store"] }
8-
bdk_electrum = { version = "0.22.0" }
8+
bdk_electrum = { version = "0.23.0" }
99
anyhow = "1"

examples/example_wallet_esplora_async/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ edition = "2021"
77

88
[dependencies]
99
bdk_wallet = { path = "../../wallet", features = ["rusqlite"] }
10-
bdk_esplora = { version = "0.21.0", features = ["async-https", "tokio"] }
10+
bdk_esplora = { version = "0.22.0", features = ["async-https", "tokio"] }
1111
tokio = { version = "1.38.1", features = ["rt", "rt-multi-thread", "macros"] }
1212
anyhow = "1"

examples/example_wallet_esplora_blocking/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ publish = false
88

99
[dependencies]
1010
bdk_wallet = { path = "../../wallet", features = ["file_store"] }
11-
bdk_esplora = { version = "0.21.0", features = ["blocking"] }
11+
bdk_esplora = { version = "0.22.0", features = ["blocking"] }
1212
anyhow = "1"

examples/example_wallet_rpc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77

88
[dependencies]
99
bdk_wallet = { path = "../../wallet", features = ["file_store"] }
10-
bdk_bitcoind_rpc = { version = "0.19.0" }
10+
bdk_bitcoind_rpc = { version = "0.20.0" }
1111

1212
anyhow = "1"
1313
clap = { version = "4.5.17", features = ["derive", "env"] }

wallet/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ miniscript = { version = "12.3.1", features = [ "serde" ], default-features = fa
2121
bitcoin = { version = "0.32.4", features = [ "serde", "base64" ], default-features = false }
2222
serde = { version = "^1.0", features = ["derive"] }
2323
serde_json = { version = "^1.0" }
24-
bdk_chain = { version = "0.22.0", features = [ "miniscript", "serde" ], default-features = false }
24+
bdk_chain = { version = "0.23.0", features = [ "miniscript", "serde" ], default-features = false }
2525

2626
# Optional dependencies
2727
bip39 = { version = "2.0", optional = true }
28-
bdk_file_store = { version = "0.20.0", optional = true }
28+
bdk_file_store = { version = "0.21.0", optional = true }
2929

3030
[features]
3131
default = ["std"]
@@ -40,7 +40,7 @@ test-utils = ["std"]
4040
[dev-dependencies]
4141
assert_matches = "1.5.0"
4242
tempfile = "3"
43-
bdk_chain = { version = "0.22.0", features = ["rusqlite"] }
43+
bdk_chain = { version = "0.23.0", features = ["rusqlite"] }
4444
bdk_wallet = { path = ".", features = ["rusqlite", "file_store", "test-utils"] }
4545
anyhow = "1"
4646
rand = "^0.8"

wallet/src/wallet/coin_selection.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ mod test {
750750
value,
751751
index,
752752
ChainPosition::Unconfirmed {
753+
first_seen: Some(last_seen),
753754
last_seen: Some(last_seen),
754755
},
755756
)
@@ -850,7 +851,10 @@ mod test {
850851
transitively: None,
851852
}
852853
} else {
853-
ChainPosition::Unconfirmed { last_seen: Some(0) }
854+
ChainPosition::Unconfirmed {
855+
first_seen: Some(1),
856+
last_seen: Some(1),
857+
}
854858
},
855859
}),
856860
});
@@ -875,7 +879,10 @@ mod test {
875879
keychain: KeychainKind::External,
876880
is_spent: false,
877881
derivation_index: 42,
878-
chain_position: ChainPosition::Unconfirmed { last_seen: Some(0) },
882+
chain_position: ChainPosition::Unconfirmed {
883+
first_seen: Some(1),
884+
last_seen: Some(1),
885+
},
879886
}),
880887
})
881888
.collect()
@@ -1231,7 +1238,10 @@ mod test {
12311238
optional.push(utxo(
12321239
Amount::from_sat(500_000),
12331240
3,
1234-
ChainPosition::<ConfirmationBlockTime>::Unconfirmed { last_seen: Some(0) },
1241+
ChainPosition::<ConfirmationBlockTime>::Unconfirmed {
1242+
first_seen: Some(1),
1243+
last_seen: Some(1),
1244+
},
12351245
));
12361246

12371247
// Defensive assertions, for sanity and in case someone changes the test utxos vector.

wallet/src/wallet/mod.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,12 @@ impl Wallet {
437437
None => (None, Arc::new(SignersContainer::new())),
438438
};
439439

440-
let index = create_indexer(descriptor, change_descriptor, params.lookahead)?;
440+
let index = create_indexer(
441+
descriptor,
442+
change_descriptor,
443+
params.lookahead,
444+
params.use_spk_cache,
445+
)?;
441446

442447
let descriptor = index.get_descriptor(KeychainKind::External).cloned();
443448
let change_descriptor = index.get_descriptor(KeychainKind::Internal).cloned();
@@ -636,8 +641,13 @@ impl Wallet {
636641
None => Arc::new(SignersContainer::new()),
637642
};
638643

639-
let index = create_indexer(descriptor, change_descriptor, params.lookahead)
640-
.map_err(LoadError::Descriptor)?;
644+
let index = create_indexer(
645+
descriptor,
646+
change_descriptor,
647+
params.lookahead,
648+
params.use_spk_cache,
649+
)
650+
.map_err(LoadError::Descriptor)?;
641651

642652
let mut indexed_graph = IndexedTxGraph::new(index);
643653
indexed_graph.apply_changeset(changeset.indexer.into());
@@ -1090,9 +1100,9 @@ impl Wallet {
10901100
/// "tx is an ancestor of a tx anchored in {}:{}",
10911101
/// anchor.block_id.height, anchor.block_id.hash,
10921102
/// ),
1093-
/// ChainPosition::Unconfirmed { last_seen } => println!(
1094-
/// "tx is last seen at {:?}, it is unconfirmed as it is not anchored in the best chain",
1095-
/// last_seen,
1103+
/// ChainPosition::Unconfirmed { first_seen, last_seen } => println!(
1104+
/// "tx is first seen at {:?}, last seen at {:?}, it is unconfirmed as it is not anchored in the best chain",
1105+
/// first_seen, last_seen
10961106
/// ),
10971107
/// }
10981108
/// ```
@@ -2591,17 +2601,14 @@ fn create_indexer(
25912601
descriptor: ExtendedDescriptor,
25922602
change_descriptor: Option<ExtendedDescriptor>,
25932603
lookahead: u32,
2604+
use_spk_cache: bool,
25942605
) -> Result<KeychainTxOutIndex<KeychainKind>, DescriptorError> {
2595-
let mut indexer = KeychainTxOutIndex::<KeychainKind>::new(lookahead);
2606+
let mut indexer = KeychainTxOutIndex::<KeychainKind>::new(lookahead, use_spk_cache);
25962607

2597-
// let (descriptor, keymap) = descriptor;
2598-
// let signers = Arc::new(SignersContainer::build(keymap, &descriptor, secp));
25992608
assert!(indexer
26002609
.insert_descriptor(KeychainKind::External, descriptor)
26012610
.expect("first descriptor introduced must succeed"));
26022611

2603-
// let (descriptor, keymap) = change_descriptor;
2604-
// let change_signers = Arc::new(SignersContainer::build(keymap, &descriptor, secp));
26052612
if let Some(change_descriptor) = change_descriptor {
26062613
assert!(indexer
26072614
.insert_descriptor(KeychainKind::Internal, change_descriptor)

wallet/src/wallet/params.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub struct CreateParams {
3939
pub(crate) network: Network,
4040
pub(crate) genesis_hash: Option<BlockHash>,
4141
pub(crate) lookahead: u32,
42+
pub(crate) use_spk_cache: bool,
4243
}
4344

4445
impl CreateParams {
@@ -61,6 +62,7 @@ impl CreateParams {
6162
network: Network::Bitcoin,
6263
genesis_hash: None,
6364
lookahead: DEFAULT_LOOKAHEAD,
65+
use_spk_cache: false,
6466
}
6567
}
6668

@@ -82,6 +84,7 @@ impl CreateParams {
8284
network: Network::Bitcoin,
8385
genesis_hash: None,
8486
lookahead: DEFAULT_LOOKAHEAD,
87+
use_spk_cache: false,
8588
}
8689
}
8790

@@ -118,6 +121,15 @@ impl CreateParams {
118121
self
119122
}
120123

124+
/// Use a persistent cache of indexed script pubkeys (SPKs).
125+
///
126+
/// **Note:** To persist across restarts, this option must also be set at load time with
127+
/// [`LoadParams`](LoadParams::use_spk_cache).
128+
pub fn use_spk_cache(mut self, use_spk_cache: bool) -> Self {
129+
self.use_spk_cache = use_spk_cache;
130+
self
131+
}
132+
121133
/// Create [`PersistedWallet`] with the given [`WalletPersister`].
122134
pub fn create_wallet<P>(
123135
self,
@@ -157,6 +169,7 @@ pub struct LoadParams {
157169
pub(crate) check_descriptor: Option<Option<DescriptorToExtract>>,
158170
pub(crate) check_change_descriptor: Option<Option<DescriptorToExtract>>,
159171
pub(crate) extract_keys: bool,
172+
pub(crate) use_spk_cache: bool,
160173
}
161174

162175
impl LoadParams {
@@ -173,6 +186,7 @@ impl LoadParams {
173186
check_descriptor: None,
174187
check_change_descriptor: None,
175188
extract_keys: false,
189+
use_spk_cache: false,
176190
}
177191
}
178192

@@ -234,6 +248,15 @@ impl LoadParams {
234248
self
235249
}
236250

251+
/// Use a persistent cache of indexed script pubkeys (SPKs).
252+
///
253+
/// **Note:** This should only be used if you have previously persisted a cache of script
254+
/// pubkeys using [`CreateParams::use_spk_cache`].
255+
pub fn use_spk_cache(mut self, use_spk_cache: bool) -> Self {
256+
self.use_spk_cache = use_spk_cache;
257+
self
258+
}
259+
237260
/// Load [`PersistedWallet`] with the given [`WalletPersister`].
238261
pub fn load_wallet<P>(
239262
self,

wallet/src/wallet/tx_builder.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,10 @@ mod test {
10241024
txout: TxOut::NULL,
10251025
keychain: KeychainKind::External,
10261026
is_spent: false,
1027-
chain_position: chain::ChainPosition::Unconfirmed { last_seen: Some(0) },
1027+
chain_position: chain::ChainPosition::Unconfirmed {
1028+
first_seen: Some(1),
1029+
last_seen: Some(1),
1030+
},
10281031
derivation_index: 0,
10291032
},
10301033
LocalOutput {

0 commit comments

Comments
 (0)