diff --git a/lib/coins/coinview.js b/lib/coins/coinview.js index f71b590d..0568fc01 100644 --- a/lib/coins/coinview.js +++ b/lib/coins/coinview.js @@ -107,18 +107,19 @@ CoinView.prototype.removeTX = function removeTX(tx, height) { */ CoinView.prototype.addEntry = function addEntry(prevout, coin) { - let coins = this.get(prevout.hash); + let {hash, index} = prevout; + let coins = this.get(hash); if (!coins) { coins = new Coins(); - this.add(prevout.hash, coins); + this.add(hash, coins); } if (coin.output.script.isUnspendable()) return; - if (!coins.has(prevout.index)) - coins.add(prevout.index, coin); + if (!coins.has(index)) + coins.add(index, coin); return coins; }; @@ -129,17 +130,18 @@ CoinView.prototype.addEntry = function addEntry(prevout, coin) { */ CoinView.prototype.addCoin = function addCoin(coin) { - let coins = this.get(coin.hash); + let {hash, index} = coin; + let coins = this.get(hash); if (!coins) { coins = new Coins(); - this.add(coin.hash, coins); + this.add(hash, coins); } if (coin.script.isUnspendable()) return; - if (!coins.has(coin.index)) + if (!coins.has(index)) coins.addCoin(coin); return coins; @@ -152,18 +154,19 @@ CoinView.prototype.addCoin = function addCoin(coin) { */ CoinView.prototype.addOutput = function addOutput(prevout, output) { - let coins = this.get(prevout.hash); + let {hash, index} = prevout; + let coins = this.get(hash); if (!coins) { coins = new Coins(); - this.add(prevout.hash, coins); + this.add(hash, coins); } if (output.script.isUnspendable()) return; - if (!coins.has(prevout.index)) - coins.addOutput(prevout.index, output); + if (!coins.has(index)) + coins.addOutput(index, output); }; /** @@ -173,13 +176,14 @@ CoinView.prototype.addOutput = function addOutput(prevout, output) { */ CoinView.prototype.spendOutput = function spendOutput(prevout) { - let coins = this.get(prevout.hash); + let {hash, index} = prevout; + let coins = this.get(hash); let coin; if (!coins) return false; - coin = coins.spend(prevout.index); + coin = coins.spend(index); if (!coin) return false; @@ -196,12 +200,13 @@ CoinView.prototype.spendOutput = function spendOutput(prevout) { */ CoinView.prototype.removeOutput = function removeOutput(prevout) { - let coins = this.get(prevout.hash); + let {hash, index} = prevout; + let coins = this.get(hash); if (!coins) return false; - return coins.remove(prevout.index); + return coins.remove(index); }; /** @@ -211,12 +216,13 @@ CoinView.prototype.removeOutput = function removeOutput(prevout) { */ CoinView.prototype.hasEntry = function hasEntry(prevout) { - let coins = this.get(prevout.hash); + let {hash, index} = prevout; + let coins = this.get(hash); if (!coins) return false; - return coins.has(prevout.index); + return coins.has(index); }; /** @@ -226,12 +232,13 @@ CoinView.prototype.hasEntry = function hasEntry(prevout) { */ CoinView.prototype.getEntry = function getEntry(prevout) { - let coins = this.get(prevout.hash); + let {hash, index} = prevout; + let coins = this.get(hash); if (!coins) return; - return coins.get(prevout.index); + return coins.get(index); }; /** @@ -256,12 +263,13 @@ CoinView.prototype.getCoin = function getCoin(prevout) { */ CoinView.prototype.getOutput = function getOutput(prevout) { - let coins = this.get(prevout.hash); + let {hash, index} = prevout; + let coins = this.get(hash); if (!coins) return; - return coins.getOutput(prevout.index); + return coins.getOutput(index); }; /**