coins: refactor method names. add isUnspent.

This commit is contained in:
Christopher Jeffrey 2017-07-17 21:47:32 -07:00
parent 0805babec1
commit d57dac13e0
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 29 additions and 3 deletions

View File

@ -186,7 +186,7 @@ CoinView.prototype.addOutput = function addOutput(prevout, output) {
* @returns {CoinEntry|null}
*/
CoinView.prototype.spendOutput = function spendOutput(prevout) {
CoinView.prototype.spendEntry = function spendEntry(prevout) {
let {hash, index} = prevout;
let coins = this.get(hash);
let coin;
@ -210,7 +210,7 @@ CoinView.prototype.spendOutput = function spendOutput(prevout) {
* @returns {CoinEntry|null}
*/
CoinView.prototype.removeOutput = function removeOutput(prevout) {
CoinView.prototype.removeEntry = function removeEntry(prevout) {
let {hash, index} = prevout;
let coins = this.get(hash);
@ -252,6 +252,22 @@ CoinView.prototype.getEntry = function getEntry(prevout) {
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.
* @param {Outpoint} prevout
@ -333,6 +349,16 @@ CoinView.prototype.getEntryFor = function getEntryFor(input) {
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.
* @param {Input} input

View File

@ -68,7 +68,7 @@ describe('Coins', function() {
assert(coins);
length = coins.outputs.size;
view.spendOutput(new Outpoint(hash, 0));
view.spendEntry(new Outpoint(hash, 0));
coins = view.get(hash);
assert(coins);