diff --git a/crates/chain/Cargo.toml b/crates/chain/Cargo.toml index c25dd712..8aeca3f7 100644 --- a/crates/chain/Cargo.toml +++ b/crates/chain/Cargo.toml @@ -14,13 +14,13 @@ readme = "README.md" [dependencies] # For no-std, remember to enable the bitcoin/no-std feature -bitcoin = { version = "0.29", default-features = false } +bitcoin = { version = "0.30.0", default-features = false } serde_crate = { package = "serde", version = "1", optional = true, features = ["derive"] } # Use hashbrown as a feature flag to have HashSet and HashMap from it. # note version 0.13 breaks outs MSRV. hashbrown = { version = "0.11", optional = true, features = ["serde"] } -miniscript = { version = "9.0.0", optional = true, default-features = false } +miniscript = { version = "10.0.0", optional = true, default-features = false } [dev-dependencies] rand = "0.8" diff --git a/crates/chain/src/chain_data.rs b/crates/chain/src/chain_data.rs index bd174c2e..16877637 100644 --- a/crates/chain/src/chain_data.rs +++ b/crates/chain/src/chain_data.rs @@ -104,7 +104,7 @@ impl Default for BlockId { fn default() -> Self { Self { height: Default::default(), - hash: BlockHash::from_inner([0u8; 32]), + hash: BlockHash::all_zeros(), } } } diff --git a/crates/chain/src/descriptor_ext.rs b/crates/chain/src/descriptor_ext.rs index a3565195..4c77c160 100644 --- a/crates/chain/src/descriptor_ext.rs +++ b/crates/chain/src/descriptor_ext.rs @@ -3,12 +3,14 @@ use crate::miniscript::{Descriptor, DescriptorPublicKey}; /// A trait to extend the functionality of a miniscript descriptor. pub trait DescriptorExt { /// Returns the minimum value (in satoshis) at which an output is broadcastable. + /// Panics if the descriptor wildcard is hardened. fn dust_value(&self) -> u64; } impl DescriptorExt for Descriptor { fn dust_value(&self) -> u64 { self.at_derivation_index(0) + .expect("descriptor can't have hardened derivation") .script_pubkey() .dust_value() .to_sat() diff --git a/crates/chain/src/keychain/txout_index.rs b/crates/chain/src/keychain/txout_index.rs index 8c16afc0..2c5d8d1c 100644 --- a/crates/chain/src/keychain/txout_index.rs +++ b/crates/chain/src/keychain/txout_index.rs @@ -313,7 +313,7 @@ impl KeychainTxOutIndex { self.inner .all_spks() .range((keychain.clone(), u32::MIN)..(keychain.clone(), next_index)) - .map(|((_, derivation_index), spk)| (*derivation_index, spk)) + .map(|((_, derivation_index), spk)| (*derivation_index, spk.as_script())) } /// Get the next derivation index for `keychain`. The next index is the index after the last revealed diff --git a/crates/chain/src/spk_iter.rs b/crates/chain/src/spk_iter.rs index 97c81441..1e09df36 100644 --- a/crates/chain/src/spk_iter.rs +++ b/crates/chain/src/spk_iter.rs @@ -1,5 +1,5 @@ use crate::{ - bitcoin::{secp256k1::Secp256k1, Script}, + bitcoin::{secp256k1::Secp256k1, ScriptBuf}, miniscript::{Descriptor, DescriptorPublicKey}, }; use core::{borrow::Borrow, ops::Bound, ops::RangeBounds}; @@ -22,9 +22,9 @@ pub const BIP32_MAX_INDEX: u32 = (1 << 31) - 1; /// # use std::str::FromStr; /// # let secp = bitcoin::secp256k1::Secp256k1::signing_only(); /// # let (descriptor, _) = Descriptor::::parse_descriptor(&secp, "wpkh([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/1/0)").unwrap(); -/// # let external_spk_0 = descriptor.at_derivation_index(0).script_pubkey(); -/// # let external_spk_3 = descriptor.at_derivation_index(3).script_pubkey(); -/// # let external_spk_4 = descriptor.at_derivation_index(4).script_pubkey(); +/// # let external_spk_0 = descriptor.at_derivation_index(0).unwrap().script_pubkey(); +/// # let external_spk_3 = descriptor.at_derivation_index(3).unwrap().script_pubkey(); +/// # let external_spk_4 = descriptor.at_derivation_index(4).unwrap().script_pubkey(); /// /// // Creates a new script pubkey iterator starting at 0 from a descriptor. /// let mut spk_iter = SpkIterator::new(&descriptor); @@ -84,7 +84,7 @@ impl Iterator for SpkIterator where D: Borrow>, { - type Item = (u32, Script); + type Item = (u32, ScriptBuf); fn next(&mut self) -> Option { // For non-wildcard descriptors, we expect the first element to be Some((0, spk)), then None after. @@ -96,8 +96,7 @@ where let script = self .descriptor .borrow() - .at_derivation_index(self.next_index) - .derived_descriptor(&self.secp) + .derived_descriptor(&self.secp, self.next_index) .expect("the descriptor cannot need hardened derivation") .script_pubkey(); let output = (self.next_index, script); @@ -149,15 +148,14 @@ mod test { #[test] #[allow(clippy::iter_nth_zero)] + #[rustfmt::skip] fn test_spkiterator_wildcard() { let (_, external_desc, _) = init_txout_index(); - let external_spk_0 = external_desc.at_derivation_index(0).script_pubkey(); - let external_spk_16 = external_desc.at_derivation_index(16).script_pubkey(); - let external_spk_20 = external_desc.at_derivation_index(20).script_pubkey(); - let external_spk_21 = external_desc.at_derivation_index(21).script_pubkey(); - let external_spk_max = external_desc - .at_derivation_index(BIP32_MAX_INDEX) - .script_pubkey(); + let external_spk_0 = external_desc.at_derivation_index(0).unwrap().script_pubkey(); + let external_spk_16 = external_desc.at_derivation_index(16).unwrap().script_pubkey(); + let external_spk_20 = external_desc.at_derivation_index(20).unwrap().script_pubkey(); + let external_spk_21 = external_desc.at_derivation_index(21).unwrap().script_pubkey(); + let external_spk_max = external_desc.at_derivation_index(BIP32_MAX_INDEX).unwrap().script_pubkey(); let mut external_spk = SpkIterator::new(&external_desc); let max_index = BIP32_MAX_INDEX - 22; @@ -187,6 +185,7 @@ mod test { let (no_wildcard_descriptor, _) = Descriptor::::parse_descriptor(&secp, "wpkh([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/1/0)").unwrap(); let external_spk_0 = no_wildcard_descriptor .at_derivation_index(0) + .unwrap() .script_pubkey(); let mut external_spk = SpkIterator::new(&no_wildcard_descriptor); diff --git a/crates/chain/src/spk_txout_index.rs b/crates/chain/src/spk_txout_index.rs index 31fd7883..cf862fb8 100644 --- a/crates/chain/src/spk_txout_index.rs +++ b/crates/chain/src/spk_txout_index.rs @@ -5,7 +5,7 @@ use crate::{ indexed_tx_graph::Indexer, ForEachTxOut, }; -use bitcoin::{self, OutPoint, Script, Transaction, TxOut, Txid}; +use bitcoin::{self, OutPoint, Script, ScriptBuf, Transaction, TxOut, Txid}; /// An index storing [`TxOut`]s that have a script pubkey that matches those in a list. /// @@ -30,9 +30,9 @@ use bitcoin::{self, OutPoint, Script, Transaction, TxOut, Txid}; #[derive(Clone, Debug)] pub struct SpkTxOutIndex { /// script pubkeys ordered by index - spks: BTreeMap, + spks: BTreeMap, /// A reverse lookup from spk to spk index - spk_indices: HashMap, + spk_indices: HashMap, /// The set of unused indexes. unused: BTreeSet, /// Lookup index and txout by outpoint. @@ -152,11 +152,11 @@ impl SpkTxOutIndex { use bitcoin::hashes::Hash; use core::ops::Bound::*; let min_op = OutPoint { - txid: Txid::from_inner([0x00; 32]), + txid: Txid::all_zeros(), vout: u32::MIN, }; let max_op = OutPoint { - txid: Txid::from_inner([0xff; 32]), + txid: Txid::from_byte_array([0xff; Txid::LEN]), vout: u32::MAX, }; @@ -188,18 +188,18 @@ impl SpkTxOutIndex { /// /// If that index hasn't been inserted yet, it will return `None`. pub fn spk_at_index(&self, index: &I) -> Option<&Script> { - self.spks.get(index) + self.spks.get(index).map(|s| s.as_script()) } /// The script pubkeys that are being tracked by the index. - pub fn all_spks(&self) -> &BTreeMap { + pub fn all_spks(&self) -> &BTreeMap { &self.spks } /// Adds a script pubkey to scan for. Returns `false` and does nothing if spk already exists in the map /// /// the index will look for outputs spending to this spk whenever it scans new data. - pub fn insert_spk(&mut self, index: I, spk: Script) -> bool { + pub fn insert_spk(&mut self, index: I, spk: ScriptBuf) -> bool { match self.spk_indices.entry(spk.clone()) { Entry::Vacant(value) => { value.insert(index.clone()); diff --git a/crates/chain/tests/common/mod.rs b/crates/chain/tests/common/mod.rs index a32d9c55..2573fd96 100644 --- a/crates/chain/tests/common/mod.rs +++ b/crates/chain/tests/common/mod.rs @@ -56,7 +56,7 @@ macro_rules! changeset { pub fn new_tx(lt: u32) -> bitcoin::Transaction { bitcoin::Transaction { version: 0x00, - lock_time: bitcoin::PackedLockTime(lt), + lock_time: bitcoin::absolute::LockTime::from_consensus(lt), input: vec![], output: vec![], } diff --git a/crates/chain/tests/test_indexed_tx_graph.rs b/crates/chain/tests/test_indexed_tx_graph.rs index b7b62016..59032e65 100644 --- a/crates/chain/tests/test_indexed_tx_graph.rs +++ b/crates/chain/tests/test_indexed_tx_graph.rs @@ -10,7 +10,9 @@ use bdk_chain::{ tx_graph::Additions, BlockId, ChainPosition, ConfirmationHeightAnchor, }; -use bitcoin::{secp256k1::Secp256k1, BlockHash, OutPoint, Script, Transaction, TxIn, TxOut}; +use bitcoin::{ + secp256k1::Secp256k1, BlockHash, OutPoint, Script, ScriptBuf, Transaction, TxIn, TxOut, +}; use miniscript::Descriptor; /// Ensure [`IndexedTxGraph::insert_relevant_txs`] can successfully index transactions NOT presented @@ -25,8 +27,8 @@ fn insert_relevant_txs() { const DESCRIPTOR: &str = "tr([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/0/*)"; let (descriptor, _) = Descriptor::parse_descriptor(&Secp256k1::signing_only(), DESCRIPTOR) .expect("must be valid"); - let spk_0 = descriptor.at_derivation_index(0).script_pubkey(); - let spk_1 = descriptor.at_derivation_index(9).script_pubkey(); + let spk_0 = descriptor.at_derivation_index(0).unwrap().script_pubkey(); + let spk_1 = descriptor.at_derivation_index(9).unwrap().script_pubkey(); let mut graph = IndexedTxGraph::>::default(); graph.index.add_keychain((), descriptor); @@ -127,21 +129,21 @@ fn test_list_owned_txouts() { // Get trusted and untrusted addresses - let mut trusted_spks = Vec::new(); - let mut untrusted_spks = Vec::new(); + let mut trusted_spks: Vec = Vec::new(); + let mut untrusted_spks: Vec = Vec::new(); { // we need to scope here to take immutanble reference of the graph for _ in 0..10 { let ((_, script), _) = graph.index.reveal_next_spk(&"keychain_1".to_string()); // TODO Assert indexes - trusted_spks.push(script.clone()); + trusted_spks.push(script.to_owned()); } } { for _ in 0..10 { let ((_, script), _) = graph.index.reveal_next_spk(&"keychain_2".to_string()); - untrusted_spks.push(script.clone()); + untrusted_spks.push(script.to_owned()); } } @@ -155,7 +157,7 @@ fn test_list_owned_txouts() { }], output: vec![TxOut { value: 70000, - script_pubkey: trusted_spks[0].clone(), + script_pubkey: trusted_spks[0].to_owned(), }], ..common::new_tx(0) }; @@ -164,7 +166,7 @@ fn test_list_owned_txouts() { let tx2 = Transaction { output: vec![TxOut { value: 30000, - script_pubkey: untrusted_spks[0].clone(), + script_pubkey: untrusted_spks[0].to_owned(), }], ..common::new_tx(0) }; @@ -177,7 +179,7 @@ fn test_list_owned_txouts() { }], output: vec![TxOut { value: 10000, - script_pubkey: trusted_spks[1].clone(), + script_pubkey: trusted_spks[1].to_owned(), }], ..common::new_tx(0) }; @@ -186,7 +188,7 @@ fn test_list_owned_txouts() { let tx4 = Transaction { output: vec![TxOut { value: 20000, - script_pubkey: untrusted_spks[1].clone(), + script_pubkey: untrusted_spks[1].to_owned(), }], ..common::new_tx(0) }; @@ -195,7 +197,7 @@ fn test_list_owned_txouts() { let tx5 = Transaction { output: vec![TxOut { value: 15000, - script_pubkey: trusted_spks[2].clone(), + script_pubkey: trusted_spks[2].to_owned(), }], ..common::new_tx(0) }; @@ -258,7 +260,7 @@ fn test_list_owned_txouts() { &local_chain, chain_tip, graph.index.outpoints().iter().cloned(), - |_, spk: &Script| trusted_spks.contains(spk), + |_, spk: &Script| trusted_spks.contains(&spk.to_owned()), ); assert_eq!(txouts.len(), 5); diff --git a/crates/chain/tests/test_keychain_txout_index.rs b/crates/chain/tests/test_keychain_txout_index.rs index a92e7448..d6c66c35 100644 --- a/crates/chain/tests/test_keychain_txout_index.rs +++ b/crates/chain/tests/test_keychain_txout_index.rs @@ -8,7 +8,7 @@ use bdk_chain::{ Append, }; -use bitcoin::{secp256k1::Secp256k1, OutPoint, Script, Transaction, TxOut}; +use bitcoin::{secp256k1::Secp256k1, OutPoint, ScriptBuf, Transaction, TxOut}; use miniscript::{Descriptor, DescriptorPublicKey}; #[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd)] @@ -34,7 +34,7 @@ fn init_txout_index() -> ( (txout_index, external_descriptor, internal_descriptor) } -fn spk_at_index(descriptor: &Descriptor, index: u32) -> Script { +fn spk_at_index(descriptor: &Descriptor, index: u32) -> ScriptBuf { descriptor .derived_descriptor(&Secp256k1::verification_only(), index) .expect("must derive") @@ -177,12 +177,14 @@ fn test_lookahead() { TxOut { script_pubkey: external_desc .at_derivation_index(external_index) + .unwrap() .script_pubkey(), value: 10_000, }, TxOut { script_pubkey: internal_desc .at_derivation_index(internal_index) + .unwrap() .script_pubkey(), value: 10_000, }, @@ -223,9 +225,17 @@ fn test_scan_with_lookahead() { let (mut txout_index, external_desc, _) = init_txout_index(); txout_index.set_lookahead_for_all(10); - let spks: BTreeMap = [0, 10, 20, 30] + let spks: BTreeMap = [0, 10, 20, 30] .into_iter() - .map(|i| (i, external_desc.at_derivation_index(i).script_pubkey())) + .map(|i| { + ( + i, + external_desc + .at_derivation_index(i) + .unwrap() + .script_pubkey(), + ) + }) .collect(); for (&spk_i, spk) in &spks { @@ -251,7 +261,10 @@ fn test_scan_with_lookahead() { } // now try with index 41 (lookahead surpassed), we expect that the txout to not be indexed - let spk_41 = external_desc.at_derivation_index(41).script_pubkey(); + let spk_41 = external_desc + .at_derivation_index(41) + .unwrap() + .script_pubkey(); let op = OutPoint::new(h!("fake tx"), 41); let txout = TxOut { script_pubkey: spk_41, @@ -262,12 +275,13 @@ fn test_scan_with_lookahead() { } #[test] +#[rustfmt::skip] fn test_wildcard_derivations() { let (mut txout_index, external_desc, _) = init_txout_index(); - let external_spk_0 = external_desc.at_derivation_index(0).script_pubkey(); - let external_spk_16 = external_desc.at_derivation_index(16).script_pubkey(); - let external_spk_26 = external_desc.at_derivation_index(26).script_pubkey(); - let external_spk_27 = external_desc.at_derivation_index(27).script_pubkey(); + let external_spk_0 = external_desc.at_derivation_index(0).unwrap().script_pubkey(); + let external_spk_16 = external_desc.at_derivation_index(16).unwrap().script_pubkey(); + let external_spk_26 = external_desc.at_derivation_index(26).unwrap().script_pubkey(); + let external_spk_27 = external_desc.at_derivation_index(27).unwrap().script_pubkey(); // - nothing is derived // - unused list is also empty @@ -277,10 +291,10 @@ fn test_wildcard_derivations() { // - next_unused() == ((0, ), DerivationAdditions:is_empty()) assert_eq!(txout_index.next_index(&TestKeychain::External), (0, true)); let (spk, changeset) = txout_index.reveal_next_spk(&TestKeychain::External); - assert_eq!(spk, (0_u32, &external_spk_0)); + assert_eq!(spk, (0_u32, external_spk_0.as_script())); assert_eq!(changeset.as_inner(), &[(TestKeychain::External, 0)].into()); let (spk, changeset) = txout_index.next_unused_spk(&TestKeychain::External); - assert_eq!(spk, (0_u32, &external_spk_0)); + assert_eq!(spk, (0_u32, external_spk_0.as_script())); assert_eq!(changeset.as_inner(), &[].into()); // - derived till 25 @@ -300,12 +314,12 @@ fn test_wildcard_derivations() { assert_eq!(txout_index.next_index(&TestKeychain::External), (26, true)); let (spk, changeset) = txout_index.reveal_next_spk(&TestKeychain::External); - assert_eq!(spk, (26, &external_spk_26)); + assert_eq!(spk, (26, external_spk_26.as_script())); assert_eq!(changeset.as_inner(), &[(TestKeychain::External, 26)].into()); let (spk, changeset) = txout_index.next_unused_spk(&TestKeychain::External); - assert_eq!(spk, (16, &external_spk_16)); + assert_eq!(spk, (16, external_spk_16.as_script())); assert_eq!(changeset.as_inner(), &[].into()); // - Use all the derived till 26. @@ -315,7 +329,7 @@ fn test_wildcard_derivations() { }); let (spk, changeset) = txout_index.next_unused_spk(&TestKeychain::External); - assert_eq!(spk, (27, &external_spk_27)); + assert_eq!(spk, (27, external_spk_27.as_script())); assert_eq!(changeset.as_inner(), &[(TestKeychain::External, 27)].into()); } @@ -327,6 +341,7 @@ fn test_non_wildcard_derivations() { let (no_wildcard_descriptor, _) = Descriptor::::parse_descriptor(&secp, "wpkh([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/1/0)").unwrap(); let external_spk = no_wildcard_descriptor .at_derivation_index(0) + .unwrap() .script_pubkey(); txout_index.add_keychain(TestKeychain::External, no_wildcard_descriptor); @@ -339,11 +354,11 @@ fn test_non_wildcard_derivations() { // - when we get the next unused script, script @ index 0 assert_eq!(txout_index.next_index(&TestKeychain::External), (0, true)); let (spk, changeset) = txout_index.reveal_next_spk(&TestKeychain::External); - assert_eq!(spk, (0, &external_spk)); + assert_eq!(spk, (0, external_spk.as_script())); assert_eq!(changeset.as_inner(), &[(TestKeychain::External, 0)].into()); let (spk, changeset) = txout_index.next_unused_spk(&TestKeychain::External); - assert_eq!(spk, (0, &external_spk)); + assert_eq!(spk, (0, external_spk.as_script())); assert_eq!(changeset.as_inner(), &[].into()); // given: @@ -356,11 +371,11 @@ fn test_non_wildcard_derivations() { txout_index.mark_used(&TestKeychain::External, 0); let (spk, changeset) = txout_index.reveal_next_spk(&TestKeychain::External); - assert_eq!(spk, (0, &external_spk)); + assert_eq!(spk, (0, external_spk.as_script())); assert_eq!(changeset.as_inner(), &[].into()); let (spk, changeset) = txout_index.next_unused_spk(&TestKeychain::External); - assert_eq!(spk, (0, &external_spk)); + assert_eq!(spk, (0, external_spk.as_script())); assert_eq!(changeset.as_inner(), &[].into()); let (revealed_spks, revealed_additions) = txout_index.reveal_to_target(&TestKeychain::External, 200); diff --git a/crates/chain/tests/test_spk_txout_index.rs b/crates/chain/tests/test_spk_txout_index.rs index ada5a197..099b4ca8 100644 --- a/crates/chain/tests/test_spk_txout_index.rs +++ b/crates/chain/tests/test_spk_txout_index.rs @@ -1,10 +1,10 @@ use bdk_chain::SpkTxOutIndex; -use bitcoin::{hashes::hex::FromHex, OutPoint, PackedLockTime, Script, Transaction, TxIn, TxOut}; +use bitcoin::{absolute, OutPoint, ScriptBuf, Transaction, TxIn, TxOut}; #[test] fn spk_txout_sent_and_received() { - let spk1 = Script::from_hex("001404f1e52ce2bab3423c6a8c63b7cd730d8f12542c").unwrap(); - let spk2 = Script::from_hex("00142b57404ae14f08c3a0c903feb2af7830605eb00f").unwrap(); + let spk1 = ScriptBuf::from_hex("001404f1e52ce2bab3423c6a8c63b7cd730d8f12542c").unwrap(); + let spk2 = ScriptBuf::from_hex("00142b57404ae14f08c3a0c903feb2af7830605eb00f").unwrap(); let mut index = SpkTxOutIndex::default(); index.insert_spk(0, spk1.clone()); @@ -12,7 +12,7 @@ fn spk_txout_sent_and_received() { let tx1 = Transaction { version: 0x02, - lock_time: PackedLockTime(0), + lock_time: absolute::LockTime::ZERO, input: vec![], output: vec![TxOut { value: 42_000, @@ -31,7 +31,7 @@ fn spk_txout_sent_and_received() { let tx2 = Transaction { version: 0x1, - lock_time: PackedLockTime(0), + lock_time: absolute::LockTime::ZERO, input: vec![TxIn { previous_output: OutPoint { txid: tx1.txid(), @@ -57,8 +57,8 @@ fn spk_txout_sent_and_received() { #[test] fn mark_used() { - let spk1 = Script::from_hex("001404f1e52ce2bab3423c6a8c63b7cd730d8f12542c").unwrap(); - let spk2 = Script::from_hex("00142b57404ae14f08c3a0c903feb2af7830605eb00f").unwrap(); + let spk1 = ScriptBuf::from_hex("001404f1e52ce2bab3423c6a8c63b7cd730d8f12542c").unwrap(); + let spk2 = ScriptBuf::from_hex("00142b57404ae14f08c3a0c903feb2af7830605eb00f").unwrap(); let mut spk_index = SpkTxOutIndex::default(); spk_index.insert_spk(1, spk1.clone()); @@ -74,7 +74,7 @@ fn mark_used() { let tx1 = Transaction { version: 0x02, - lock_time: PackedLockTime(0), + lock_time: absolute::LockTime::ZERO, input: vec![], output: vec![TxOut { value: 42_000, diff --git a/crates/chain/tests/test_tx_graph.rs b/crates/chain/tests/test_tx_graph.rs index 41b446e7..1a05844f 100644 --- a/crates/chain/tests/test_tx_graph.rs +++ b/crates/chain/tests/test_tx_graph.rs @@ -7,7 +7,7 @@ use bdk_chain::{ Anchor, Append, BlockId, ChainPosition, ConfirmationHeightAnchor, }; use bitcoin::{ - hashes::Hash, BlockHash, OutPoint, PackedLockTime, Script, Transaction, TxIn, TxOut, Txid, + absolute, hashes::Hash, BlockHash, OutPoint, ScriptBuf, Transaction, TxIn, TxOut, Txid, }; use core::iter; use std::vec; @@ -20,14 +20,14 @@ fn insert_txouts() { OutPoint::new(h!("tx1"), 1), TxOut { value: 10_000, - script_pubkey: Script::new(), + script_pubkey: ScriptBuf::new(), }, ), ( OutPoint::new(h!("tx1"), 2), TxOut { value: 20_000, - script_pubkey: Script::new(), + script_pubkey: ScriptBuf::new(), }, ), ]; @@ -37,21 +37,21 @@ fn insert_txouts() { OutPoint::new(h!("tx2"), 0), TxOut { value: 20_000, - script_pubkey: Script::new(), + script_pubkey: ScriptBuf::new(), }, )]; // One full transaction to be included in the update let update_txs = Transaction { version: 0x01, - lock_time: PackedLockTime(0), + lock_time: absolute::LockTime::ZERO, input: vec![TxIn { previous_output: OutPoint::null(), ..Default::default() }], output: vec![TxOut { value: 30_000, - script_pubkey: Script::new(), + script_pubkey: ScriptBuf::new(), }], }; @@ -161,14 +161,14 @@ fn insert_txouts() { 1u32, &TxOut { value: 10_000, - script_pubkey: Script::new(), + script_pubkey: ScriptBuf::new(), } ), ( 2u32, &TxOut { value: 20_000, - script_pubkey: Script::new(), + script_pubkey: ScriptBuf::new(), } ) ] @@ -181,7 +181,7 @@ fn insert_txouts() { 0u32, &TxOut { value: 30_000, - script_pubkey: Script::new() + script_pubkey: ScriptBuf::new() } )] .into() @@ -192,7 +192,7 @@ fn insert_txouts() { fn insert_tx_graph_doesnt_count_coinbase_as_spent() { let tx = Transaction { version: 0x01, - lock_time: PackedLockTime(0), + lock_time: absolute::LockTime::ZERO, input: vec![TxIn { previous_output: OutPoint::null(), ..Default::default() @@ -210,7 +210,7 @@ fn insert_tx_graph_doesnt_count_coinbase_as_spent() { fn insert_tx_graph_keeps_track_of_spend() { let tx1 = Transaction { version: 0x01, - lock_time: PackedLockTime(0), + lock_time: absolute::LockTime::ZERO, input: vec![], output: vec![TxOut::default()], }; @@ -222,7 +222,7 @@ fn insert_tx_graph_keeps_track_of_spend() { let tx2 = Transaction { version: 0x01, - lock_time: PackedLockTime(0), + lock_time: absolute::LockTime::ZERO, input: vec![TxIn { previous_output: op, ..Default::default() @@ -251,7 +251,7 @@ fn insert_tx_graph_keeps_track_of_spend() { fn insert_tx_can_retrieve_full_tx_from_graph() { let tx = Transaction { version: 0x01, - lock_time: PackedLockTime(0), + lock_time: absolute::LockTime::ZERO, input: vec![TxIn { previous_output: OutPoint::null(), ..Default::default() @@ -269,11 +269,11 @@ fn insert_tx_displaces_txouts() { let mut tx_graph = TxGraph::<()>::default(); let tx = Transaction { version: 0x01, - lock_time: PackedLockTime(0), + lock_time: absolute::LockTime::ZERO, input: vec![], output: vec![TxOut { value: 42_000, - script_pubkey: Script::default(), + script_pubkey: ScriptBuf::default(), }], }; @@ -284,7 +284,7 @@ fn insert_tx_displaces_txouts() { }, TxOut { value: 1_337_000, - script_pubkey: Script::default(), + script_pubkey: ScriptBuf::default(), }, ); @@ -295,7 +295,7 @@ fn insert_tx_displaces_txouts() { }, TxOut { value: 1_000_000_000, - script_pubkey: Script::default(), + script_pubkey: ScriptBuf::default(), }, ); @@ -325,11 +325,11 @@ fn insert_txout_does_not_displace_tx() { let mut tx_graph = TxGraph::<()>::default(); let tx = Transaction { version: 0x01, - lock_time: PackedLockTime(0), + lock_time: absolute::LockTime::ZERO, input: vec![], output: vec![TxOut { value: 42_000, - script_pubkey: Script::default(), + script_pubkey: ScriptBuf::default(), }], }; @@ -342,7 +342,7 @@ fn insert_txout_does_not_displace_tx() { }, TxOut { value: 1_337_000, - script_pubkey: Script::default(), + script_pubkey: ScriptBuf::default(), }, ); @@ -353,7 +353,7 @@ fn insert_txout_does_not_displace_tx() { }, TxOut { value: 1_000_000_000, - script_pubkey: Script::default(), + script_pubkey: ScriptBuf::default(), }, ); @@ -381,7 +381,7 @@ fn test_calculate_fee() { let mut graph = TxGraph::<()>::default(); let intx1 = Transaction { version: 0x01, - lock_time: PackedLockTime(0), + lock_time: absolute::LockTime::ZERO, input: vec![], output: vec![TxOut { value: 100, @@ -390,7 +390,7 @@ fn test_calculate_fee() { }; let intx2 = Transaction { version: 0x02, - lock_time: PackedLockTime(0), + lock_time: absolute::LockTime::ZERO, input: vec![], output: vec![TxOut { value: 200, @@ -415,7 +415,7 @@ fn test_calculate_fee() { let mut tx = Transaction { version: 0x01, - lock_time: PackedLockTime(0), + lock_time: absolute::LockTime::ZERO, input: vec![ TxIn { previous_output: OutPoint { @@ -464,7 +464,7 @@ fn test_calculate_fee() { fn test_calculate_fee_on_coinbase() { let tx = Transaction { version: 0x01, - lock_time: PackedLockTime(0), + lock_time: absolute::LockTime::ZERO, input: vec![TxIn { previous_output: OutPoint::null(), ..Default::default() @@ -636,11 +636,11 @@ fn test_chain_spends() { output: vec![ TxOut { value: 10_000, - script_pubkey: Script::new(), + script_pubkey: ScriptBuf::new(), }, TxOut { value: 20_000, - script_pubkey: Script::new(), + script_pubkey: ScriptBuf::new(), }, ], ..common::new_tx(0) @@ -655,11 +655,11 @@ fn test_chain_spends() { output: vec![ TxOut { value: 5_000, - script_pubkey: Script::new(), + script_pubkey: ScriptBuf::new(), }, TxOut { value: 5_000, - script_pubkey: Script::new(), + script_pubkey: ScriptBuf::new(), }, ], ..common::new_tx(0) @@ -674,11 +674,11 @@ fn test_chain_spends() { output: vec![ TxOut { value: 10_000, - script_pubkey: Script::new(), + script_pubkey: ScriptBuf::new(), }, TxOut { value: 10_000, - script_pubkey: Script::new(), + script_pubkey: ScriptBuf::new(), }, ], ..common::new_tx(0)