Skip to content

Commit 0118419

Browse files
committed
refactor(bdk)!: Remove trait Vbytes
The only place this is being used is a unit test that is easily refactored. For size conversions prefer methods on e.g. `Weight`.
1 parent 596452b commit 0118419

File tree

2 files changed

+6
-24
lines changed

2 files changed

+6
-24
lines changed

crates/bdk/src/types.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,6 @@ impl AsRef<[u8]> for KeychainKind {
4646
}
4747
}
4848

49-
/// Trait implemented by types that can be used to measure weight units.
50-
pub trait Vbytes {
51-
/// Convert weight units to virtual bytes.
52-
fn vbytes(self) -> usize;
53-
}
54-
55-
impl Vbytes for usize {
56-
fn vbytes(self) -> usize {
57-
// ref: https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#transaction-size-calculations
58-
(self as f32 / 4.0).ceil() as usize
59-
}
60-
}
61-
6249
/// An unspent output owned by a [`Wallet`].
6350
///
6451
/// [`Wallet`]: crate::Wallet

crates/bdk/src/wallet/coin_selection.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -744,12 +744,11 @@ mod test {
744744
use core::str::FromStr;
745745

746746
use bdk_chain::ConfirmationTime;
747-
use bitcoin::{OutPoint, ScriptBuf, TxOut};
747+
use bitcoin::{Amount, OutPoint, ScriptBuf, TxOut};
748748

749749
use super::*;
750750
use crate::types::*;
751751
use crate::wallet::coin_selection::filter_duplicates;
752-
use crate::wallet::Vbytes;
753752

754753
use rand::rngs::StdRng;
755754
use rand::seq::SliceRandom;
@@ -1233,22 +1232,18 @@ mod test {
12331232
let utxos = get_test_utxos();
12341233
let drain_script = ScriptBuf::default();
12351234
let target_amount = 99932; // first utxo's effective value
1235+
let feerate = FeeRate::BROADCAST_MIN;
12361236

12371237
let result = BranchAndBoundCoinSelection::new(0)
1238-
.coin_select(
1239-
vec![],
1240-
utxos,
1241-
FeeRate::from_sat_per_vb_unchecked(1),
1242-
target_amount,
1243-
&drain_script,
1244-
)
1238+
.coin_select(vec![], utxos, feerate, target_amount, &drain_script)
12451239
.unwrap();
12461240

12471241
assert_eq!(result.selected.len(), 1);
12481242
assert_eq!(result.selected_amount(), 100_000);
1249-
let input_size = (TXIN_BASE_WEIGHT + P2WPKH_SATISFACTION_SIZE).vbytes();
1243+
let input_weight = (TXIN_BASE_WEIGHT + P2WPKH_SATISFACTION_SIZE) as u64;
12501244
// the final fee rate should be exactly the same as the fee rate given
1251-
assert!((1.0 - (result.fee_amount as f32 / input_size as f32)).abs() < f32::EPSILON);
1245+
let result_feerate = Amount::from_sat(result.fee_amount) / Weight::from_wu(input_weight);
1246+
assert_eq!(result_feerate, feerate);
12521247
}
12531248

12541249
#[test]

0 commit comments

Comments
 (0)