coins: refactor method names. add isUnspent.
This commit is contained in:
parent
0805babec1
commit
d57dac13e0
@ -186,7 +186,7 @@ CoinView.prototype.addOutput = function addOutput(prevout, output) {
|
|||||||
* @returns {CoinEntry|null}
|
* @returns {CoinEntry|null}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CoinView.prototype.spendOutput = function spendOutput(prevout) {
|
CoinView.prototype.spendEntry = function spendEntry(prevout) {
|
||||||
let {hash, index} = prevout;
|
let {hash, index} = prevout;
|
||||||
let coins = this.get(hash);
|
let coins = this.get(hash);
|
||||||
let coin;
|
let coin;
|
||||||
@ -210,7 +210,7 @@ CoinView.prototype.spendOutput = function spendOutput(prevout) {
|
|||||||
* @returns {CoinEntry|null}
|
* @returns {CoinEntry|null}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CoinView.prototype.removeOutput = function removeOutput(prevout) {
|
CoinView.prototype.removeEntry = function removeEntry(prevout) {
|
||||||
let {hash, index} = prevout;
|
let {hash, index} = prevout;
|
||||||
let coins = this.get(hash);
|
let coins = this.get(hash);
|
||||||
|
|
||||||
@ -252,6 +252,22 @@ CoinView.prototype.getEntry = function getEntry(prevout) {
|
|||||||
return coins.get(index);
|
return coins.get(index);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test whether an entry has been spent by prevout.
|
||||||
|
* @param {Outpoint} prevout
|
||||||
|
* @returns {Boolean}
|
||||||
|
*/
|
||||||
|
|
||||||
|
CoinView.prototype.isUnspent = function isUnspent(prevout) {
|
||||||
|
let {hash, index} = prevout;
|
||||||
|
let coins = this.get(hash);
|
||||||
|
|
||||||
|
if (!coins)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return coins.isUnspent(index);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a single coin by prevout.
|
* Get a single coin by prevout.
|
||||||
* @param {Outpoint} prevout
|
* @param {Outpoint} prevout
|
||||||
@ -333,6 +349,16 @@ CoinView.prototype.getEntryFor = function getEntryFor(input) {
|
|||||||
return this.getEntry(input.prevout);
|
return this.getEntry(input.prevout);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test whether an entry has been spent by input.
|
||||||
|
* @param {Input} input
|
||||||
|
* @returns {Boolean}
|
||||||
|
*/
|
||||||
|
|
||||||
|
CoinView.prototype.isUnspentFor = function isUnspentFor(input) {
|
||||||
|
return this.isUnspent(input.prevout);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a single coin by input.
|
* Get a single coin by input.
|
||||||
* @param {Input} input
|
* @param {Input} input
|
||||||
|
|||||||
@ -68,7 +68,7 @@ describe('Coins', function() {
|
|||||||
assert(coins);
|
assert(coins);
|
||||||
length = coins.outputs.size;
|
length = coins.outputs.size;
|
||||||
|
|
||||||
view.spendOutput(new Outpoint(hash, 0));
|
view.spendEntry(new Outpoint(hash, 0));
|
||||||
|
|
||||||
coins = view.get(hash);
|
coins = view.get(hash);
|
||||||
assert(coins);
|
assert(coins);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user