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) {
|
CoinView.prototype.addEntry = function addEntry(prevout, coin) {
|
||||||
let coins = this.get(prevout.hash);
|
let {hash, index} = prevout;
|
||||||
|
let coins = this.get(hash);
|
||||||
|
|
||||||
if (!coins) {
|
if (!coins) {
|
||||||
coins = new Coins();
|
coins = new Coins();
|
||||||
this.add(prevout.hash, coins);
|
this.add(hash, coins);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (coin.output.script.isUnspendable())
|
if (coin.output.script.isUnspendable())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!coins.has(prevout.index))
|
if (!coins.has(index))
|
||||||
coins.add(prevout.index, coin);
|
coins.add(index, coin);
|
||||||
|
|
||||||
return coins;
|
return coins;
|
||||||
};
|
};
|
||||||
@ -129,17 +130,18 @@ CoinView.prototype.addEntry = function addEntry(prevout, coin) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
CoinView.prototype.addCoin = function addCoin(coin) {
|
CoinView.prototype.addCoin = function addCoin(coin) {
|
||||||
let coins = this.get(coin.hash);
|
let {hash, index} = coin;
|
||||||
|
let coins = this.get(hash);
|
||||||
|
|
||||||
if (!coins) {
|
if (!coins) {
|
||||||
coins = new Coins();
|
coins = new Coins();
|
||||||
this.add(coin.hash, coins);
|
this.add(hash, coins);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (coin.script.isUnspendable())
|
if (coin.script.isUnspendable())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!coins.has(coin.index))
|
if (!coins.has(index))
|
||||||
coins.addCoin(coin);
|
coins.addCoin(coin);
|
||||||
|
|
||||||
return coins;
|
return coins;
|
||||||
@ -152,18 +154,19 @@ CoinView.prototype.addCoin = function addCoin(coin) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
CoinView.prototype.addOutput = function addOutput(prevout, output) {
|
CoinView.prototype.addOutput = function addOutput(prevout, output) {
|
||||||
let coins = this.get(prevout.hash);
|
let {hash, index} = prevout;
|
||||||
|
let coins = this.get(hash);
|
||||||
|
|
||||||
if (!coins) {
|
if (!coins) {
|
||||||
coins = new Coins();
|
coins = new Coins();
|
||||||
this.add(prevout.hash, coins);
|
this.add(hash, coins);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (output.script.isUnspendable())
|
if (output.script.isUnspendable())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!coins.has(prevout.index))
|
if (!coins.has(index))
|
||||||
coins.addOutput(prevout.index, output);
|
coins.addOutput(index, output);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -173,13 +176,14 @@ CoinView.prototype.addOutput = function addOutput(prevout, output) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
CoinView.prototype.spendOutput = function spendOutput(prevout) {
|
CoinView.prototype.spendOutput = function spendOutput(prevout) {
|
||||||
let coins = this.get(prevout.hash);
|
let {hash, index} = prevout;
|
||||||
|
let coins = this.get(hash);
|
||||||
let coin;
|
let coin;
|
||||||
|
|
||||||
if (!coins)
|
if (!coins)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
coin = coins.spend(prevout.index);
|
coin = coins.spend(index);
|
||||||
|
|
||||||
if (!coin)
|
if (!coin)
|
||||||
return false;
|
return false;
|
||||||
@ -196,12 +200,13 @@ CoinView.prototype.spendOutput = function spendOutput(prevout) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
CoinView.prototype.removeOutput = function removeOutput(prevout) {
|
CoinView.prototype.removeOutput = function removeOutput(prevout) {
|
||||||
let coins = this.get(prevout.hash);
|
let {hash, index} = prevout;
|
||||||
|
let coins = this.get(hash);
|
||||||
|
|
||||||
if (!coins)
|
if (!coins)
|
||||||
return false;
|
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) {
|
CoinView.prototype.hasEntry = function hasEntry(prevout) {
|
||||||
let coins = this.get(prevout.hash);
|
let {hash, index} = prevout;
|
||||||
|
let coins = this.get(hash);
|
||||||
|
|
||||||
if (!coins)
|
if (!coins)
|
||||||
return false;
|
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) {
|
CoinView.prototype.getEntry = function getEntry(prevout) {
|
||||||
let coins = this.get(prevout.hash);
|
let {hash, index} = prevout;
|
||||||
|
let coins = this.get(hash);
|
||||||
|
|
||||||
if (!coins)
|
if (!coins)
|
||||||
return;
|
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) {
|
CoinView.prototype.getOutput = function getOutput(prevout) {
|
||||||
let coins = this.get(prevout.hash);
|
let {hash, index} = prevout;
|
||||||
|
let coins = this.get(hash);
|
||||||
|
|
||||||
if (!coins)
|
if (!coins)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
return coins.getOutput(prevout.index);
|
return coins.getOutput(index);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user