refactor.

This commit is contained in:
Christopher Jeffrey 2016-06-12 23:50:18 -07:00
parent e51464f29b
commit b301fe5def
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -957,24 +957,26 @@ TX.prototype.hasCoins = function hasCoins() {
TX.prototype.fillCoins = function fillCoins(coins) { TX.prototype.fillCoins = function fillCoins(coins) {
var total = 0; 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]; coins = [coins];
if (Array.isArray(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) { if (coin instanceof TX) {
out[coin.hash('hex')] = coin; map[coin.hash('hex')] = coin;
} else if (coin instanceof bcoin.coin) { } else if (coin instanceof bcoin.coin) {
assert(typeof coin.hash === 'string'); assert(typeof coin.hash === 'string');
assert(typeof coin.index === 'number'); assert(typeof coin.index === 'number');
out[coin.hash + '/' + coin.index] = coin; map[coin.hash + '/' + coin.index] = coin;
} else { } else {
assert(false, 'Non-coin object passed to fillCoins.'); assert(false, 'Non-coin object passed to fillCoins.');
} }
return out; }
}, {}); coins = map;
} }
for (i = 0; i < this.inputs.length; i++) { for (i = 0; i < this.inputs.length; i++) {