coins: refactor prevout methods.
This commit is contained in:
parent
492c05c378
commit
aa71ae690a
@ -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);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user