diff --git a/mine-your-first-block/src/main.rs b/mine-your-first-block/src/main.rs index 0e2dc92..b33ba70 100644 --- a/mine-your-first-block/src/main.rs +++ b/mine-your-first-block/src/main.rs @@ -134,7 +134,7 @@ fn create_coinbase_tx(total_tx_fee: u64) -> Transaction { } // This function creates the block header struct -fn construct_block_header(valid_tx_vec: Vec, nonce: u32) -> BlockHeader { +fn construct_block_header(valid_tx_vec: Vec, nonce: u32, merkle_root: String) -> BlockHeader { let mut block_header = BlockHeader{ version: 0x20000000, @@ -157,9 +157,6 @@ fn construct_block_header(valid_tx_vec: Vec, nonce: u32) -> BlockHeader block_header.prev_block_hash = prev_block_hash.to_string(); // Left off on merkle root!! Lets go! - // Need to get the txids from the valid txs vec But this is just a placeholder for now - let txids: Vec = valid_tx_vec.iter().map(|txid| txid.clone()).collect(); - let merkle_root = get_merkle_root(txids); block_header.merkle_root = merkle_root; let timestamp = SystemTime::now() @@ -188,6 +185,7 @@ fn serialize_block_header(block_header: &BlockHeader) -> Vec { // Write each field directly into the buffer at the correct position writer.write_u32::(block_header.version).unwrap(); + // I had to reverse the byte order of the prev block hash and merkle root to test writer.write_all(&hex::decode(&block_header.prev_block_hash).unwrap().iter().rev().cloned().collect::>()).unwrap(); writer.write_all(&hex::decode(&block_header.merkle_root).unwrap().iter().rev().cloned().collect::>()).unwrap(); //writer.write_all(&hex::decode(&block_header.prev_block_hash).unwrap()).unwrap(); @@ -834,12 +832,9 @@ fn process_mempool(mempool_path: &str) -> io::Result