From 5b68ec0b3e1b85f091faa87b8466fa0b4d741bd1 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 17 Dec 2015 17:31:37 -0800 Subject: [PATCH] add option for colored coin output creation. --- lib/bcoin/tx.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index 964ff589..3f4ee741 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -407,6 +407,16 @@ TX.prototype.scriptOutput = function scriptOutput(output, options) { assert(n >= 1 && n <= 3); script = bcoin.script.multisig(keys, m, n); + + // make it p2sh + if (options.scripthash) { + var hash = utils.ripesha(bcoin.script.encode(script)); + script = [ + 'hash160', + hash, + 'eq' + ]; + } } else if (bcoin.wallet.validateAddress(options.address, 'scripthash')) { // p2sh transaction // https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki @@ -426,18 +436,15 @@ TX.prototype.scriptOutput = function scriptOutput(output, options) { 'eqverify', 'checksig' ]; - } - - // make it p2sh - if (options.hash) { - var redeem = script; - var hash = utils.ripesha(bcoin.script.encode(redeem)); + } else if (options.color) { + var color = options.color; + if (typeof color === 'string') + color = utils.ascii2array(color); + assert(color.length <= 40); script = [ - 'hash160', - hash, - 'eq' + 'ret', + color ]; - script.redeem = redeem; } output.script = script;