Merge rust-bitcoin/rust-bitcoin#3798: refactor: use amount type
774f066879
refactor: Change from u64 to Amount (yancy) Pull request description: Separate out refactor commit from https://github.com/rust-bitcoin/rust-bitcoin/pull/3794. Can be merged independently. ACKs for top commit: tcharding: ACK774f066879
apoelstra: ACK 774f066879c8ad1af81c7e46b404fa63682a0b4c; successfully ran local tests Tree-SHA512: 9ec5121d823ee3ec506eee5b5187bd496221bd3576afcaa6daf647099720d87b58b69521f29ae9537f123e2958771bc867b123da3f2ba941cba403a6c98e46de
This commit is contained in:
commit
2de44ab2a6
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue