Update coin_select to rust-bitcoin 0.30.0

This commit is contained in:
Daniela Brozzoni 2023-06-26 12:18:15 +02:00
parent 6c29e53ee8
commit b8ac16d03c
No known key found for this signature in database
GPG Key ID: 7DE4F1FDCED0AB87
2 changed files with 7 additions and 5 deletions

View File

@ -97,11 +97,13 @@ impl CoinSelectorOpt {
let mut tx = Transaction { let mut tx = Transaction {
input: vec![], input: vec![],
version: 1, version: 1,
lock_time: LockTime::ZERO.into(), lock_time: absolute::LockTime::ZERO,
output: txouts.to_vec(), output: txouts.to_vec(),
}; };
let base_weight = tx.weight(); 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 = { let drain_weight = {
tx.output.push(drain_output.clone()); tx.output.push(drain_output.clone());
tx.weight() - base_weight tx.weight() - base_weight
@ -113,8 +115,8 @@ impl CoinSelectorOpt {
Some(txouts.iter().map(|txout| txout.value).sum()) Some(txouts.iter().map(|txout| txout.value).sum())
}, },
..Self::from_weights( ..Self::from_weights(
base_weight as u32, base_weight.to_wu() as u32,
drain_weight as u32, drain_weight.to_wu() as u32,
TXIN_BASE_WEIGHT + drain_satisfaction_weight, TXIN_BASE_WEIGHT + drain_satisfaction_weight,
) )
} }

View File

@ -12,7 +12,7 @@ use bdk_chain::{
bitcoin, bitcoin,
collections::{BTreeSet, HashMap}, collections::{BTreeSet, HashMap},
}; };
use bitcoin::{LockTime, Transaction, TxOut}; use bitcoin::{absolute, Transaction, TxOut};
use core::fmt::{Debug, Display}; use core::fmt::{Debug, Display};
mod coin_selector; mod coin_selector;