Skip to content

Commit b8ac16d

Browse files
Update coin_select to rust-bitcoin 0.30.0
1 parent 6c29e53 commit b8ac16d

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

nursery/coin_select/src/coin_selector.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ impl CoinSelectorOpt {
9797
let mut tx = Transaction {
9898
input: vec![],
9999
version: 1,
100-
lock_time: LockTime::ZERO.into(),
100+
lock_time: absolute::LockTime::ZERO,
101101
output: txouts.to_vec(),
102102
};
103103
let base_weight = tx.weight();
104-
// this awkward calculation is necessary since TxOut doesn't have \.weight()
104+
// Calculating drain_weight like this instead of using .weight()
105+
// allows us to take into account the output len varint increase that
106+
// might happen when adding a new output
105107
let drain_weight = {
106108
tx.output.push(drain_output.clone());
107109
tx.weight() - base_weight
@@ -113,8 +115,8 @@ impl CoinSelectorOpt {
113115
Some(txouts.iter().map(|txout| txout.value).sum())
114116
},
115117
..Self::from_weights(
116-
base_weight as u32,
117-
drain_weight as u32,
118+
base_weight.to_wu() as u32,
119+
drain_weight.to_wu() as u32,
118120
TXIN_BASE_WEIGHT + drain_satisfaction_weight,
119121
)
120122
}

nursery/coin_select/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use bdk_chain::{
1212
bitcoin,
1313
collections::{BTreeSet, HashMap},
1414
};
15-
use bitcoin::{LockTime, Transaction, TxOut};
15+
use bitcoin::{absolute, Transaction, TxOut};
1616
use core::fmt::{Debug, Display};
1717

1818
mod coin_selector;

0 commit comments

Comments
 (0)