I have created a P2sh includes OP_CHECKSEQUENCEVERIFY and funded the same. I was trying to redeem the coins. But i could not understand the working of OP_CHECKSEQUENCEVERIFY. Below is the example which I have tried,
Execute the timelock condn: currently the block count is 152
btcc [OP_IF 155 OP_CHECKSEQUENCEVERIFY OP_DROP OP_SHA256 ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d1 OP_EQUAL OP_ENDIF
]
redeemscript:
2a63029b00b275a820ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d18768
bitcoin-cli decodescript 63029b00b275a820ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d18768
{
"asm": "OP_IF 155 OP_CHECKSEQUENCEVERIFY OP_DROP OP_SHA256 ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d1 OP_EQUAL OP_ENDIF",
"type": "nonstandard",
"p2sh": "2N8grZYRHeBLPy9hE7LoY6MvS53j81UYcpP",
"segwit": {
"asm": "0 204808939e268852417e8d2988688fbb7482887aa3ecb10e46e848427976bd77",
"hex": "0020204808939e268852417e8d2988688fbb7482887aa3ecb10e46e848427976bd77",
"reqSigs": 1,
"type": "witness_v0_scripthash",
"addresses": [
"bcrt1qypyq3yu7y6y9yst7355cs6y0hd6g9zr650ktzrjxapyyy7tkh4mshxnqjw"
],
"p2sh-segwit": "2NFRd4rwoGkRy13fA4h2DhmHrAUgJ1rx5cr"
}
}
bitcoin-cli sendtoaddress 2N8grZYRHeBLPy9hE7LoY6MvS53j81UYcpP 0.001
4383cef8bb9026ec5a0a7ee0be4379b5d888bddbbf328ed2c356941fb0e2a4af
create raw txn with below given txid and vout:
bitcoin-cli getrawtransaction 4383cef8bb9026ec5a0a7ee0be4379b5d888bddbbf328ed2c356941fb0e2a4af
02000000000101fc4d29e944c0efb5aad0e437dc13a0bba3374ae885673879b213c6dc80c021350000000017160014544aa5cc9c1377f5bc51240216d0dfbcd0809efdfeffffff02c4bb25050000000017a9145b5337c2a79e2f3c01185eaca7f1322eff343fb087a08601000000000017a914a962d0d582a9ffe4f4ffeef878ced14b381a3daa870247304402206c9c3af6dedd715b21037e53b7212d4228fb75b7e7c9b136511f46a35dadcdda0220499b18337235323bd558cbf0b91ed0a73ff56373c312fccd69e5866ba1662cf1012103ba91e8963545b487403bf7b325598b896dbd6e6e858f9b8fd053576033f114c198000000
Some parts of o/p:
txid: 4383cef8bb9026ec5a0a7ee0be4379b5d888bddbbf328ed2c356941fb0e2a4af
vout: {
"value": 0.00100000, "n": 1, "scriptPubKey": { "asm": "OP_HASH160 a962d0d582a9ffe4f4ffeef878ced14b381a3daa OP_EQUAL", "hex": "a914a962d0d582a9ffe4f4ffeef878ced14b381a3daa87", "reqSigs": 1, "type": "scripthash", "addresses": [ "2N8grZYRHeBLPy9hE7LoY6MvS53j81UYcpP" ] } }
bitcoin-cli createrawtransaction "[{\"txid\":\"4383cef8bb9026ec5a0a7ee0be4379b5d888bddbbf328ed2c356941fb0e2a4af\",\"vout\":1}]" "[{\"mtrNo3QBMwXRV5HdxknBesWBzitqEnfLxM\":0.0003},{\"2N8grZYRHeBLPy9hE7LoY6MvS53j81UYcpP\":0.000688}]"
o/p:
0200000001afa4e2b01f9456c3d28e32bfdbbd88d8b57943bee07e0a5aec2690bbf8ce83430100000000ffffffff0230750000000000001976a9149245fd67a780afdd93ae3e8d39cdc41b40deeeaa88acc00c01000000000017a914a962d0d582a9ffe4f4ffeef878ced14b381a3daa8700000000
adding the signature:
ScriptSig part:
secret hex: 0a626c6f636b636861696e
redeemscript:
2a63029b00b275a820ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d18768
secrethash + if condn+ redeem script
0a626c6f636b636861696e01512a63029b00b275a820ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d18768
manually created signature:
0200000001afa4e2b01f9456c3d28e32bfdbbd88d8b57943bee07e0a5aec2690bbf8ce834301000000380a626c6f636b636861696e01512a63029b00b275a820ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d18768ffffffff0230750000000000001976a9149245fd67a780afdd93ae3e8d39cdc41b40deeeaa88acc00c01000000000017a914a962d0d582a9ffe4f4ffeef878ced14b381a3daa8700000000
bitcoin-cli sendrawtransaction 0200000001afa4e2b01f9456c3d28e32bfdbbd88d8b57943bee07e0a5aec2690bbf8ce834301000000380a626c6f636b636861696e01512a63029b00b275a820ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d18768ffffffff0230750000000000001976a9149245fd67a780afdd93ae3e8d39cdc41b40deeeaa88acc00c01000000000017a914a962d0d582a9ffe4f4ffeef878ced14b381a3daa8700000000
error code: -26 error message: non-mandatory-script-verify-flag (Locktime requirement not satisfied) (code 64)
the same error , was getting even if the blocksize reached more than 155.
Can you please explain to me what I have missed?
bitcoin-cli getrawtransaction 4383cef8bb9026ec5a0a7ee0be4379b5d888bddbbf328ed2c356941fb0e2a4af
– Alistair Mann Sep 30 '19 at 16:50nSequence
of your transaction to default, which is 4294967295. When redeeming OP_CSV, your nSequence should be higher than the blocks locked in OP_CSV, but lower than the number of blocks that have been mined since the transaction was confirmed in the block. You can set yournSequence
to 155 in thecreaterawtransaction
step. – Ugam Kamat Oct 1 '19 at 6:00nSequence
value. This value has to be more than 155, but less than 166 in our case. If we set it more than 166, the software will detect that the value ofnSequence
is higher than the number of blocks have passed and reject the transaction. – Ugam Kamat Oct 1 '19 at 16:05