Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
slanesuke committed Apr 21, 2024
1 parent a3d5bce commit edfef57
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions mine-your-first-block/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1378,15 +1378,26 @@ fn main() {
block_txs.sort_by(|a, b| b.fee.cmp(&a.fee));

// Get the wtxids for the witness root
let mut txids_for_merkle = vec![];
let mut wtx_ids_for_witness_root = vec!["0000000000000000000000000000000000000000000000000000000000000000".to_string()];
// for tx in &block_txs {
// if tx.is_p2wpkh {
// if let Some(ref wtxid) = tx.wtxid {
// wtx_ids_for_witness_root.push(wtxid.clone()); // Collect wtxid if valid
// }
// }
// }
for tx in &block_txs {
txids_for_merkle.push(tx.txid.clone()); // Use txid for Merkle root
if tx.is_p2wpkh {
if let Some(ref wtxid) = tx.wtxid {
wtx_ids_for_witness_root.push(wtxid.clone()); // Collect wtxid if valid
}
}
}



// Calculate the witness root
let witness_root = get_merkle_root(wtx_ids_for_witness_root);

Expand All @@ -1403,12 +1414,13 @@ fn main() {
let coinbase_txid = hex::encode(coinbase_txid_le);

// Get the txids for the merkle root
let mut txids_for_merkle = vec![coinbase_txid];
//let mut txids_for_merkle = vec![coinbase_txid];


for tx in &block_txs {
txids_for_merkle.push(tx.txid.clone()); // Use txid for Merkle root
}
// for tx in &block_txs {
// txids_for_merkle.push(tx.txid.clone()); // Use txid for Merkle root
// }
txids_for_merkle.insert(0, coinbase_txid.clone());
// Calculate the merkle root
let merkle_root = get_merkle_root(txids_for_merkle.clone());
println!("Merkle Root: {}", merkle_root);
Expand Down

0 comments on commit edfef57

Please sign in to comment.