optimize tx.fillCoins.
This commit is contained in:
parent
98eeaf0af3
commit
4381cb5d84
@ -1021,8 +1021,8 @@ TX.prototype.hasCoins = function hasCoins() {
|
||||
*/
|
||||
|
||||
TX.prototype.fillCoins = function fillCoins(coins) {
|
||||
var total = 0;
|
||||
var key, i, input, prevout, map, coin;
|
||||
var result = true;
|
||||
var i, input, hash, index, map, coin;
|
||||
|
||||
if ((coins instanceof bcoin.coin)
|
||||
|| (coins instanceof TX)) {
|
||||
@ -1048,23 +1048,30 @@ TX.prototype.fillCoins = function fillCoins(coins) {
|
||||
|
||||
for (i = 0; i < this.inputs.length; i++) {
|
||||
input = this.inputs[i];
|
||||
prevout = input.prevout;
|
||||
|
||||
if (!input.coin) {
|
||||
if (coins[prevout.hash]) {
|
||||
input.coin = bcoin.coin.fromTX(coins[prevout.hash], prevout.index);
|
||||
} else {
|
||||
key = prevout.hash + '/' + prevout.index;
|
||||
if (coins[key])
|
||||
input.coin = coins[key];
|
||||
}
|
||||
}
|
||||
hash = input.prevout.hash;
|
||||
index = input.prevout.index;
|
||||
|
||||
if (input.coin)
|
||||
total++;
|
||||
continue;
|
||||
|
||||
coin = coins[hash];
|
||||
|
||||
if (coin) {
|
||||
input.coin = bcoin.coin.fromTX(coin, index);
|
||||
continue;
|
||||
}
|
||||
|
||||
coin = coins[hash + '/' + index];
|
||||
|
||||
if (coin) {
|
||||
input.coin = coin;
|
||||
continue;
|
||||
}
|
||||
|
||||
result = false;
|
||||
}
|
||||
|
||||
return total === this.inputs.length;
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user