Skip to content

Commit

Permalink
I moved the clacute transaction weight fn to the utils.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
slanesuke committed Apr 28, 2024
1 parent 00da94f commit afce257
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
13 changes: 13 additions & 0 deletions mine-your-first-block/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,3 +567,16 @@ pub fn reverse_bytes(mut bytes: Vec<u8>) -> 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
}
12 changes: 0 additions & 12 deletions mine-your-first-block/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit afce257

Please sign in to comment.