Merge rust-bitcoin/rust-bitcoin#4537: Use / to divide fee by weight
7e67737393
Use / to divide fee by weight (Tobin C. Harding)
Pull request description:
Looks like this code was written before we added support for dividing `Amount` by `Weight`.
Refactor, no logic change.
ACKs for top commit:
apoelstra:
ACK 7e67737393bc1a966bf2ce544d291ea30dc4f0f7; successfully ran local tests; will one-ack merge on the basis that this is trivial
Tree-SHA512: e1c97bea4eaa07ef24e82844c07c899a9baca65d0d3d2dfe32371e7b3c81363ac5844b4fdce9dbe12d8c0131d03dfd4cc13fcc5cc8a0b595ade1c1b06c727c10
This commit is contained in:
commit
7ad0b234ba
|
@ -20,6 +20,7 @@ use std::collections::{HashMap, HashSet};
|
|||
|
||||
use internals::write_err;
|
||||
use secp256k1::{Keypair, Message, Secp256k1, Signing, Verification};
|
||||
use units::NumOpResult;
|
||||
|
||||
use crate::bip32::{self, DerivationPath, KeySource, Xpriv, Xpub};
|
||||
use crate::crypto::key::{PrivateKey, PublicKey};
|
||||
|
@ -209,11 +210,14 @@ impl Psbt {
|
|||
let tx = self.internal_extract_tx();
|
||||
|
||||
// Now that the extracted Transaction is made, decide how to return it.
|
||||
let fee_rate =
|
||||
FeeRate::from_sat_per_kwu(fee.to_sat().saturating_mul(1000) / tx.weight().to_wu());
|
||||
// Prefer to return an AbsurdFeeRate error when both trigger.
|
||||
if fee_rate > max_fee_rate {
|
||||
return Err(ExtractTxError::AbsurdFeeRate { fee_rate, tx });
|
||||
match fee / tx.weight() {
|
||||
NumOpResult::Valid(fee_rate) => {
|
||||
// Prefer to return an AbsurdFeeRate error when both trigger.
|
||||
if fee_rate > max_fee_rate {
|
||||
return Err(ExtractTxError::AbsurdFeeRate { fee_rate, tx });
|
||||
}
|
||||
}
|
||||
NumOpResult::Error(_) => unreachable!("weight() is always non-zero"),
|
||||
}
|
||||
|
||||
Ok(tx)
|
||||
|
|
Loading…
Reference in New Issue