Skip to content

Commit 0cd384d

Browse files
committed
Update segwit_weight and legacy_weight to use non-deprecated functions
1 parent a11c037 commit 0cd384d

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

bitcoin/src/blockdata/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ mod tests {
659659
assert_eq!(block_base_size(real_decode.transactions()), some_block.len());
660660
assert_eq!(
661661
real_decode.weight(),
662-
Weight::from_non_witness_data_size(some_block.len().to_u64())
662+
Weight::from_vb_unchecked(some_block.len().to_u64())
663663
);
664664

665665
assert_eq!(serialize(&real_decode), some_block);

bitcoin/src/blockdata/transaction.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ internal_macros::define_extension_trait! {
139139
///
140140
/// If the coversion overflows.
141141
fn legacy_weight(&self) -> Weight {
142-
Weight::from_non_witness_data_size(self.base_size().to_u64())
142+
Weight::from_vb(self.base_size().to_u64()).unwrap()
143143
}
144144

145145
/// The weight of the TxIn when it's included in a SegWit transaction (i.e., a transaction
@@ -158,8 +158,8 @@ internal_macros::define_extension_trait! {
158158
///
159159
/// If the coversion overflows.
160160
fn segwit_weight(&self) -> Weight {
161-
Weight::from_non_witness_data_size(self.base_size().to_u64())
162-
+ Weight::from_witness_data_size(self.witness.size().to_u64())
161+
Weight::from_vb(self.base_size().to_u64())
162+
.and_then(|w| w.checked_add(Weight::from_wu(self.witness.size().to_u64()))).unwrap()
163163
}
164164

165165
/// Returns the base size of this input.

units/src/weight.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,15 @@ impl Weight {
9696
}
9797

9898
/// Constructs a new [`Weight`] from witness size.
99+
#[deprecated(since = "TBD", note = "use `from_wu` instead")]
99100
pub const fn from_witness_data_size(witness_size: u64) -> Self { Weight::from_wu(witness_size) }
100101

101102
/// Constructs a new [`Weight`] from non-witness size.
102103
///
103104
/// # Panics
104105
///
105106
/// If the conversion from virtual bytes overflows.
107+
#[deprecated(since = "TBD", note = "use `from_vb` or `from_vb_unchecked` instead")]
106108
pub const fn from_non_witness_data_size(non_witness_size: u64) -> Self {
107109
Weight::from_wu(non_witness_size * Self::WITNESS_SCALE_FACTOR)
108110
}
@@ -366,6 +368,8 @@ mod tests {
366368
fn from_vb_unchecked_panic() { Weight::from_vb_unchecked(u64::MAX); }
367369

368370
#[test]
371+
#[allow(deprecated)] // tests the deprecated function
372+
#[allow(deprecated_in_future)]
369373
fn from_witness_data_size() {
370374
let witness_data_size = 1;
371375
let got = Weight::from_witness_data_size(witness_data_size);
@@ -374,6 +378,8 @@ mod tests {
374378
}
375379

376380
#[test]
381+
#[allow(deprecated)] // tests the deprecated function
382+
#[allow(deprecated_in_future)]
377383
fn from_non_witness_data_size() {
378384
let non_witness_data_size = 1;
379385
let got = Weight::from_non_witness_data_size(non_witness_data_size);

0 commit comments

Comments
 (0)