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 -}