|
|
|
@ -25,7 +25,7 @@ used.
|
|
|
|
|
[role="pagebreak-before less_space_h1"]
|
|
|
|
|
=== Transaction Scripts and Script Language
|
|
|
|
|
|
|
|
|
|
((("scripting", "transactions and",id="Stransact06")))The original version of Bitcoin introduced a new
|
|
|
|
|
The original version of Bitcoin introduced a new
|
|
|
|
|
programming language called _Script_, a Forth-like stack-based
|
|
|
|
|
language. Both the script placed in an output and the legacy
|
|
|
|
|
input script used in a spending transaction are written in this scripting
|
|
|
|
@ -311,7 +311,7 @@ image::images/mbc2_0606.png["Tx_Script_P2PubKeyHash_2"]
|
|
|
|
|
[[multisig]]
|
|
|
|
|
=== Scripted multisignatures
|
|
|
|
|
|
|
|
|
|
((("scripting","multisignature scripts", id="Smulti07")))((("multisignature
|
|
|
|
|
((("multisignature
|
|
|
|
|
scripts")))Multisignature scripts set a condition where _k_ public keys
|
|
|
|
|
are recorded in the script and at least _t_ of those must provide
|
|
|
|
|
signatures to spend the funds, called t-of-k.
|
|
|
|
@ -473,7 +473,7 @@ introduced in 2012 as a powerful new type of operation that greatly
|
|
|
|
|
simplifies the use of complex scripts. To explain the need
|
|
|
|
|
for P2SH, let's look at a practical example.
|
|
|
|
|
|
|
|
|
|
((("Pay-to-Script-Hash(P2SH)", "import/export example")))
|
|
|
|
|
|
|
|
|
|
Mohammed is an electronics importer based in Dubai. Mohammed's
|
|
|
|
|
company uses Bitcoin's multisignature feature extensively for its
|
|
|
|
|
corporate accounts. Multisignature scripts are one of the most common
|
|
|
|
@ -606,7 +606,7 @@ If the redeem script hash matches, the redeem script is executed:
|
|
|
|
|
|
|
|
|
|
==== P2SH Addresses
|
|
|
|
|
|
|
|
|
|
((("bitcoinimprovement proposals", "Address Format for P2SH (BIP13)")))Another
|
|
|
|
|
Another
|
|
|
|
|
important part of the P2SH feature is the ability to encode a script
|
|
|
|
|
hash as an address, as defined in BIP13. P2SH addresses are Base58Check
|
|
|
|
|
encodings of the 20-byte hash of a script, just like Bitcoin addresses
|
|
|
|
@ -676,7 +676,7 @@ spent.
|
|
|
|
|
[[op_return]]
|
|
|
|
|
=== Data Recording Output (OP_RETURN)
|
|
|
|
|
|
|
|
|
|
((("data recording(nonpayment data)")))((("blockchain (the)",
|
|
|
|
|
((("blockchain (the)",
|
|
|
|
|
"nonpayment data recording")))Bitcoin's
|
|
|
|
|
distributed and timestamped blockchain has potential uses
|
|
|
|
|
beyond payments. Many developers have tried to use the transaction
|
|
|
|
@ -766,7 +766,7 @@ It is important to understand the limitations of transaction lock time. The only
|
|
|
|
|
|
|
|
|
|
==== Check Lock Time Verify (OP_CLTV)
|
|
|
|
|
|
|
|
|
|
((("scripting", "timelocks", "Check Lock TimeVerify (OP_CLTV)")))((("bitcoin improvement proposals",
|
|
|
|
|
((("bitcoin improvement proposals",
|
|
|
|
|
"OP_CHECKLOCKTIMEVERIFY (BIP65)")))In December 2015, a new form of
|
|
|
|
|
timelock was introduced to Bitcoin as a soft fork upgrade. Based on a
|
|
|
|
|
specification in BIP65, a new script operator called
|
|
|
|
@ -881,7 +881,7 @@ https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki[BIP65
|
|
|
|
|
[[op_csv]]
|
|
|
|
|
==== Relative Timelocks
|
|
|
|
|
|
|
|
|
|
Lock time and +OP_CLTV+ are ((("scripting", "timelocks", "relativetimelocks")))both
|
|
|
|
|
Lock time and +OP_CLTV+ are both
|
|
|
|
|
_absolute timelocks_ in that they specify an absolute point in time. The
|
|
|
|
|
next two timelock features we will examine are _relative timelocks_ in
|
|
|
|
|
that they specify, as a condition of spending an output, an elapsed time
|
|
|
|
@ -902,7 +902,7 @@ on the value of +sequence+, a transaction field that is set in every
|
|
|
|
|
transaction input. Script-level relative timelocks are implemented with
|
|
|
|
|
the +OP_CHECKSEQUENCEVERIFY+ (OP_CSV) opcode.
|
|
|
|
|
|
|
|
|
|
((("bitcoin improvementproposals", "CHECKSEQUENCEVERIFY (BIP112)")))Relative timelocks are
|
|
|
|
|
Relative timelocks are
|
|
|
|
|
implemented according to the specifications in
|
|
|
|
|
https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki[BIP68,
|
|
|
|
|
Relative lock-time using consensus-enforced sequence numbers] and
|
|
|
|
@ -953,7 +953,7 @@ CHECKSEQUENCEVERIFY].
|
|
|
|
|
|
|
|
|
|
=== Scripts with Flow Control (Conditional Clauses)
|
|
|
|
|
|
|
|
|
|
((("conditional clauses",id="condition07")))One of the more
|
|
|
|
|
One of the more
|
|
|
|
|
powerful features of Bitcoin Script is flow control, also known as
|
|
|
|
|
conditional clauses. You are probably familiar with flow control in
|
|
|
|
|
various programming languages that use the construct +IF...THEN...ELSE+.
|
|
|
|
|