blockchain – How transactions script work?

0
118


You’ll be able to consider a “locking script” as perform definition, and the “unlocking script” as perform arguments that may make the perform consider to true.

The generally used P2PKH handle is mostly a little program hooked up to the UTXO which has a perform definition like f_p2pkh(public_key, signature, sighash_flags). An UTXO retains some BTC locked with that perform. The spender then creates a transaction which references a selected occasion of the perform f_p2pkh and offers the three arguments public_key, signature, and sighash_flags.

Right here the perform definition hard-codes the general public key hash so you may’t signal with any key however should use the particular key outlined as a continuing within the perform itself.

However what “message” does the signature signal? The perform will name a local perform (OP_CHECKSIG) which constructs a message from the transaction context it is being spent in utilizing the instruction encoded within the “sighash_flag” argument. This lets the spender not simply unlock the UTXO but in addition determine precisely the place the unlocked BTC can transfer to (new outputs).

The signature “message” is constructed from the transaction physique in keeping with supported recipes, encoded by sighash flags. With P2PKH, the spender will get to decide on the recipe – which permits for some flexibility in what outputs to require: SIGHASH_ALL, SIGHASH_NONE, SIGHASH_SINGLE, and likewise provides signer the choice to permit others so as to add extra inputs through the use of SIGHASH_ANYONECANPAY.

Every UTXO is sort of a little field that holds some BTC and locked with a wise lock, and our perform definition is the lock’s firmware, and the firmware can “see” different elements of the transaction. We spend by feeding the good lock the data required to open, which then releases the BTC and strikes it to some new bins.

LEAVE A REPLY

Please enter your comment!
Please enter your name here