From fe805cd8fe1b034a55691cce5181a5637f7e9dfa Mon Sep 17 00:00:00 2001 From: Ian Slane Date: Sat, 20 Apr 2024 21:06:29 -0600 Subject: [PATCH] testing --- mine-your-first-block/src/main.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/mine-your-first-block/src/main.rs b/mine-your-first-block/src/main.rs index 8c2ede1..6f86d19 100644 --- a/mine-your-first-block/src/main.rs +++ b/mine-your-first-block/src/main.rs @@ -1426,8 +1426,8 @@ fn main() { // Check if the hash meets the target if hash_meets_difficulty_target(&block_hash) { - //write_block_to_file(&serialized_block_header, &cd_tx_bytes, &block_txs); - write_block_to_file(&serialized_block_header, &cd_tx_bytes, txids_for_merkle.clone(), &block_txs); + write_block_to_file(&serialized_block_header, &cd_tx_bytes, &block_txs); + //write_block_to_file(&serialized_block_header, &cd_tx_bytes, txids_for_merkle.clone(), &block_txs); println!("Success, the block met the target difficulty!"); break; } else { @@ -1450,23 +1450,17 @@ fn main() { // append_to_file("../output.txt", &txids).unwrap(); // } // } - -fn write_block_to_file(serialized_header: &[u8], serialized_cb_tx: &[u8], txs: Vec, block_txs: &[TransactionForProcessing]) { +fn write_block_to_file(serialized_header: &[u8], serialized_cb_tx: &[u8], block_txs: &[TransactionForProcessing]) { fs::write("../output.txt", "").unwrap(); // Clear the output file append_to_file("../output.txt", &hex::encode(serialized_header)).unwrap(); append_to_file("../output.txt", &hex::encode(serialized_cb_tx)).unwrap(); - // Create a hashmap of txid to transaction for easy lookup - let tx_map: HashMap = block_txs.iter().map(|tx| (tx.txid.clone(), tx)).collect(); - - // Write the transactions in the order they appear in txs - for txid in txs { - if let Some(tx) = tx_map.get(&txid) { - append_to_file("../output.txt", &tx.txid).unwrap(); - } + for tx in block_txs { + append_to_file("../output.txt", &tx.txid).unwrap(); } } +