check for double-spends in txdb.
This commit is contained in:
parent
d86031c073
commit
e8a70f9d7b
@ -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,31 +245,40 @@ TXPool.prototype._add = function add(tx, callback, force) {
|
|||||||
if (!result)
|
if (!result)
|
||||||
return next();
|
return next();
|
||||||
|
|
||||||
// Add orphan, if no parent transaction is yet known
|
self.getTX(input.prevout.hash, function(err, result) {
|
||||||
self.db.get(p + 'o/' + key, function(err, orphans) {
|
if (err)
|
||||||
if (err && err.type !== 'NotFoundError')
|
|
||||||
return done(err);
|
return done(err);
|
||||||
|
|
||||||
if (orphans) {
|
// Are we double-spending?
|
||||||
try {
|
if (result)
|
||||||
orphans = JSON.parse(orphans.toString('utf8'));
|
return done(new Error('Transaction is double-spending.'));
|
||||||
} catch (e) {
|
|
||||||
return done(e);
|
// Add orphan, if no parent transaction is yet known
|
||||||
|
self.db.get(p + 'o/' + key, function(err, orphans) {
|
||||||
|
if (err && err.type !== 'NotFoundError')
|
||||||
|
return done(err);
|
||||||
|
|
||||||
|
if (orphans) {
|
||||||
|
try {
|
||||||
|
orphans = JSON.parse(orphans.toString('utf8'));
|
||||||
|
} catch (e) {
|
||||||
|
return done(e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
orphans = [];
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
orphans = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
orphans.push({
|
orphans.push({
|
||||||
tx: tx.toExtended(true).toString('hex'),
|
tx: tx.toExtended(true).toString('hex'),
|
||||||
index: i
|
index: i
|
||||||
|
});
|
||||||
|
|
||||||
|
orphans = new Buffer(JSON.stringify(orphans), 'utf8');
|
||||||
|
|
||||||
|
batch.put(p + 'o/' + key, orphans);
|
||||||
|
|
||||||
|
return next();
|
||||||
});
|
});
|
||||||
|
|
||||||
orphans = new Buffer(JSON.stringify(orphans), 'utf8');
|
|
||||||
|
|
||||||
batch.put(p + 'o/' + key, orphans);
|
|
||||||
|
|
||||||
return next();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user