From 5c1606985a06b19190f9aace7e4665c8d874f3fb Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 10 Dec 2015 18:02:47 -0800 Subject: [PATCH] outputScript() consistency. --- lib/bcoin/tx.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index d48bc338..731d11d7 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -301,21 +301,25 @@ TX.prototype.scriptSig = function(input, key, pub, type) { return input.script; }; -TX.prototype.output = function output(output, value) { - if (output instanceof bcoin.wallet) - output = output.getAddress(); +TX.prototype.output = function output(options, value) { + if (options instanceof bcoin.wallet) + options = options.getAddress(); - if (typeof output === 'string') { - output = { - address: output, + if (typeof options === 'string') { + options = { + address: options, value: value }; } - this.outputs.push({ - value: new bn(output.value), - script: this.scriptOutput(output) - }); + var output = { + value: new bn(options.value), + script: options.script ? options.script.slice() : [] + }; + + this.outputs.push(output); + + this.scriptOutput(output, options); return this; }; @@ -323,8 +327,10 @@ TX.prototype.output = function output(output, value) { // compat TX.prototype.out = TX.prototype.output; -TX.prototype.scriptOutput = function(options) { - var script = options.script ? options.script.slice() : []; +TX.prototype.scriptOutput = function(output, options) { + options = options || output; + + var script = output.script ? output.script.slice() : []; if (Array.isArray(options.keys || options.address)) { // Raw multisig transaction @@ -391,7 +397,7 @@ TX.prototype.scriptOutput = function(options) { script.redeem = redeem; } - return script; + output.script = script; }; TX.prototype.getSubscript = function getSubscript(index) {