optimize more.

This commit is contained in:
Christopher Jeffrey 2016-06-12 10:01:19 -07:00
parent 3e7f1cea42
commit f95f3e929b
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 4 additions and 30 deletions

View File

@ -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);

View File

@ -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) {