refactor: Change from u64 to Amount

The Amount type provides better type safety and is more appropriate in
this context than u64.  Currently the checked arithmetic operations for
Amount and u64 are identical in behavior.  Therefore, this refactor does
not result in any behavior change and is purely cosmetic.
This commit is contained in:
yancy 2024-12-21 10:20:11 -06:00
parent 9cb302e477
commit 774f066879
1 changed files with 5 additions and 5 deletions

View File

@ -712,15 +712,15 @@ impl Psbt {
/// - [`Error::NegativeFee`] if calculated value is negative.
/// - [`Error::FeeOverflow`] if an integer overflow occurs.
pub fn fee(&self) -> Result<Amount, Error> {
let mut inputs: u64 = 0;
let mut inputs = Amount::ZERO;
for utxo in self.iter_funding_utxos() {
inputs = inputs.checked_add(utxo?.value.to_sat()).ok_or(Error::FeeOverflow)?;
inputs = inputs.checked_add(utxo?.value).ok_or(Error::FeeOverflow)?;
}
let mut outputs: u64 = 0;
let mut outputs = Amount::ZERO;
for out in &self.unsigned_tx.output {
outputs = outputs.checked_add(out.value.to_sat()).ok_or(Error::FeeOverflow)?;
outputs = outputs.checked_add(out.value).ok_or(Error::FeeOverflow)?;
}
inputs.checked_sub(outputs).map(Amount::from_sat).ok_or(Error::NegativeFee)
inputs.checked_sub(outputs).ok_or(Error::NegativeFee)
}
}