Use / to divide fee by weight
Looks like this code was written before we added support for dividing `Amount` by `Weight`. Refactor, no logic change.
This commit is contained in:
parent
855299ab7e
commit
7e67737393
|
@ -20,6 +20,7 @@ use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
use internals::write_err;
|
use internals::write_err;
|
||||||
use secp256k1::{Keypair, Message, Secp256k1, Signing, Verification};
|
use secp256k1::{Keypair, Message, Secp256k1, Signing, Verification};
|
||||||
|
use units::NumOpResult;
|
||||||
|
|
||||||
use crate::bip32::{self, DerivationPath, KeySource, Xpriv, Xpub};
|
use crate::bip32::{self, DerivationPath, KeySource, Xpriv, Xpub};
|
||||||
use crate::crypto::key::{PrivateKey, PublicKey};
|
use crate::crypto::key::{PrivateKey, PublicKey};
|
||||||
|
@ -209,12 +210,15 @@ impl Psbt {
|
||||||
let tx = self.internal_extract_tx();
|
let tx = self.internal_extract_tx();
|
||||||
|
|
||||||
// Now that the extracted Transaction is made, decide how to return it.
|
// Now that the extracted Transaction is made, decide how to return it.
|
||||||
let fee_rate =
|
match fee / tx.weight() {
|
||||||
FeeRate::from_sat_per_kwu(fee.to_sat().saturating_mul(1000) / tx.weight().to_wu());
|
NumOpResult::Valid(fee_rate) => {
|
||||||
// Prefer to return an AbsurdFeeRate error when both trigger.
|
// Prefer to return an AbsurdFeeRate error when both trigger.
|
||||||
if fee_rate > max_fee_rate {
|
if fee_rate > max_fee_rate {
|
||||||
return Err(ExtractTxError::AbsurdFeeRate { fee_rate, tx });
|
return Err(ExtractTxError::AbsurdFeeRate { fee_rate, tx });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
NumOpResult::Error(_) => unreachable!("weight() is always non-zero"),
|
||||||
|
}
|
||||||
|
|
||||||
Ok(tx)
|
Ok(tx)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue