Skip to content

Commit

Permalink
Have most of the logic worked out for the validate_tx function. verif…
Browse files Browse the repository at this point in the history
…y_script function is next
  • Loading branch information
slanesuke committed Mar 28, 2024
1 parent 2c8c994 commit 63d3ddb
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion mine-your-first-block/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,31 @@ fn deserialize_tx(filename: &str) -> Result<Transaction, Box<dyn std::error::Err


fn validate_tx(transaction: &Transaction) -> bool {
// Code to validate tx based

// If the input value in sats is less than the output value then the transaction is already
// invalid. the sum of the input must be greater than the sum of the output the difference is
// the transaction fee. need to filter out higher tx fees later to include in block
let input_value: u64 = transaction.vin.iter().map(|vin| vin.prevout.value).sum();
let output_value: u64 = transaction.vout.iter().map(|vout| vout.value).sum();
if input_value < output_value {
return false;
}

// Verify if scriptpubkey_asm returns true
// will this work as for outputs in transaction outputs? verify if this is correct
for vout in &transaction.vout {
if !verify_script(&vout.scriptpubkey_asm) {
return false;
}
}
// if all verifications pass the transaction is validated and returns true or OK
true
}

// TODO make a function that verifies if a script returns OK
fn verify_script(script: &str) -> bool {
// Verify the script based off grokking bitcoin chapter 5
// look over OP_CODES or operators
true
}

Expand Down

0 comments on commit 63d3ddb

Please sign in to comment.