mirror of
https://github.com/bitcoinbook/bitcoinbook
synced 2025-06-09 09:38:50 +00:00
Merged branch develop into master
This commit is contained in:
commit
767df92aef
@ -344,7 +344,7 @@ When interpreting nSequence as a relative timelock, only the 16 least significan
|
||||
The following diagram shows the binary layout of the nSequence value, as defined by BIP-68:
|
||||
|
||||
.BIP-68 definition of nSequence encoding
|
||||
image::nSequence_encoding.png["BIP-68 definition of nSequence encoding"]
|
||||
image::images/nSequence_encoding.png["BIP-68 definition of nSequence encoding"]
|
||||
|
||||
Relative timelocks based on consensus enforcement of the nSequence value are defined in BIP-68:
|
||||
|
||||
@ -434,9 +434,9 @@ code to run in either case
|
||||
|
||||
When reading Bitcoin Script, remember that the condition being evaluated comes *before* the +IF+ opcode.
|
||||
|
||||
==== Flow Control with VERIFY opcodes
|
||||
==== Conditional clauses with VERIFY opcodes
|
||||
|
||||
Another form of flow control in Bitcoin Script is any opcode that ends in +VERIFY+. The +VERIFY+ suffix means that if the condition evaluated is not TRUE, execution of the script terminates immediately and the transaction is deemed invalid.
|
||||
Another form of conditional in Bitcoin Script is any opcode that ends in +VERIFY+. The +VERIFY+ suffix means that if the condition evaluated is not TRUE, execution of the script terminates immediately and the transaction is deemed invalid.
|
||||
|
||||
Unlike an +IF+ clause which offers alternative execution paths, the +VERIFY+ suffix acts as a _guard clause_, continuing only if a precondition is met.
|
||||
|
||||
@ -475,7 +475,7 @@ Bob's unlocking script is identical:
|
||||
|
||||
The script with +IF+ does the same thing as using an opcode with a +VERIFY+ suffix, they both operate as guard clauses. However, the +VERIFY+ construction is more efficient, using one fewer opcode.
|
||||
|
||||
So, when do we use +VERIFY+ and when do we use +IF+? If all we are trying to do is to attach a pre-condition (guard clause), then +VERIFY+ is better. If however, we want to have more than one execution path, then we need an +IF...ELSE+ flow control clause.
|
||||
So, when do we use +VERIFY+ and when do we use +IF+? If all we are trying to do is to attach a pre-condition (guard clause), then +VERIFY+ is better. If however, we want to have more than one execution path (flow control), then we need an +IF...ELSE+ flow control clause.
|
||||
|
||||
==== Using Flow Control in Scripts
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user