diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index 073e7e35..40d5da52 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -781,7 +781,7 @@ Chain.prototype._findDuplicates = function _findDuplicates(block, prev, callback var hash = tx.hash('hex'); // BIP30 - Ensure there are no duplicate txids - self.db.isUnspentTX(hash, function(err, result) { + self.db.hasCoins(hash, function(err, result) { if (err) return next(err); diff --git a/lib/bcoin/chaindb.js b/lib/bcoin/chaindb.js index 4eab67fe..98eaf221 100644 --- a/lib/bcoin/chaindb.js +++ b/lib/bcoin/chaindb.js @@ -1479,40 +1479,14 @@ ChainDB.prototype.getBlock = function getBlock(hash, callback) { }; /** - * Check whether a transaction is unspent (i.e. not yet _fully_ spent). + * Check whether coins are still unspent. Necessary for bip30. * @see https://bitcointalk.org/index.php?topic=67738.0 * @param {Hash} hash * @param {Function} callback - Returns [Error, Boolean]. */ -ChainDB.prototype.isUnspentTX = function isUnspentTX(hash, callback) { - if (this.options.spv) - return callback(null, false); - - return this.isSpentTX(hash, function(err, spent) { - if (err) - return callback(err); - - return callback(null, !spent); - }); -}; - -/** - * Check whether a transaction is _fully_ spent. - * @see https://bitcointalk.org/index.php?topic=67738.0 - * @param {Hash} hash - * @param {Function} callback - Returns [Error, Boolean]. - */ - -ChainDB.prototype.isSpentTX = function isSpentTX(hash, callback) { - if (hash.hash) - hash = hash.hash('hex'); - - this.getCoins(hash, function(err, coins) { - if (err) - return callback(err); - return callback(null, !coins); - }); +ChainDB.prototype.hasCoins = function hasCoins(hash, callback) { + this.db.has(layout.c(hash), callback); }; ChainDB.prototype._pruneBlock = function _pruneBlock(block, batch, callback) {