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.
|
// Check all transactions.
|
||||||
for (let tx of block.txs) {
|
for (let tx of block.txs) {
|
||||||
let result = await this.db.hasCoins(tx.hash());
|
let result = await this.db.hasCoins(tx);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
let height = prev.height + 1;
|
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.
|
* Check whether coins are still unspent. Necessary for bip30.
|
||||||
* @see https://bitcointalk.org/index.php?topic=67738.0
|
* @see https://bitcointalk.org/index.php?topic=67738.0
|
||||||
* @param {Hash} hash
|
* @param {TX} tx
|
||||||
* @returns {Promise} - Returns Boolean.
|
* @returns {Promise} - Returns Boolean.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ChainDB.prototype.hasCoins = async function hasCoins(hash) {
|
ChainDB.prototype.hasCoins = async function hasCoins(tx) {
|
||||||
let iter = this.db.iterator({
|
for (let i = 0; i < tx.outputs.length; i++) {
|
||||||
gte: layout.c(hash, 0x00000000),
|
let key = layout.c(tx.hash(), i);
|
||||||
lte: layout.c(hash, 0xffffffff)
|
if (await this.db.has(key))
|
||||||
});
|
return true;
|
||||||
|
}
|
||||||
if (!(await iter.next()))
|
return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
await iter.end();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -803,7 +803,7 @@ Mempool.prototype.insertTX = async function insertTX(tx, id) {
|
|||||||
// We can test whether this is an
|
// We can test whether this is an
|
||||||
// non-fully-spent transaction on
|
// non-fully-spent transaction on
|
||||||
// the chain.
|
// the chain.
|
||||||
if (await this.chain.db.hasCoins(hash)) {
|
if (await this.chain.db.hasCoins(tx)) {
|
||||||
throw new VerifyError(tx,
|
throw new VerifyError(tx,
|
||||||
'alreadyknown',
|
'alreadyknown',
|
||||||
'txn-already-known',
|
'txn-already-known',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user