diff --git a/lib/bcoin/mempool.js b/lib/bcoin/mempool.js index 121ef3fd..37b08775 100644 --- a/lib/bcoin/mempool.js +++ b/lib/bcoin/mempool.js @@ -504,6 +504,25 @@ Mempool.prototype.hasTX = function hasTX(hash, callback) { return this.tx.hasTX(hash, callback); }; +/** + * Test the mempool to see if it contains a transaction or an orphan. + * @param {Hash} hash + * @param {Function} callback - Returns [Error, Boolean]. + */ + +Mempool.prototype.hasAny = function hasAny(hash, callback) { + var self = this; + return this.hasTX(hash, function(err, exists) { + if (err) + return callback(err); + + if (exists) + return callback(null, true); + + self.hasOrphan(hash, callback); + }); +}; + /** * Add a transaction to the mempool. Note that this * will lock the mempool until the transaction is @@ -998,7 +1017,7 @@ Mempool.prototype.getOrphan = function getOrphan(orphanHash, callback) { this.db.get('O/' + orphanHash, function(err, orphan) { if (err && err.type !== 'NotFoundError') - return next(err); + return callback(err); if (!orphan) return callback(); @@ -1019,11 +1038,11 @@ Mempool.prototype.getOrphan = function getOrphan(orphanHash, callback) { */ Mempool.prototype.hasOrphan = function hasOrphan(orphanHash, callback) { - return this.getOrphan(orphanHash, function(err, tx) { - if (err) + this.db.get('O/' + orphanHash, function(err, orphan) { + if (err && err.type !== 'NotFoundError') return callback(err); - return callback(null, tx != null); + return callback(null, orphan != null); }); }; diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index d390cd59..aaa57035 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -1616,7 +1616,7 @@ Pool.prototype.getData = function getData(peer, type, hash, options, callback) { if (type === this.tx.type) { if (!this.mempool) return utils.asyncify(done)(null, false); - return this.mempool.hasTX(hash, done); + return this.mempool.hasAny(hash, done); } return this.chain.has(hash, done); }