cashscript icon indicating copy to clipboard operation
cashscript copied to clipboard

support to set `nSequence` as a number of second chunks

Open mr-zwets opened this issue 1 year ago • 1 comments

support to set nSequence as a number of second chunks

Currently this is not supported a laid out in the docs:

Because of the way time locks work, a corresponding time lock needs to be added to the transaction. This can be done in the CashScript SDK through [addInput()][addInput()] by passing the sequence as optional argument. However, the value passed into this function will always be treated as a number of blocks, so it is currently not supported to use this.age as a number of second chunks.

mr-zwets avatar Mar 03 '25 16:03 mr-zwets

@kiok46 mentioned the following

I was testing out the nSequence parameter for both block-based and time-based relative locking by setting 22nd bit, so I set it to 0x400001 i.e 4193405 it worked, and in bitcann I have already enforced that at the contract level to always ensure that the nsequence is added as the correct value so it always work. (forced that it must be added in input correctly)

I was this comment in the cashscript next documentation: https://next.cashscript.org/docs/language/globals#thisage

but I tested with the values I mentioned above for 4193405 and for 4193406, it did was is expected increase in relative locking time of 512 seconds for increasing by 1 bit.

so it seems this behavior is supported in a roundabout way, the user needs to pass a correctly encoded hex number (or the corresponding decimal number) to the sequence InputOption but can use 'seconds-chunks' instead of a 'block' value for the sequence number

mr-zwets avatar May 04 '25 13:05 mr-zwets