]> Untitled Git - bdk/commitdiff
Update bdk_chain to bitcoin 0.30.0
authorDaniela Brozzoni <danielabrozzoni@protonmail.com>
Wed, 21 Jun 2023 15:59:34 +0000 (17:59 +0200)
committerDaniela Brozzoni <danielabrozzoni@protonmail.com>
Thu, 3 Aug 2023 08:58:59 +0000 (10:58 +0200)
crates/chain/Cargo.toml
crates/chain/src/chain_data.rs
crates/chain/src/descriptor_ext.rs
crates/chain/src/keychain/txout_index.rs
crates/chain/src/spk_iter.rs
crates/chain/src/spk_txout_index.rs
crates/chain/tests/common/mod.rs
crates/chain/tests/test_indexed_tx_graph.rs
crates/chain/tests/test_keychain_txout_index.rs
crates/chain/tests/test_spk_txout_index.rs
crates/chain/tests/test_tx_graph.rs

index c25dd7129a8879a8540ce3c90d1111655b03c6b5..8aeca3f7172a0991a105c872dd8da1f4e9acc195 100644 (file)
@@ -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"
index bd174c2e8d6feeac264dafbc13220eea7e50aeea..16877637072d6290013ec338cfcdb10e6a306178 100644 (file)
@@ -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(),
         }
     }
 }
index a356519589752322034dd5b63d4b5e5ccddb69b8..4c77c160bacec8f8c494f6aa34404537dfd58247 100644 (file)
@@ -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<DescriptorPublicKey> {
     fn dust_value(&self) -> u64 {
         self.at_derivation_index(0)
+            .expect("descriptor can't have hardened derivation")
             .script_pubkey()
             .dust_value()
             .to_sat()
index 8c16afc0343953b9650f0ead7f5aaf540a90a301..2c5d8d1c405d9349859801c4b3bf3e0a915977d1 100644 (file)
@@ -313,7 +313,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
         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
index 97c814417985679938b37d4093ec2a2bf31c3188..1e09df36f25d4253c607a3a9a2d7108e72b24e92 100644 (file)
@@ -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::<DescriptorPublicKey>::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<D> Iterator for SpkIterator<D>
 where
     D: Borrow<Descriptor<DescriptorPublicKey>>,
 {
-    type Item = (u32, Script);
+    type Item = (u32, ScriptBuf);
 
     fn next(&mut self) -> Option<Self::Item> {
         // 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::<DescriptorPublicKey>::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);
index 31fd7883c638587dac78d5d54c8df8c150cdf9c8..cf862fb838b936b2a1635fe8293bd5fb8837ed61 100644 (file)
@@ -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<I> {
     /// script pubkeys ordered by index
-    spks: BTreeMap<I, Script>,
+    spks: BTreeMap<I, ScriptBuf>,
     /// A reverse lookup from spk to spk index
-    spk_indices: HashMap<Script, I>,
+    spk_indices: HashMap<ScriptBuf, I>,
     /// The set of unused indexes.
     unused: BTreeSet<I>,
     /// Lookup index and txout by outpoint.
@@ -152,11 +152,11 @@ impl<I: Clone + Ord> SpkTxOutIndex<I> {
         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<I: Clone + Ord> SpkTxOutIndex<I> {
     ///
     /// 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<I, Script> {
+    pub fn all_spks(&self) -> &BTreeMap<I, ScriptBuf> {
         &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());
index a32d9c557f39c7b1cbbf697bcfbb8bb22cfd2e13..2573fd9618afd9639d6967c057d8787f956587ff 100644 (file)
@@ -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![],
     }
index b7b620162d65f2498fb1f5b46febcc01743a54b0..59032e65db59dedaa09dea8fbdd008dd94fe24d2 100644 (file)
@@ -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::<ConfirmationHeightAnchor, KeychainTxOutIndex<()>>::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<ScriptBuf> = Vec::new();
+    let mut untrusted_spks: Vec<ScriptBuf> = 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);
index a92e74486dab2f16bf19ccdd9ac359545492e8d6..d6c66c3539309a44a5e52aa1604d046c63ec934e 100644 (file)
@@ -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<DescriptorPublicKey>, index: u32) -> Script {
+fn spk_at_index(descriptor: &Descriptor<DescriptorPublicKey>, 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<u32, Script> = [0, 10, 20, 30]
+    let spks: BTreeMap<u32, ScriptBuf> = [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, <spk>), 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::<DescriptorPublicKey>::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);
index ada5a19732bafb288ba3f115cb0280b7180ac3e2..099b4ca884071ac64bec9ad01817a09dd487ba6a 100644 (file)
@@ -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,
index 41b446e762bbc5ad4806269b667c503a56460a97..1a05844fe7e2c21a630c9dabfa1c39f5d2bbf299 100644 (file)
@@ -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)