Add `to_fee` in place of `fee_wu`
Use the more idiomatic to_fee instead of `fee_wu`. Since the method takes a strongly typed argument, remove `wu` from the method name to improve clarity.
This commit is contained in:
parent
422ea03ef7
commit
73b14d03b9
|
@ -1069,6 +1069,7 @@ pub fn bitcoin_units::fee_rate::FeeRate::sub_assign(&mut self, rhs: &bitcoin_uni
|
|||
pub fn bitcoin_units::fee_rate::FeeRate::sub_assign(&mut self, rhs: bitcoin_units::fee_rate::FeeRate)
|
||||
pub fn bitcoin_units::fee_rate::FeeRate::sum<I>(iter: I) -> Self where I: core::iter::traits::iterator::Iterator<Item = &'a bitcoin_units::fee_rate::FeeRate>
|
||||
pub fn bitcoin_units::fee_rate::FeeRate::sum<I>(iter: I) -> Self where I: core::iter::traits::iterator::Iterator<Item = Self>
|
||||
pub fn bitcoin_units::fee_rate::FeeRate::to_fee(self, weight: bitcoin_units::weight::Weight) -> core::option::Option<bitcoin_units::Amount>
|
||||
pub fn bitcoin_units::fee_rate::FeeRate::try_from(s: &str) -> core::result::Result<Self, Self::Error>
|
||||
pub fn bitcoin_units::fee_rate::FeeRate::try_from(s: alloc::boxed::Box<str>) -> core::result::Result<Self, Self::Error>
|
||||
pub fn bitcoin_units::fee_rate::FeeRate::try_from(s: alloc::string::String) -> core::result::Result<Self, Self::Error>
|
||||
|
|
|
@ -950,6 +950,7 @@ pub fn bitcoin_units::fee_rate::FeeRate::sub_assign(&mut self, rhs: &bitcoin_uni
|
|||
pub fn bitcoin_units::fee_rate::FeeRate::sub_assign(&mut self, rhs: bitcoin_units::fee_rate::FeeRate)
|
||||
pub fn bitcoin_units::fee_rate::FeeRate::sum<I>(iter: I) -> Self where I: core::iter::traits::iterator::Iterator<Item = &'a bitcoin_units::fee_rate::FeeRate>
|
||||
pub fn bitcoin_units::fee_rate::FeeRate::sum<I>(iter: I) -> Self where I: core::iter::traits::iterator::Iterator<Item = Self>
|
||||
pub fn bitcoin_units::fee_rate::FeeRate::to_fee(self, weight: bitcoin_units::weight::Weight) -> core::option::Option<bitcoin_units::Amount>
|
||||
pub fn bitcoin_units::fee_rate::FeeRate::try_from(s: &str) -> core::result::Result<Self, Self::Error>
|
||||
pub fn bitcoin_units::fee_rate::FeeRate::try_from(s: alloc::boxed::Box<str>) -> core::result::Result<Self, Self::Error>
|
||||
pub fn bitcoin_units::fee_rate::FeeRate::try_from(s: alloc::string::String) -> core::result::Result<Self, Self::Error>
|
||||
|
|
|
@ -916,6 +916,7 @@ pub fn bitcoin_units::fee_rate::FeeRate::sub_assign(&mut self, rhs: &bitcoin_uni
|
|||
pub fn bitcoin_units::fee_rate::FeeRate::sub_assign(&mut self, rhs: bitcoin_units::fee_rate::FeeRate)
|
||||
pub fn bitcoin_units::fee_rate::FeeRate::sum<I>(iter: I) -> Self where I: core::iter::traits::iterator::Iterator<Item = &'a bitcoin_units::fee_rate::FeeRate>
|
||||
pub fn bitcoin_units::fee_rate::FeeRate::sum<I>(iter: I) -> Self where I: core::iter::traits::iterator::Iterator<Item = Self>
|
||||
pub fn bitcoin_units::fee_rate::FeeRate::to_fee(self, weight: bitcoin_units::weight::Weight) -> core::option::Option<bitcoin_units::Amount>
|
||||
pub fn bitcoin_units::fee_rate::FeeRate::try_from(s: &str) -> core::result::Result<Self, Self::Error>
|
||||
pub fn bitcoin_units::locktime::absolute::ConversionError::clone(&self) -> bitcoin_units::locktime::absolute::ConversionError
|
||||
pub fn bitcoin_units::locktime::absolute::ConversionError::eq(&self, other: &bitcoin_units::locktime::absolute::ConversionError) -> bool
|
||||
|
|
|
@ -43,7 +43,7 @@ pub mod fee_rate {
|
|||
|
||||
let rate = FeeRate::from_sat_per_vb(1).expect("1 sat/byte is valid");
|
||||
|
||||
assert_eq!(rate.fee_vb(tx.vsize().to_u64()), rate.fee_wu(tx.weight()));
|
||||
assert_eq!(rate.fee_vb(tx.vsize().to_u64()), rate.to_fee(tx.weight()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,6 +118,14 @@ impl FeeRate {
|
|||
///
|
||||
/// This is equivalent to `Self::checked_mul_by_weight()`.
|
||||
#[must_use]
|
||||
pub fn to_fee(self, weight: Weight) -> Option<Amount> { self.checked_mul_by_weight(weight) }
|
||||
|
||||
/// Calculates the fee by multiplying this fee rate by weight, in weight units, returning [`None`]
|
||||
/// if an overflow occurred.
|
||||
///
|
||||
/// This is equivalent to `Self::checked_mul_by_weight()`.
|
||||
#[must_use]
|
||||
#[deprecated(since = "TBD", note = "use `to_fee()` instead")]
|
||||
pub fn fee_wu(self, weight: Weight) -> Option<Amount> { self.checked_mul_by_weight(weight) }
|
||||
|
||||
/// Calculates the fee by multiplying this fee rate by weight, in virtual bytes, returning [`None`]
|
||||
|
@ -127,7 +135,7 @@ impl FeeRate {
|
|||
/// `Self::fee_wu(weight)`.
|
||||
#[must_use]
|
||||
pub fn fee_vb(self, vb: u64) -> Option<Amount> {
|
||||
Weight::from_vb(vb).and_then(|w| self.fee_wu(w))
|
||||
Weight::from_vb(vb).and_then(|w| self.to_fee(w))
|
||||
}
|
||||
|
||||
/// Checked weight multiplication.
|
||||
|
@ -218,12 +226,12 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn fee_wu() {
|
||||
let fee_overflow = FeeRate::from_sat_per_kwu(10).fee_wu(Weight::MAX);
|
||||
let fee_overflow = FeeRate::from_sat_per_kwu(10).to_fee(Weight::MAX);
|
||||
assert!(fee_overflow.is_none());
|
||||
|
||||
let fee_rate = FeeRate::from_sat_per_vb(2).unwrap();
|
||||
let weight = Weight::from_vb(3).unwrap();
|
||||
assert_eq!(fee_rate.fee_wu(weight).unwrap(), Amount::from_sat_unchecked(6));
|
||||
assert_eq!(fee_rate.to_fee(weight).unwrap(), Amount::from_sat_unchecked(6));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue