chaindb: alter hasCoins.

This commit is contained in:
Christopher Jeffrey 2017-07-03 17:39:20 -07:00
parent 82bdd73f05
commit a1601b8f3a
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 10 additions and 15 deletions

View File

@ -548,7 +548,7 @@ Chain.prototype.verifyDuplicates = async function verifyDuplicates(block, prev,
// Check all transactions.
for (let tx of block.txs) {
let result = await this.db.hasCoins(tx.hash());
let result = await this.db.hasCoins(tx);
if (result) {
let height = prev.height + 1;

View File

@ -894,22 +894,17 @@ ChainDB.prototype.getCoin = async function getCoin(hash, index) {
/**
* Check whether coins are still unspent. Necessary for bip30.
* @see https://bitcointalk.org/index.php?topic=67738.0
* @param {Hash} hash
* @param {TX} tx
* @returns {Promise} - Returns Boolean.
*/
ChainDB.prototype.hasCoins = async function hasCoins(hash) {
let iter = this.db.iterator({
gte: layout.c(hash, 0x00000000),
lte: layout.c(hash, 0xffffffff)
});
if (!(await iter.next()))
return false;
await iter.end();
return true;
ChainDB.prototype.hasCoins = async function hasCoins(tx) {
for (let i = 0; i < tx.outputs.length; i++) {
let key = layout.c(tx.hash(), i);
if (await this.db.has(key))
return true;
}
return false;
};
/**

View File

@ -803,7 +803,7 @@ Mempool.prototype.insertTX = async function insertTX(tx, id) {
// We can test whether this is an
// non-fully-spent transaction on
// the chain.
if (await this.chain.db.hasCoins(hash)) {
if (await this.chain.db.hasCoins(tx)) {
throw new VerifyError(tx,
'alreadyknown',
'txn-already-known',