From afce25701126048d89ee851180c46223b8d52a30 Mon Sep 17 00:00:00 2001 From: Ian Slane Date: Sun, 28 Apr 2024 15:52:28 -0600 Subject: [PATCH] I moved the clacute transaction weight fn to the utils.rs --- mine-your-first-block/src/utils.rs | 13 +++++++++++++ mine-your-first-block/src/validation.rs | 12 ------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/mine-your-first-block/src/utils.rs b/mine-your-first-block/src/utils.rs index ce293f2..e4332b7 100644 --- a/mine-your-first-block/src/utils.rs +++ b/mine-your-first-block/src/utils.rs @@ -567,3 +567,16 @@ pub fn reverse_bytes(mut bytes: Vec) -> String { bytes.reverse(); hex::encode(bytes) } + +pub fn calculate_transaction_weight(tx: &Transaction) -> u64 { + // Serialized tx size without witness + let base_size = serialize_tx(tx).len() as u64; + + // Serialized tx size with witness + let total_size = serialized_segwit_tx(tx).len() as u64; + + // Calculate weight of the transaction + let tx_weight = base_size * 3 + total_size; + + tx_weight // Return the weight of the transaction +} diff --git a/mine-your-first-block/src/validation.rs b/mine-your-first-block/src/validation.rs index 0d6fbd0..1415d87 100644 --- a/mine-your-first-block/src/validation.rs +++ b/mine-your-first-block/src/validation.rs @@ -429,16 +429,4 @@ pub fn hash_meets_difficulty_target(hash: &str) -> bool { hash_as_num < target } -pub fn calculate_transaction_weight(tx: &Transaction) -> u64 { - // Serialized tx size without witness - let base_size = serialize_tx(tx).len() as u64; - - // Serialized tx size with witness - let total_size = serialized_segwit_tx(tx).len() as u64; - - // Calculate weight of the transaction - let tx_weight = base_size * 3 + total_size; - - tx_weight // Return the weight of the transaction -}