Skip to content

Commit 853d361

Browse files
Update bdk_chain to bitcoin 0.30.0
1 parent d73669e commit 853d361

File tree

11 files changed

+115
-97
lines changed

11 files changed

+115
-97
lines changed

crates/chain/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ readme = "README.md"
1414

1515
[dependencies]
1616
# For no-std, remember to enable the bitcoin/no-std feature
17-
bitcoin = { version = "0.29", default-features = false }
17+
bitcoin = { version = "0.30.0", default-features = false }
1818
serde_crate = { package = "serde", version = "1", optional = true, features = ["derive"] }
1919

2020
# Use hashbrown as a feature flag to have HashSet and HashMap from it.
2121
# note version 0.13 breaks outs MSRV.
2222
hashbrown = { version = "0.11", optional = true, features = ["serde"] }
23-
miniscript = { version = "9.0.0", optional = true, default-features = false }
23+
miniscript = { version = "10.0.0", optional = true, default-features = false }
2424

2525
[dev-dependencies]
2626
rand = "0.8"

crates/chain/src/chain_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl Default for BlockId {
104104
fn default() -> Self {
105105
Self {
106106
height: Default::default(),
107-
hash: BlockHash::from_inner([0u8; 32]),
107+
hash: BlockHash::all_zeros(),
108108
}
109109
}
110110
}

crates/chain/src/descriptor_ext.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ use crate::miniscript::{Descriptor, DescriptorPublicKey};
33
/// A trait to extend the functionality of a miniscript descriptor.
44
pub trait DescriptorExt {
55
/// Returns the minimum value (in satoshis) at which an output is broadcastable.
6+
/// Panics if the descriptor wildcard is hardened.
67
fn dust_value(&self) -> u64;
78
}
89

