Skip to content

Commit 6de9121

Browse files
committed
refactor: use fee calc from rust-bitcoin
Simplify code base by using an upstream method instead of creating a local method that does the same thing.
1 parent ee229bf commit 6de9121

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

src/lib.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,13 @@ pub trait WeightedUtxo {
6161
effective_value(fee_rate, self.weight(), self.value())
6262
}
6363

64-
/// Computes the fee to spend this `Utxo`.
65-
///
66-
/// The fee is calculated as: fee rate * (satisfaction_weight + the base weight).
67-
fn calculate_fee(&self, fee_rate: FeeRate) -> Option<Amount> {
68-
fee_rate.checked_mul_by_weight(self.weight())
69-
}
70-
7164
/// Computes how wastefull it is to spend this `Utxo`
7265
///
7366
/// The waste is the difference of the fee to spend this `Utxo` now compared with the expected
7467
/// fee to spend in the future (long_term_fee_rate).
7568
fn waste(&self, fee_rate: FeeRate, long_term_fee_rate: FeeRate) -> Option<SignedAmount> {
76-
let fee: SignedAmount = self.calculate_fee(fee_rate)?.to_signed().ok()?;
77-
let lt_fee: SignedAmount = self.calculate_fee(long_term_fee_rate)?.to_signed().ok()?;
69+
let fee: SignedAmount = fee_rate.fee_wu(self.weight())?.to_signed().ok()?;
70+
let lt_fee: SignedAmount = long_term_fee_rate.fee_wu(self.weight())?.to_signed().ok()?;
7871
fee.checked_sub(lt_fee)
7972
}
8073
}

0 commit comments

Comments
 (0)