From 774f066879c8ad1af81c7e46b404fa63682a0b4c Mon Sep 17 00:00:00 2001 From: yancy Date: Sat, 21 Dec 2024 10:20:11 -0600 Subject: [PATCH] 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. --- bitcoin/src/psbt/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bitcoin/src/psbt/mod.rs b/bitcoin/src/psbt/mod.rs index 071b5afa3..098e853e2 100644 --- a/bitcoin/src/psbt/mod.rs +++ b/bitcoin/src/psbt/mod.rs @@ -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 { - 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) } }