Skip to content

Commit 3dc5dc8

Browse files
committed
Merge rust-bitcoin#5117: Add documentation for Witness::size panic
c3e1bdc Add documentation for panics during size calculations (Shing Him Ng) Pull request description: Found while working on rust-bitcoin#5114 ACKs for top commit: apoelstra: ACK c3e1bdc; successfully ran local tests Tree-SHA512: 3dbc4f42446146e9c5a4bd00bf39df1eab986df6e2fd5c7f8d86812fe833f2fbd5d2e2f76bb5839ad837807f57ec148840b46feb6f4a0e8aee2e2803d96ee181
2 parents d819f08 + c3e1bdc commit 3dc5dc8

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

bitcoin/src/blockdata/block.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ pub trait BlockCheckedExt: sealed::Sealed {
273273
///
274274
/// > Total size is the block size in bytes with transactions serialized as described in BIP-0144,
275275
/// > including base data and witness data.
276+
///
277+
/// # Panics
278+
///
279+
/// If the size calculation overflows.
276280
fn total_size(&self) -> usize;
277281

278282
/// Returns the coinbase transaction.
@@ -304,6 +308,9 @@ impl BlockCheckedExt for Block<Checked> {
304308
Weight::from_wu(wu.to_u64())
305309
}
306310

311+
/// # Panics
312+
///
313+
/// If the size calculation overflows.
307314
fn total_size(&self) -> usize {
308315
let mut size = Header::SIZE;
309316

bitcoin/src/blockdata/transaction.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,20 @@ pub trait TransactionExt: sealed::Sealed {
286286
/// Returns the base transaction size.
287287
///
288288
/// > Base transaction size is the size of the transaction serialised with the witness data stripped.
289+
///
290+
/// # Panics
291+
///
292+
/// If the size calculation overflows.
289293
fn base_size(&self) -> usize;
290294

291295
/// Returns the total transaction size.
292296
///
293297
/// > Total transaction size is the transaction size in bytes serialized as described in BIP-0144,
294298
/// > including base data and witness data.
299+
///
300+
/// # Panics
301+
///
302+
/// If the size calculation overflows.
295303
fn total_size(&self) -> usize;
296304

297305
/// Returns the "virtual size" (vsize) of this transaction.
@@ -385,6 +393,9 @@ impl TransactionExt for Transaction {
385393
Weight::from_wu(wu.to_u64())
386394
}
387395

396+
/// # Panics
397+
///
398+
/// If the size calculation overflows.
388399
fn base_size(&self) -> usize {
389400
let mut size: usize = 4; // Serialized length of a u32 for the version number.
390401

@@ -397,6 +408,9 @@ impl TransactionExt for Transaction {
397408
size + absolute::LockTime::SIZE
398409
}
399410

411+
/// # Panics
412+
///
413+
/// If the size calculation overflows.
400414
#[inline]
401415
fn total_size(&self) -> usize {
402416
let mut size: usize = 4; // Serialized length of a u32 for the version number.

primitives/src/witness.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ impl Witness {
131131
pub fn len(&self) -> usize { self.witness_elements }
132132

133133
/// Returns the number of bytes this witness contributes to a transactions total size.
134+
///
135+
/// # Panics
136+
///
137+
/// If the size calculation overflows.
134138
pub fn size(&self) -> usize {
135139
let mut size: usize = 0;
136140

0 commit comments

Comments
 (0)