@@ -231,18 +231,20 @@ impl Block {
231231 bitcoin_merkle_root ( hashes) . into ( )
232232 }
233233
234+ /// The size of the header + the size of the varint with the tx count + the txs themselves
235+ #[ inline]
236+ fn get_base_size ( & self ) -> usize {
237+ 80 + VarInt ( self . txdata . len ( ) as u64 ) . len ( )
238+ }
239+
234240 /// Get the size of the block
235241 pub fn get_size ( & self ) -> usize {
236- // The size of the header + the size of the varint with the tx count + the txs themselves
237- let base_size = 80 + VarInt ( self . txdata . len ( ) as u64 ) . len ( ) ;
238242 let txs_size: usize = self . txdata . iter ( ) . map ( Transaction :: get_size) . sum ( ) ;
239- base_size + txs_size
243+ self . get_base_size ( ) + txs_size
240244 }
241245
242246 /// Get the strippedsize of the block
243247 pub fn get_strippedsize ( & self ) -> usize {
244- // The size of the header + the size of the varint with the tx count + the txs themselves
245- let base_size = 80 + VarInt ( self . txdata . len ( ) as u64 ) . len ( ) ;
246248 let txs_size: usize = self . txdata . iter ( ) . map ( |tx| {
247249 // size = non_witness_size + witness_size.
248250 let size = tx. get_size ( ) ;
@@ -251,12 +253,12 @@ impl Block {
251253 // weight - size = (WITNESS_SCALE_FACTOR - 1) * non_witness_size.
252254 ( weight - size) / ( WITNESS_SCALE_FACTOR - 1 )
253255 } ) . sum ( ) ;
254- base_size + txs_size
256+ self . get_base_size ( ) + txs_size
255257 }
256258
257259 /// Get the weight of the block
258260 pub fn get_weight ( & self ) -> usize {
259- let base_weight = WITNESS_SCALE_FACTOR * ( 80 + VarInt ( self . txdata . len ( ) as u64 ) . len ( ) ) ;
261+ let base_weight = WITNESS_SCALE_FACTOR * self . get_base_size ( ) ;
260262 let txs_weight: usize = self . txdata . iter ( ) . map ( Transaction :: get_weight) . sum ( ) ;
261263 base_weight + txs_weight
262264 }
0 commit comments