check for double-spends in txdb.

This commit is contained in:
Christopher Jeffrey 2016-03-02 03:03:14 -08:00
parent d86031c073
commit e8a70f9d7b

View File

@ -237,8 +237,6 @@ TXPool.prototype._add = function add(tx, callback, force) {
return next(); return next();
} }
// TODO: Check for double-spend by doing self.getTX(input.prevout.hash)
// Only add orphans if this input is ours. // Only add orphans if this input is ours.
self._hasAddress(input.getAddress(), function(err, result) { self._hasAddress(input.getAddress(), function(err, result) {
if (err) if (err)
@ -247,6 +245,14 @@ TXPool.prototype._add = function add(tx, callback, force) {
if (!result) if (!result)
return next(); return next();
self.getTX(input.prevout.hash, function(err, result) {
if (err)
return done(err);
// Are we double-spending?
if (result)
return done(new Error('Transaction is double-spending.'));
// Add orphan, if no parent transaction is yet known // Add orphan, if no parent transaction is yet known
self.db.get(p + 'o/' + key, function(err, orphans) { self.db.get(p + 'o/' + key, function(err, orphans) {
if (err && err.type !== 'NotFoundError') if (err && err.type !== 'NotFoundError')
@ -275,6 +281,7 @@ TXPool.prototype._add = function add(tx, callback, force) {
}); });
}); });
}); });
});
}, function(err) { }, function(err) {
if (err) if (err)
return done(err); return done(err);