Merge rust-bitcoin/rust-bitcoin#4006: Rename fee_wu and remove fee_vb

a7526b6a70 Remove `fee_vb` (yancy)
73b14d03b9 Add `to_fee` in place of `fee_wu` (yancy)

Pull request description:

  Rename fee_wu and remove fee_vb

  closes https://github.com/rust-bitcoin/rust-bitcoin/issues/3908

ACKs for top commit:
  apoelstra:
    ACK a7526b6a70642e04f0a8ad8a89aa368031fdb6cd; successfully ran local tests
  Kixunil:
    ACK a7526b6a70

Tree-SHA512: fd865525e56caddc49158fd94fb125d92fd09654d5c72609a6f8e34370e79a9be4213dbd7e69b0d8498d92fca8a970142262f56b63cebd76c200aca75b6e0ca6
This commit is contained in:
merge-script 2025-02-05 20:15:08 +00:00
commit a380d4b9de
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
5 changed files with 15 additions and 36 deletions

View File

@ -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>

View File

@ -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>

View File

@ -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

View File

@ -22,30 +22,6 @@ pub use self::{
pub mod fee_rate {
/// Re-export everything from the [`units::fee_rate`] module.
pub use units::fee_rate::FeeRate;
#[cfg(test)]
mod tests {
use internals::ToU64 as _;
use super::*;
#[test]
fn fee_convenience_functions_agree() {
use hex::test_hex_unwrap as hex;
use crate::consensus::Decodable;
use crate::transaction::{Transaction, TransactionExt as _};
const SOME_TX: &str = "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000";
let raw_tx = hex!(SOME_TX);
let tx: Transaction = Decodable::consensus_decode(&mut raw_tx.as_slice()).unwrap();
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()));
}
}
}
/// Provides absolute and relative locktimes.

View File

@ -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`]
@ -126,8 +134,9 @@ impl FeeRate {
/// This is equivalent to converting `vb` to [`Weight`] using [`Weight::from_vb`] and then calling
/// `Self::fee_wu(weight)`.
#[must_use]
#[deprecated(since = "TBD", note = "use Weight::from_vb and then `to_fee()` instead")]
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,21 +227,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));
}
#[test]
fn fee_vb() {
let fee_overflow = FeeRate::from_sat_per_kwu(10).fee_vb(Weight::MAX.to_wu());
assert!(fee_overflow.is_none());
let fee_rate = FeeRate::from_sat_per_vb(2).unwrap();
assert_eq!(fee_rate.fee_vb(3).unwrap(), Amount::from_sat_unchecked(6));
assert_eq!(fee_rate.to_fee(weight).unwrap(), Amount::from_sat_unchecked(6));
}
#[test]