diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index e607b0a2..83bf96e2 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -125,37 +125,36 @@ TX.prototype.input = TX.prototype.addInput; // tx._addInput(input) // tx._addInput({ hash: hash, index: index }) // tx._addInput({ tx: tx, index: index }) -TX.prototype._addInput = function _addInput(obj, index) { - var options, hash, input, ex, i, prevout; +TX.prototype._addInput = function _addInput(options, index) { + var input, ex, i, prevout; - if (obj instanceof TX) - options = { tx: obj, index: index }; - else if (typeof obj === 'string' || utils.isBuffer(obj)) - options = { hash: obj, index: index }; + if (options instanceof TX) + options = { prevout: { tx: options, index: index } }; + else if (typeof options === 'string' || utils.isBuffer(options)) + options = { prevout: { hash: options, index: index } }; + else if (!options.prevout) + options = { prevout: options, script: options.script, sequence: options.sequence }; else - options = obj; + options = options; - prevout = options.prevout || options.out; + if (options.out) + options.prevout = options.out; - if (options.tx) - hash = options.tx.hash('hex'); - else if (prevout) - hash = prevout.hash; - else - hash = options.hash; + if (options.seq != null) + options.sequence = options.seq; - if (typeof hash !== 'string') - hash = utils.toHex(hash); + if (options.prevout.tx) + options.prevout.hash = options.prevout.tx.hash('hex'); input = bcoin.input({ tx: this, prevout: { - tx: prevout ? prevout.tx : options.tx, - hash: hash, - index: prevout ? prevout.index : options.index + tx: options.prevout.tx, + hash: options.prevout.hash, + index: options.prevout.index }, script: options.script, - sequence: options.sequence || options.seq + sequence: options.sequence }); // Try modifying existing input first