Update 9_2_Using_CLTV_in_Scripts.md

This commit is contained in:
Shannon Appelcline 2017-05-24 14:33:12 -07:00 committed by GitHub
parent 0eeea9d291
commit a46981388b

View File

@ -4,6 +4,8 @@
`OP_CHECKLOCKTIMEVERIFY` (or CLTV) is the natural complement to `nLockTime`. It moves the idea of locking transactions by an absolute time or blockheight into the realm of opcodes, allowing for the locking of individual UTXOs. `OP_CHECKLOCKTIMEVERIFY` (or CLTV) is the natural complement to `nLockTime`. It moves the idea of locking transactions by an absolute time or blockheight into the realm of opcodes, allowing for the locking of individual UTXOs.
> **VERSION WARNING:** CLTV became available with Bitcoin Core 0.11.2, and should be fairly widely deployed at this time.
## Remember nLockTime ## Remember nLockTime
Before digging into CLTV, we should first recall how `nLockTime` works. Before digging into CLTV, we should first recall how `nLockTime` works.
@ -21,6 +23,8 @@ The transaction cannot be spent (or even put on the block chain) until either th
Because CLTV is just part of a script (and presumably part of a P2SH transaction), the transaction immediately goes into the mempool; as soon as it's verified, it goes onto the blockchain, and the funds are considered spent. The trick is that all the outputs that were locked with the CLTV aren't available for _respending_ until the CLTV allows it. Because CLTV is just part of a script (and presumably part of a P2SH transaction), the transaction immediately goes into the mempool; as soon as it's verified, it goes onto the blockchain, and the funds are considered spent. The trick is that all the outputs that were locked with the CLTV aren't available for _respending_ until the CLTV allows it.
### Understand a CLTV Absolute Time
This is how a `OP_CHECKLOCKTIMEVERIFY` might be used to check against May 24, 2017: This is how a `OP_CHECKLOCKTIMEVERIFY` might be used to check against May 24, 2017:
``` ```
1495652013 OP_CHECKLOCKTIME VERIFY 1495652013 OP_CHECKLOCKTIME VERIFY
@ -33,6 +37,9 @@ Or this:
``` ```
<AbsoluteTime> OP_CHECKLOCKTIME VERIFY <AbsoluteTime> OP_CHECKLOCKTIME VERIFY
``` ```
### Understand a CLTV Absolute Block Height
This is how `OPCHECKLOCKTIMEVERIFY` might be used to check against a blockheight that was reached on May 24, 2017: This is how `OPCHECKLOCKTIMEVERIFY` might be used to check against a blockheight that was reached on May 24, 2017:
``` ```
467951 OP_CHECKLOCKTIME VERIFY 467951 OP_CHECKLOCKTIME VERIFY
@ -42,8 +49,6 @@ But we'll usually abtract it like this:
<AbsoluteBlockHeight> OP_CHECKLOCKTIME VERIFY <AbsoluteBlockHeight> OP_CHECKLOCKTIME VERIFY
``` ```
> **VERSION WARNING:** CLTV became available with Bitcoin Core 0.11.2, and should be fairly widely deployed at this time.
### Understand How CLTV Really Works ### Understand How CLTV Really Works
The above explanation is sufficient to use and understand CLTV. However, [BIP 65](https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki) lays out all the details. The above explanation is sufficient to use and understand CLTV. However, [BIP 65](https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki) lays out all the details.