From dc0e5dff34a4fb7bc3a43a6648d8c78dc24b273a Mon Sep 17 00:00:00 2001 From: yancy Date: Wed, 24 Jan 2024 12:45:27 +0100 Subject: [PATCH] wip --- src/lib.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 0a9445f..e3dac71 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,7 +55,18 @@ pub struct WeightedUtxo { impl WeightedUtxo { fn effective_value(&self, fee_rate: FeeRate) -> Option { - effective_value(fee_rate, self.satisfaction_weight, self.utxo.value) + let signed_input_fee = self.calculate_fee(fee_rate)?.to_signed().ok()?; + self.utxo.value.to_signed().ok()?.checked_sub(signed_input_fee) + } + + fn calculate_fee(&self, fee_rate: FeeRate) -> Option { + // TODO TxIn::BASE_WEIGHT + let weight = self.satisfaction_weight.checked_add(Weight::ZERO)?; + fee_rate.checked_mul_by_weight(weight) + } + + fn is_wasteful(&self, fee_rate: FeeRate, long_term_fee_rate: FeeRate) -> bool { + self.calculate_fee(fee_rate) > self.calculate_fee(long_term_fee_rate) } }