From a1fea2bd65b3fecd84f8b00301cfc29ff1e4b09a Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 7 Dec 2015 15:53:56 -0800 Subject: [PATCH] scriptOutput: move "p2shify". --- lib/bcoin/tx.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index e57f17a6..bab63608 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -301,16 +301,6 @@ TX.prototype.scriptOutput = function(options) { assert(n >= 1 && n <= 3); script = bcoin.script.multisig(keys, m, n); - - // make it p2sh - if (options.hash) { - var hash = utils.ripesha(bcoin.script.encode(script)); - script = [ - 'hash160', - hash, - 'eq' - ]; - } } else if (bcoin.wallet.validateAddress(options.address, 'p2sh')) { // p2sh transaction // https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki @@ -332,6 +322,18 @@ TX.prototype.scriptOutput = function(options) { ]; } + // make it p2sh + if (options.hash) { + var redeem = script; + var hash = utils.ripesha(bcoin.script.encode(redeem)); + script = [ + 'hash160', + hash, + 'eq' + ]; + script.redeem = redeem; + } + return script; };