From 5a41c04bfd04b6d2dbc35a777546aa2b84cd3c65 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 29 Aug 2016 15:01:19 -0700 Subject: [PATCH] mtx: add setSequence. --- lib/primitives/mtx.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/primitives/mtx.js b/lib/primitives/mtx.js index 676bfca3..d6d19c5b 100644 --- a/lib/primitives/mtx.js +++ b/lib/primitives/mtx.js @@ -1497,6 +1497,30 @@ MTX.prototype.setLocktime = function setLocktime(locktime) { this.locktime = locktime; }; +/** + * Set sequence locktime. + * @param {Number} index - Input index. + * @param {Number} locktime + * @param {Boolean?} seconds + */ + +MTX.prototype.setSequence = function setSequence(index, locktime, seconds) { + var input = this.inputs[index]; + + assert(input, 'Input does not exist.'); + + this.version = 2; + + if (seconds) { + locktime >>>= constants.sequence.GRANULARITY; + locktime = constants.sequence.TYPE_FLAG | locktime; + } else { + locktime = constants.sequence.MASK & locktime; + } + + input.sequence = locktime; +}; + /** * Mark inputs and outputs as mutable. * @private