Rename strippedsize to stripped_size
This commit is contained in:
parent
3369257c75
commit
1a88c887f5
|
@ -287,8 +287,15 @@ impl Block {
|
|||
}
|
||||
|
||||
/// Returns the stripped size of the block.
|
||||
pub fn strippedsize(&self) -> usize {
|
||||
let txs_size: usize = self.txdata.iter().map(Transaction::strippedsize).sum();
|
||||
#[deprecated(
|
||||
since = "0.31.0",
|
||||
note = "Truncates on 32-bit machines, Use Block::stripped_size() instead"
|
||||
)]
|
||||
pub fn strippedsize(&self) -> usize { Self::stripped_size(self) }
|
||||
|
||||
/// Returns the stripped size of the block.
|
||||
pub fn stripped_size(&self) -> usize {
|
||||
let txs_size: usize = self.txdata.iter().map(Transaction::stripped_size).sum();
|
||||
self.base_size() + txs_size
|
||||
}
|
||||
|
||||
|
@ -481,7 +488,7 @@ mod tests {
|
|||
// [test] TODO: check the transaction data
|
||||
|
||||
assert_eq!(real_decode.size(), some_block.len());
|
||||
assert_eq!(real_decode.strippedsize(), some_block.len());
|
||||
assert_eq!(real_decode.stripped_size(), some_block.len());
|
||||
assert_eq!(
|
||||
real_decode.weight(),
|
||||
Weight::from_non_witness_data_size(some_block.len() as u64)
|
||||
|
@ -523,7 +530,7 @@ mod tests {
|
|||
// [test] TODO: check the transaction data
|
||||
|
||||
assert_eq!(real_decode.size(), segwit_block.len());
|
||||
assert_eq!(real_decode.strippedsize(), 4283);
|
||||
assert_eq!(real_decode.stripped_size(), 4283);
|
||||
assert_eq!(real_decode.weight(), Weight::from_wu(17168));
|
||||
|
||||
assert!(real_decode.check_witness_commitment());
|
||||
|
|
|
@ -713,7 +713,11 @@ impl Transaction {
|
|||
}
|
||||
|
||||
/// Returns the size of this transaction excluding the witness data.
|
||||
pub fn strippedsize(&self) -> usize {
|
||||
#[deprecated(since = "0.31.0", note = "Use Transaction::stripped_size() instead")]
|
||||
pub fn strippedsize(&self) -> usize { Self::stripped_size(self) }
|
||||
|
||||
/// Returns the size of this transaction excluding the witness data.
|
||||
pub fn stripped_size(&self) -> usize {
|
||||
let mut input_size = 0;
|
||||
for input in &self.input {
|
||||
input_size += TxIn::BASE_WEIGHT.to_wu() as usize
|
||||
|
@ -1394,7 +1398,7 @@ mod tests {
|
|||
assert_eq!(realtx.weight().to_wu() as usize, tx_bytes.len() * WITNESS_SCALE_FACTOR);
|
||||
assert_eq!(realtx.size(), tx_bytes.len());
|
||||
assert_eq!(realtx.vsize(), tx_bytes.len());
|
||||
assert_eq!(realtx.strippedsize(), tx_bytes.len());
|
||||
assert_eq!(realtx.stripped_size(), tx_bytes.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1442,7 +1446,7 @@ mod tests {
|
|||
// stripped_size = (weight - size) / (WITNESS_SCALE_FACTOR - 1)
|
||||
let expected_strippedsize =
|
||||
(EXPECTED_WEIGHT.to_wu() as usize - tx_bytes.len()) / (WITNESS_SCALE_FACTOR - 1);
|
||||
assert_eq!(realtx.strippedsize(), expected_strippedsize);
|
||||
assert_eq!(realtx.stripped_size(), expected_strippedsize);
|
||||
// Construct a transaction without the witness data.
|
||||
let mut tx_without_witness = realtx;
|
||||
tx_without_witness.input.iter_mut().for_each(|input| input.witness.clear());
|
||||
|
@ -1452,7 +1456,7 @@ mod tests {
|
|||
);
|
||||
assert_eq!(tx_without_witness.size(), expected_strippedsize);
|
||||
assert_eq!(tx_without_witness.vsize(), expected_strippedsize);
|
||||
assert_eq!(tx_without_witness.strippedsize(), expected_strippedsize);
|
||||
assert_eq!(tx_without_witness.stripped_size(), expected_strippedsize);
|
||||
}
|
||||
|
||||
// We temporarily abuse `Transaction` for testing consensus serde adapter.
|
||||
|
|
Loading…
Reference in New Issue