locktime – How does nSequence/Verify Sequence Confirm work?

0
2


In an effort to use a relative time lock, it’s essential present the necessities within the scriptPubKey to which the Bitcoin is shipped.

Instance

scriptPubKey for escrow with 30 day timeout:

IF
    2 <Alice's pubkey> <Bob's pubkey> <Escrow's pubkey> 3 CHECKMULTISIG
ELSE
    "30d" CHECKSEQUENCEVERIFY DROP
    <Alice's pubkey> CHECKSIG
ENDIF

Then, so as to spend it earlier than 30 days, the scriptSig that satisfies the primary conditional assertion (multisig script) have to be offered, i.e.:

scriptSig: 0 <signature1> <signature2>

Or after 30 days, alice can present:

scriptSig: <signature>

See BIP112

Sequence

Be aware that so as to set a relative locktime: the tx will need to have the next properties:

  • model have to be 2 or higher
  • nSequence should not have thirty second bit set
  • nSequence will need to have the twenty third bit set (0x400000) if it’s a lock-time kind, unset for block peak kind
  • for relative lock-time kind the granularity of every bit is 512 seconds
  • for relative block peak kind every bit represents 1 block

For 30 days, I consider it could be as follows:

30 * 24 * 60 * 60 = 2592000 seconds
2592000 / 512 = 5062.5 ~= 5063 or 0x13C7
sequence = 0x13C7 | 0x400000 = 0x4013C7 or 4199367
nSequence = 0xC7134000 (little endian)

The sequence is the final 4 bytes of an enter, see https://en.bitcoin.it/wiki/Transaction

LEAVE A REPLY

Please enter your comment!
Please enter your name here