refactor.
This commit is contained in:
parent
e51464f29b
commit
b301fe5def
@ -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++) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user