Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
slanesuke committed Apr 21, 2024
1 parent 0f4476f commit fe805cd
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions mine-your-first-block/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<String>, 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<String, &TransactionForProcessing> = 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();
}
}





0 comments on commit fe805cd

Please sign in to comment.