From b301fe5defc2945a710e3850f26ada6b7920acf7 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 12 Jun 2016 23:50:18 -0700 Subject: [PATCH] refactor. --- lib/bcoin/tx.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index 576c3bd2..9003f59b 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -957,24 +957,26 @@ TX.prototype.hasCoins = function hasCoins() { TX.prototype.fillCoins = function fillCoins(coins) { var total = 0; - var key, i, input, prevout; + var key, i, input, prevout, map, coin; - if ((coins instanceof bcoin.coin) || (coins instanceof bcoin.tx)) + if ((coins instanceof bcoin.coin) || (coins instanceof TX)) coins = [coins]; if (Array.isArray(coins)) { - coins = coins.reduce(function(out, coin) { + map = {}; + for (i = 0; i < coins.length; i++) { + coin = coins[i]; if (coin instanceof TX) { - out[coin.hash('hex')] = coin; + map[coin.hash('hex')] = coin; } else if (coin instanceof bcoin.coin) { assert(typeof coin.hash === 'string'); assert(typeof coin.index === 'number'); - out[coin.hash + '/' + coin.index] = coin; + map[coin.hash + '/' + coin.index] = coin; } else { assert(false, 'Non-coin object passed to fillCoins.'); } - return out; - }, {}); + } + coins = map; } for (i = 0; i < this.inputs.length; i++) {