Skip to content

Commit a380d4b

Browse files
committed
Merge rust-bitcoin#4006: Rename fee_wu and remove fee_vb
a7526b6 Remove `fee_vb` (yancy) 73b14d0 Add `to_fee` in place of `fee_wu` (yancy) Pull request description: Rename fee_wu and remove fee_vb closes rust-bitcoin#3908 ACKs for top commit: apoelstra: ACK a7526b6; successfully ran local tests Kixunil: ACK a7526b6 Tree-SHA512: fd865525e56caddc49158fd94fb125d92fd09654d5c72609a6f8e34370e79a9be4213dbd7e69b0d8498d92fca8a970142262f56b63cebd76c200aca75b6e0ca6
2 parents 5fef0dd + a7526b6 commit a380d4b

File tree

5 files changed

+15
-36
lines changed

5 files changed

+15
-36
lines changed

api/units/all-features.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,7 @@ pub fn bitcoin_units::fee_rate::FeeRate::sub_assign(&mut self, rhs: &bitcoin_uni
10691069
pub fn bitcoin_units::fee_rate::FeeRate::sub_assign(&mut self, rhs: bitcoin_units::fee_rate::FeeRate)
10701070
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>
10711071
pub fn bitcoin_units::fee_rate::FeeRate::sum<I>(iter: I) -> Self where I: core::iter::traits::iterator::Iterator<Item = Self>
1072+
pub fn bitcoin_units::fee_rate::FeeRate::to_fee(self, weight: bitcoin_units::weight::Weight) -> core::option::Option<bitcoin_units::Amount>
10721073
pub fn bitcoin_units::fee_rate::FeeRate::try_from(s: &str) -> core::result::Result<Self, Self::Error>
10731074
pub fn bitcoin_units::fee_rate::FeeRate::try_from(s: alloc::boxed::Box<str>) -> core::result::Result<Self, Self::Error>
10741075
pub fn bitcoin_units::fee_rate::FeeRate::try_from(s: alloc::string::String) -> core::result::Result<Self, Self::Error>

api/units/alloc-only.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,7 @@ pub fn bitcoin_units::fee_rate::FeeRate::sub_assign(&mut self, rhs: &bitcoin_uni
950950
pub fn bitcoin_units::fee_rate::FeeRate::sub_assign(&mut self, rhs: bitcoin_units::fee_rate::FeeRate)
951951
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>
952952
pub fn bitcoin_units::fee_rate::FeeRate::sum<I>(iter: I) -> Self where I: core::iter::traits::iterator::Iterator<Item = Self>
953+
pub fn bitcoin_units::fee_rate::FeeRate::to_fee(self, weight: bitcoin_units::weight::Weight) -> core::option::Option<bitcoin_units::Amount>
953954
pub fn bitcoin_units::fee_rate::FeeRate::try_from(s: &str) -> core::result::Result<Self, Self::Error>
954955
pub fn bitcoin_units::fee_rate::FeeRate::try_from(s: alloc::boxed::Box<str>) -> core::result::Result<Self, Self::Error>
955956
pub fn bitcoin_units::fee_rate::FeeRate::try_from(s: alloc::string::String) -> core::result::Result<Self, Self::Error>

api/units/no-features.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,7 @@ pub fn bitcoin_units::fee_rate::FeeRate::sub_assign(&mut self, rhs: &bitcoin_uni
916916
pub fn bitcoin_units::fee_rate::FeeRate::sub_assign(&mut self, rhs: bitcoin_units::fee_rate::FeeRate)
917917
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>
918918
pub fn bitcoin_units::fee_rate::FeeRate::sum<I>(iter: I) -> Self where I: core::iter::traits::iterator::Iterator<Item = Self>
919+
pub fn bitcoin_units::fee_rate::FeeRate::to_fee(self, weight: bitcoin_units::weight::Weight) -> core::option::Option<bitcoin_units::Amount>
919920
pub fn bitcoin_units::fee_rate::FeeRate::try_from(s: &str) -> core::result::Result<Self, Self::Error>
920921
pub fn bitcoin_units::locktime::absolute::ConversionError::clone(&self) -> bitcoin_units::locktime::absolute::ConversionError
921922
pub fn bitcoin_units::locktime::absolute::ConversionError::eq(&self, other: &bitcoin_units::locktime::absolute::ConversionError) -> bool

bitcoin/src/blockdata/mod.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,6 @@ pub use self::{
2222
pub mod fee_rate {
2323
/// Re-export everything from the [`units::fee_rate`] module.
2424
pub use units::fee_rate::FeeRate;
25-
26-
#[cfg(test)]
27-
mod tests {
28-
use internals::ToU64 as _;
29-
30-
use super::*;
31-
32-
#[test]
33-
fn fee_convenience_functions_agree() {
34-
use hex::test_hex_unwrap as hex;
35-
36-
use crate::consensus::Decodable;
37-
use crate::transaction::{Transaction, TransactionExt as _};
38-
39-
const SOME_TX: &str = "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000";
40-
41-
let raw_tx = hex!(SOME_TX);
42-
let tx: Transaction = Decodable::consensus_decode(&mut raw_tx.as_slice()).unwrap();
43-
44-
let rate = FeeRate::from_sat_per_vb(1).expect("1 sat/byte is valid");
45-
46-
assert_eq!(rate.fee_vb(tx.vsize().to_u64()), rate.fee_wu(tx.weight()));
47-
}
48-
}
4925
}
5026

5127
/// Provides absolute and relative locktimes.

units/src/fee.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ impl FeeRate {
118118
///
119119
/// This is equivalent to `Self::checked_mul_by_weight()`.
120120
#[must_use]
121+
pub fn to_fee(self, weight: Weight) -> Option<Amount> { self.checked_mul_by_weight(weight) }
122+
123+
/// Calculates the fee by multiplying this fee rate by weight, in weight units, returning [`None`]
124+
/// if an overflow occurred.
125+
///
126+
/// This is equivalent to `Self::checked_mul_by_weight()`.
127+
#[must_use]
128+
#[deprecated(since = "TBD", note = "use `to_fee()` instead")]
121129
pub fn fee_wu(self, weight: Weight) -> Option<Amount> { self.checked_mul_by_weight(weight) }
122130

123131
/// Calculates the fee by multiplying this fee rate by weight, in virtual bytes, returning [`None`]
@@ -126,8 +134,9 @@ impl FeeRate {
126134
/// This is equivalent to converting `vb` to [`Weight`] using [`Weight::from_vb`] and then calling
127135
/// `Self::fee_wu(weight)`.
128136
#[must_use]
137+
#[deprecated(since = "TBD", note = "use Weight::from_vb and then `to_fee()` instead")]
129138
pub fn fee_vb(self, vb: u64) -> Option<Amount> {
130-
Weight::from_vb(vb).and_then(|w| self.fee_wu(w))
139+
Weight::from_vb(vb).and_then(|w| self.to_fee(w))
131140
}
132141

133142
/// Checked weight multiplication.
@@ -218,21 +227,12 @@ mod tests {
218227

219228
#[test]
220229
fn fee_wu() {
221-
let fee_overflow = FeeRate::from_sat_per_kwu(10).fee_wu(Weight::MAX);
230+
let fee_overflow = FeeRate::from_sat_per_kwu(10).to_fee(Weight::MAX);
222231
assert!(fee_overflow.is_none());
223232

224233
let fee_rate = FeeRate::from_sat_per_vb(2).unwrap();
225234
let weight = Weight::from_vb(3).unwrap();
226-
assert_eq!(fee_rate.fee_wu(weight).unwrap(), Amount::from_sat_unchecked(6));
227-
}
228-
229-
#[test]
230-
fn fee_vb() {
231-
let fee_overflow = FeeRate::from_sat_per_kwu(10).fee_vb(Weight::MAX.to_wu());
232-
assert!(fee_overflow.is_none());
233-
234-
let fee_rate = FeeRate::from_sat_per_vb(2).unwrap();
235-
assert_eq!(fee_rate.fee_vb(3).unwrap(), Amount::from_sat_unchecked(6));
235+
assert_eq!(fee_rate.to_fee(weight).unwrap(), Amount::from_sat_unchecked(6));
236236
}
237237

238238
#[test]

0 commit comments

Comments
 (0)