Skip to content

Commit

Permalink
forgot to update my calcuate tx weight fn with the size of txs with a…
Browse files Browse the repository at this point in the history
… witness
  • Loading branch information
slanesuke committed Apr 28, 2024
1 parent 646d27a commit efc0d61
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mine-your-first-block/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,14 +451,16 @@ pub fn hash_meets_difficulty_target(hash: &str) -> bool {
hash_as_num < target
}

pub fn calculate_transaction_weight(tx: &Transaction) -> u64 {
pub fn calculate_transaction_weight(tx: &Transaction) -> u64 {
// Serialized tx size without witness
let base_size = serialize_tx(tx).len() as u64;
let total_size = base_size; // Need to update once i include more tx types

// 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 * 2 // Return the weight of the transaction
tx_weight // Return the weight of the transaction
}

0 comments on commit efc0d61

Please sign in to comment.