saner _addInput.

This commit is contained in:
Christopher Jeffrey 2016-02-06 01:07:26 -08:00
parent 18f0a55779
commit 26f1e44eb3

View File

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