]> Untitled Git - bdk/commitdiff
Update coin_select to rust-bitcoin 0.30.0
authorDaniela Brozzoni <danielabrozzoni@protonmail.com>
Mon, 26 Jun 2023 10:18:15 +0000 (12:18 +0200)
committerDaniela Brozzoni <danielabrozzoni@protonmail.com>
Thu, 3 Aug 2023 08:59:08 +0000 (10:59 +0200)
nursery/coin_select/src/coin_selector.rs
nursery/coin_select/src/lib.rs

index 7b136c21136c87cfdf9212c266d265350fb896c7..281992a963472963cff70a842b23d5a6b6e7afbe 100644 (file)
@@ -97,11 +97,13 @@ impl CoinSelectorOpt {
         let mut tx = Transaction {
             input: vec![],
             version: 1,
-            lock_time: LockTime::ZERO.into(),
+            lock_time: absolute::LockTime::ZERO,
             output: txouts.to_vec(),
         };
         let base_weight = tx.weight();
-        // this awkward calculation is necessary since TxOut doesn't have \.weight()
+        // Calculating drain_weight like this instead of using .weight()
+        // allows us to take into account the output len varint increase that
+        // might happen when adding a new output
         let drain_weight = {
             tx.output.push(drain_output.clone());
             tx.weight() - base_weight
@@ -113,8 +115,8 @@ impl CoinSelectorOpt {
                 Some(txouts.iter().map(|txout| txout.value).sum())
             },
             ..Self::from_weights(
-                base_weight as u32,
-                drain_weight as u32,
+                base_weight.to_wu() as u32,
+                drain_weight.to_wu() as u32,
                 TXIN_BASE_WEIGHT + drain_satisfaction_weight,
             )
         }
index ff4d4539932a89162046f76ba67a693cf47aeb78..dc38c676db77f63754f3346363522fbecfe2054c 100644 (file)
@@ -12,7 +12,7 @@ use bdk_chain::{
     bitcoin,
     collections::{BTreeSet, HashMap},
 };
-use bitcoin::{LockTime, Transaction, TxOut};
+use bitcoin::{absolute, Transaction, TxOut};
 use core::fmt::{Debug, Display};
 
 mod coin_selector;