Skip to content

Commit

Permalink
added marker and flag to coinbase tx
Browse files Browse the repository at this point in the history
  • Loading branch information
slanesuke committed Apr 20, 2024
1 parent 2112833 commit 4408255
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mine-your-first-block/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ fn serialize_tx(transaction: &Transaction) -> String {
let version = transaction.version.to_le_bytes();
serialized_tx.push_str(&hex::encode(version));

// For the coinbase transaction in between the version and vin count I need to add the marker and flag
// If the is_coinbase == true push 00 and 01
if transaction.vin[0].is_coinbase {
serialized_tx.push_str("0001");
}

// Serialize vin count
let vin_count = transaction.vin.len() as u64;
serialized_tx.push_str(&format!("{:02x}", vin_count));
Expand Down Expand Up @@ -1446,8 +1452,8 @@ fn write_block_to_file(serialized_header: &[u8], serialized_cb_tx: &[u8], txs: V
// println!("{}", &tx.txid);
// append_to_file("../output.txt", &tx.txid).unwrap();
// }
let len = txs.len() / 2;
for txids in txs[..len].iter() {
//let len = txs.len() / 2;
for txids in txs {
//println!("{}", txids);
append_to_file("../output.txt", &txids).unwrap();
}
Expand Down

0 comments on commit 4408255

Please sign in to comment.