chaindb: alter hasCoins.
This commit is contained in:
parent
82bdd73f05
commit
a1601b8f3a
@ -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;
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -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',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user