910
impl DescriptorExt for Descriptor<DescriptorPublicKey> {
1011
fn dust_value(&self) -> u64 {
1112
self.at_derivation_index(0)
13+
.expect("descriptor can't have hardened derivation")
1214
.script_pubkey()
1315
.dust_value()
1416
.to_sat()

crates/chain/src/keychain/txout_index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
313313
self.inner
314314
.all_spks()
315315
.range((keychain.clone(), u32::MIN)..(keychain.clone(), next_index))
316-
.map(|((_, derivation_index), spk)| (*derivation_index, spk))
316+
.map(|((_, derivation_index), spk)| (*derivation_index, spk.as_script()))
317317
}
318318

319319
/// Get the next derivation index for `keychain`. The next index is the index after the last revealed

crates/chain/src/spk_iter.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
bitcoin::{secp256k1::Secp256k1, Script},
2+
bitcoin::{secp256k1::Secp256k1, ScriptBuf},
33
miniscript::{Descriptor, DescriptorPublicKey},
44
};
55
use core::{borrow::Borrow, ops::Bound, ops::RangeBounds};
@@ -22,9 +22,9 @@ pub const BIP32_MAX_INDEX: u32 = (1 << 31) - 1;
2222
/// # use std::str::FromStr;
2323
/// # let secp = bitcoin::secp256k1::Secp256k1::signing_only();
2424
/// # let (descriptor, _) = Descriptor::<DescriptorPublicKey>::parse_descriptor(&secp, "wpkh([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/1/0)").unwrap();
25-
/// # let external_spk_0 = descriptor.at_derivation_index(0).script_pubkey();
26-
/// # let external_spk_3 = descriptor.at_derivation_index(3).script_pubkey();
27-
/// # let external_spk_4 = descriptor.at_derivation_index(4).script_pubkey();
25+
/// # let external_spk_0 = descriptor.at_derivation_index(0).unwrap().script_pubkey();
26+
/// # let external_spk_3 = descriptor.at_derivation_index(3).unwrap().script_pubkey();
27+
/// # let external_spk_4 = descriptor.at_derivation_index(4).unwrap().script_pubkey();
2828
///
2929
/// // Creates a new script pubkey iterator starting at 0 from a descriptor.
3030
/// let mut spk_iter = SpkIterator::new(&descriptor);
@@ -84,7 +84,7 @@ impl<D> Iterator for SpkIterator<D>
8484
where
8585
D: Borrow<Descriptor<DescriptorPublicKey>>,
8686
{
87-
type Item = (u32, Script);
87+
type Item = (u32, ScriptBuf);
8888

8989
fn next(&mut self) -> Option<Self::Item> {
9090
// For non-wildcard descriptors, we expect the first element to be Some((0, spk)), then None after.
@@ -96,8 +96,7 @@ where
9696
let script = self
9797
.descriptor
9898
.borrow()
99-
.at_derivation_index(self.next_index)
100-
.derived_descriptor(&self.secp)
99+
.derived_descriptor(&self.secp, self.next_index)
101100
.expect("the descriptor cannot need hardened derivation")
102101
.script_pubkey();
103102
let output = (self.next_index, script);
@@ -149,15 +148,14 @@ mod test {
149148

150149
#[test]
151150
#[allow(clippy::iter_nth_zero)]
151+
#[rustfmt::skip]
152152
fn test_spkiterator_wildcard() {
153153
let (_, external_desc, _) = init_txout_index();
154-
let external_spk_0 = external_desc.at_derivation_index(0).script_pubkey();
155-
let external_spk_16 = external_desc.at_derivation_index(16).script_pubkey();
156-
let external_spk_20 = external_desc.at_derivation_index(20).script_pubkey();
157-
let external_spk_21 = external_desc.at_derivation_index(21).script_pubkey();
158-
let external_spk_max = external_desc
159-
.at_derivation_index(BIP32_MAX_INDEX)
160-
.script_pubkey();
154+
let external_spk_0 = external_desc.at_derivation_index(0).unwrap().script_pubkey();
155+
let external_spk_16 = external_desc.at_derivation_index(16).unwrap().script_pubkey();
156+
let external_spk_20 = external_desc.at_derivation_index(20).unwrap().script_pubkey();
157+
let external_spk_21 = external_desc.at_derivation_index(21).unwrap().script_pubkey();
158+
let external_spk_max = external_desc.at_derivation_index(BIP32_MAX_INDEX).unwrap().script_pubkey();
161159

162160
let mut external_spk = SpkIterator::new(&external_desc);
163161
let max_index = BIP32_MAX_INDEX - 22;
@@ -187,6 +185,7 @@ mod test {
187185
let (no_wildcard_descriptor, _) = Descriptor::<DescriptorPublicKey>::parse_descriptor(&secp, "wpkh([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/1/0)").unwrap();
188186
let external_spk_0 = no_wildcard_descriptor
189187
.at_derivation_index(0)
188+
.unwrap()
190189
.script_pubkey();
191190

192191
let mut external_spk = SpkIterator::new(&no_wildcard_descriptor);

crates/chain/src/spk_txout_index.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
indexed_tx_graph::Indexer,
66
ForEachTxOut,
77
};
8-
use bitcoin::{self, OutPoint, Script, Transaction, TxOut, Txid};
8+
use bitcoin::{self, OutPoint, Script, ScriptBuf, Transaction, TxOut, Txid};
99

1010
/// An index storing [`TxOut`]s that have a script pubkey that matches those in a list.
1111
///
@@ -30,9 +30,9 @@ use bitcoin::{self, OutPoint, Script, Transaction, TxOut, Txid};
3030
#[derive(Clone, Debug)]
3131
pub struct SpkTxOutIndex<I> {
3232
/// script pubkeys ordered by index
33-
spks: BTreeMap<I, Script>,
33+
spks: BTreeMap<I, ScriptBuf>,
3434
/// A reverse lookup from spk to spk index
35-
spk_indices: HashMap<Script, I>,
35+
spk_indices: HashMap<ScriptBuf, I>,
3636
/// The set of unused indexes.
3737
unused: BTreeSet<I>,
3838
/// Lookup index and txout by outpoint.
@@ -152,11 +152,11 @@ impl<I: Clone + Ord> SpkTxOutIndex<I> {
152152
use bitcoin::hashes::Hash;
153153
use core::ops::Bound::*;
154154
let min_op = OutPoint {
155-
txid: Txid::from_inner([0x00; 32]),
155+
txid: Txid::all_zeros(),
156156
vout: u32::MIN,
157157
};
158158
let max_op = OutPoint {
159-
txid: Txid::from_inner([0xff; 32]),
159+
txid: Txid::from_byte_array([0xff; Txid::LEN]),
160160
vout: u32::MAX,
161161
};
162162

@@ -188,18 +188,18 @@ impl<I: Clone + Ord> SpkTxOutIndex<I> {
188188
///
189189
/// If that index hasn't been inserted yet, it will return `None`.
190190
pub fn spk_at_index(&self, index: &I) -> Option<&Script> {
191-
self.spks.get(index)
191+
self.spks.get(index).map(|s| s.as_script())
192192
}
193193

194194
/// The script pubkeys that are being tracked by the index.
195-
pub fn all_spks(&self) -> &BTreeMap<I, Script> {
195+
pub fn all_spks(&self) -> &BTreeMap<I, ScriptBuf> {
196196
&self.spks
197197
}
198198

199199
/// Adds a script pubkey to scan for. Returns `false` and does nothing if spk already exists in the map
200200
///
201201
/// the index will look for outputs spending to this spk whenever it scans new data.
202-
pub fn insert_spk(&mut self, index: I, spk: Script) -> bool {
202+
pub fn insert_spk(&mut self, index: I, spk: ScriptBuf) -> bool {
203203
match self.spk_indices.entry(spk.clone()) {
204204
Entry::Vacant(value) => {
205205
value.insert(index.clone());

crates/chain/tests/common/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ macro_rules! changeset {
5656
pub fn new_tx(lt: u32) -> bitcoin::Transaction {
5757
bitcoin::Transaction {
5858
version: 0x00,
59-
lock_time: bitcoin::PackedLockTime(lt),
59+
lock_time: bitcoin::absolute::LockTime::from_consensus(lt),
6060
input: vec![],
6161
output: vec![],
6262
}

crates/chain/tests/test_indexed_tx_graph.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ use bdk_chain::{
1010
tx_graph::Additions,
1111
BlockId, ChainPosition, ConfirmationHeightAnchor,
1212
};
13-
use bitcoin::{secp256k1::Secp256k1, BlockHash, OutPoint, Script, Transaction, TxIn, TxOut};
13+
use bitcoin::{
14+
secp256k1::Secp256k1, BlockHash, OutPoint, Script, ScriptBuf, Transaction, TxIn, TxOut,
15+
};
1416
use miniscript::Descriptor;
1517

1618
/// Ensure [`IndexedTxGraph::insert_relevant_txs`] can successfully index transactions NOT presented
@@ -25,8 +27,8 @@ fn insert_relevant_txs() {
2527
const DESCRIPTOR: &str = "tr([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/0/*)";
2628
let (descriptor, _) = Descriptor::parse_descriptor(&Secp256k1::signing_only(), DESCRIPTOR)
2729
.expect("must be valid");
28-
let spk_0 = descriptor.at_derivation_index(0).script_pubkey();
29-
let spk_1 = descriptor.at_derivation_index(9).script_pubkey();
30+
let spk_0 = descriptor.at_derivation_index(0).unwrap().script_pubkey();
31+
let spk_1 = descriptor.at_derivation_index(9).unwrap().script_pubkey();
3032

3133
let mut graph = IndexedTxGraph::<ConfirmationHeightAnchor, KeychainTxOutIndex<()>>::default();
3234
graph.index.add_keychain((), descriptor);
@@ -127,21 +129,21 @@ fn test_list_owned_txouts() {
127129

128130
// Get trusted and untrusted addresses
129131

130-
let mut trusted_spks = Vec::new();
131-
let mut untrusted_spks = Vec::new();
132+
let mut trusted_spks: Vec<ScriptBuf> = Vec::new();
133+
let mut untrusted_spks: Vec<ScriptBuf> = Vec::new();
132134

133135
{
134136
// we need to scope here to take immutanble reference of the graph
135137
for _ in 0..10 {
136138
let ((_, script), _) = graph.index.reveal_next_spk(&"keychain_1".to_string());
137139
// TODO Assert indexes
138-
trusted_spks.push(script.clone());
140+
trusted_spks.push(script.to_owned());
139141
}
140142
}
141143
{
142144
for _ in 0..10 {
143145
let ((_, script), _) = graph.index.reveal_next_spk(&"keychain_2".to_string());
144-
untrusted_spks.push(script.clone());
146+
untrusted_spks.push(script.to_owned());
145147
}
146148
}
147149

@@ -155,7 +157,7 @@ fn test_list_owned_txouts() {
155157
}],
156158
output: vec![TxOut {
157159
value: 70000,
158-
script_pubkey: trusted_spks[0].clone(),
160+
script_pubkey: trusted_spks[0].to_owned(),
159161
}],
160162
..common::new_tx(0)
161163
};
@@ -164,7 +166,7 @@ fn test_list_owned_txouts() {
164166
let tx2 = Transaction {
165167
output: vec![TxOut {
166168
value: 30000,
167-
script_pubkey: untrusted_spks[0].clone(),
169+
script_pubkey: untrusted_spks[0].to_owned(),
168170
}],
169171
..common::new_tx(0)
170172
};
@@ -177,7 +179,7 @@ fn test_list_owned_txouts() {
177179
}],
178180
output: vec![TxOut {
179181
value: 10000,
180-
script_pubkey: trusted_spks[1].clone(),
182+
script_pubkey: trusted_spks[1].to_owned(),
181183
}],
182184
..common::new_tx(0)
183185
};
@@ -186,7 +188,7 @@ fn test_list_owned_txouts() {
186188
let tx4 = Transaction {
187189
output: vec![TxOut {
188190
value: 20000,
189-
script_pubkey: untrusted_spks[1].clone(),
191+
script_pubkey: untrusted_spks[1].to_owned(),
190192
}],
191193
..common::new_tx(0)
192194
};
@@ -195,7 +197,7 @@ fn test_list_owned_txouts() {
195197
let tx5 = Transaction {
196198
output: vec![TxOut {
197199
value: 15000,
198-
script_pubkey: trusted_spks[2].clone(),
200+
script_pubkey: trusted_spks[2].to_owned(),
199201
}],
200202
..common::new_tx(0)
201203
};
@@ -258,7 +260,7 @@ fn test_list_owned_txouts() {
258260
&local_chain,
259261
chain_tip,
260262
graph.index.outpoints().iter().cloned(),
261-
|_, spk: &Script| trusted_spks.contains(spk),
263+
|_, spk: &Script| trusted_spks.contains(&spk.to_owned()),
262264
);
263265

264266
assert_eq!(txouts.len(), 5);

0 commit comments

Comments
 (0)