check orphan txs before requesting.
This commit is contained in:
parent
3326078694
commit
1bf606a22d
@ -504,6 +504,25 @@ Mempool.prototype.hasTX = function hasTX(hash, callback) {
|
|||||||
return this.tx.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
|
* Add a transaction to the mempool. Note that this
|
||||||
* will lock the mempool until the transaction is
|
* 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) {
|
this.db.get('O/' + orphanHash, function(err, orphan) {
|
||||||
if (err && err.type !== 'NotFoundError')
|
if (err && err.type !== 'NotFoundError')
|
||||||
return next(err);
|
return callback(err);
|
||||||
|
|
||||||
if (!orphan)
|
if (!orphan)
|
||||||
return callback();
|
return callback();
|
||||||
@ -1019,11 +1038,11 @@ Mempool.prototype.getOrphan = function getOrphan(orphanHash, callback) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Mempool.prototype.hasOrphan = function hasOrphan(orphanHash, callback) {
|
Mempool.prototype.hasOrphan = function hasOrphan(orphanHash, callback) {
|
||||||
return this.getOrphan(orphanHash, function(err, tx) {
|
this.db.get('O/' + orphanHash, function(err, orphan) {
|
||||||
if (err)
|
if (err && err.type !== 'NotFoundError')
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
return callback(null, tx != null);
|
return callback(null, orphan != null);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1616,7 +1616,7 @@ Pool.prototype.getData = function getData(peer, type, hash, options, callback) {
|
|||||||
if (type === this.tx.type) {
|
if (type === this.tx.type) {
|
||||||
if (!this.mempool)
|
if (!this.mempool)
|
||||||
return utils.asyncify(done)(null, false);
|
return utils.asyncify(done)(null, false);
|
||||||
return this.mempool.hasTX(hash, done);
|
return this.mempool.hasAny(hash, done);
|
||||||
}
|
}
|
||||||
return this.chain.has(hash, done);
|
return this.chain.has(hash, done);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user