0
I'm working on a tool for timelocked contract generation. My redeem script looks like so:
OP_HASH160 <revocationHash> OP_EQUAL
OP_IF
<bobPubKey>
OP_ELSE
<timeDelay> OP_CHECKSEQUENCEVERIFY OP_DROP
<alicePubKey>
OP_ENDIF
OP_CHECKSIG
The goal is that Alice can spend the funds after a time delay, while Bob can spend them at any time by proving knowledge of the hash preimage.
Spending through the revocation hash is easy enough. However, I'm having trouble constructing a transaction that spends based on the timelock is proving more difficult. Essentially, my questions are:
- What does the
<timeDelay>value represent? How can I e.g. lock the funds for 2 blocks? - From what I've read, the sequence number on the spend transaction needs to be set. But what should it be set to?
- How do I practically implement this using
bitcoinjs-libor another library?
an update bitcoin-js also has a handy bip68 lib on the github https://github.com/bitcoinjs/bip68
so you could do something like this
var sequenceNumber = bip68.encode({ seconds: timeToLock }); bitcoin.script.number.encode(sequenceNumber), bitcoin.opcodes.OP_NOP3, bitcoin.opcodes.OP_DROP,