feat: use Amount on calculate_fee, fee_absolute, fee_amount and others

- update to use `bitcoin::Amount` on `CreateTxError::FeeTooLow` variant.
- update to use `bitcoin::Amount` on `Wallet::calculate_fee()`.
- update to use `bitcoin::Amount` on `FeePolicy::fee_absolute()`.
- update to use `bitcoin::SignedAmount` on
  `CalculateFeeError::NegativeFee` variant.
- update to use `bitcoin::Amount` on `TxGraph::calculate_fee()`.
- update to use `bitcoin::Amount` on `PsbUtils::fee_amount()`
This commit is contained in:
Leonardo Lima
2024-05-05 17:41:31 -03:00
parent 4a8452f9b8
commit a03949adb0
10 changed files with 113 additions and 118 deletions

View File

@@ -10,8 +10,8 @@ use bdk_chain::{
Anchor, Append, BlockId, ChainOracle, ChainPosition, ConfirmationHeightAnchor,
};
use bitcoin::{
absolute, hashes::Hash, transaction, Amount, BlockHash, OutPoint, ScriptBuf, Transaction, TxIn,
TxOut, Txid,
absolute, hashes::Hash, transaction, Amount, BlockHash, OutPoint, ScriptBuf, SignedAmount,
Transaction, TxIn, TxOut, Txid,
};
use common::*;
use core::iter;
@@ -466,14 +466,14 @@ fn test_calculate_fee() {
}],
};
assert_eq!(graph.calculate_fee(&tx), Ok(100));
assert_eq!(graph.calculate_fee(&tx), Ok(Amount::from_sat(100)));
tx.input.remove(2);
// fee would be negative, should return CalculateFeeError::NegativeFee
assert_eq!(
graph.calculate_fee(&tx),
Err(CalculateFeeError::NegativeFee(-200))
Err(CalculateFeeError::NegativeFee(SignedAmount::from_sat(-200)))
);
// If we have an unknown outpoint, fee should return CalculateFeeError::MissingTxOut.
@@ -505,7 +505,7 @@ fn test_calculate_fee_on_coinbase() {
let graph = TxGraph::<()>::default();
assert_eq!(graph.calculate_fee(&tx), Ok(0));
assert_eq!(graph.calculate_fee(&tx), Ok(Amount::ZERO));
}
// `test_walk_ancestors` uses the following transaction structure: