Skip to content

Commit 033a48b

Browse files
feat: expose FeeRate::fee_vb and FeeRate::fee_wu methods
1 parent 51c183a commit 033a48b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

bdk-ffi/src/bitcoin.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use bdk_wallet::bitcoin::Transaction as BdkTransaction;
2626
use bdk_wallet::bitcoin::TxIn as BdkTxIn;
2727
use bdk_wallet::bitcoin::TxOut as BdkTxOut;
2828
use bdk_wallet::bitcoin::Txid as BitcoinTxid;
29+
use bdk_wallet::bitcoin::Weight;
2930
use bdk_wallet::bitcoin::Wtxid as BitcoinWtxid;
3031
use bdk_wallet::miniscript::psbt::PsbtExt;
3132
use bdk_wallet::serde_json;
@@ -156,6 +157,22 @@ impl FeeRate {
156157
pub fn to_sat_per_kwu(&self) -> u64 {
157158
self.0.to_sat_per_kwu()
158159
}
160+
161+
/// Calculates fee in satoshis by multiplying this fee rate by weight, in virtual bytes, returning `None` if overflow occurred.
162+
///
163+
/// This is equivalent to converting vb to weight using Weight::from_vb and then calling Self::fee_wu(weight).
164+
pub fn fee_vb(&self, vb: u64) -> Option<u64> {
165+
self.0.fee_vb(vb).map(|amount| amount.to_sat())
166+
}
167+
168+
/// Calculates fee in satoshis by multiplying this fee rate by weight, in weight units, returning `None` if overflow occurred.
169+
//
170+
// This is equivalent to Self::checked_mul_by_weight().
171+
pub fn fee_wu(&self, wu: u64) -> Option<u64> {
172+
self.0
173+
.fee_wu(Weight::from_wu(wu))
174+
.map(|amount| amount.to_sat())
175+
}
159176
}
160177

161178
impl Display for FeeRate {

0 commit comments

Comments
 (0)