txdb: reject rbf.
This commit is contained in:
parent
acaf0600e7
commit
9ed439b60c
@ -176,6 +176,9 @@ layout.txdb = {
|
|||||||
},
|
},
|
||||||
Cc: function Cc(key) {
|
Cc: function Cc(key) {
|
||||||
return this.ihii(key);
|
return this.ihii(key);
|
||||||
|
},
|
||||||
|
r: function r(hash) {
|
||||||
|
return this.ha('r', hash);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -189,6 +189,9 @@ var layout = {
|
|||||||
},
|
},
|
||||||
Cc: function Cc(key) {
|
Cc: function Cc(key) {
|
||||||
return layout.ihii(key);
|
return layout.ihii(key);
|
||||||
|
},
|
||||||
|
r: function r(hash) {
|
||||||
|
return layout.ha(0x72, hash);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -688,18 +691,30 @@ TXDB.prototype.add = co(function* add(tx) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
TXDB.prototype._add = co(function* add(tx, info) {
|
TXDB.prototype._add = co(function* add(tx, info) {
|
||||||
var hash, path, account;
|
var hash = tx.hash('hex');
|
||||||
|
var path, account;
|
||||||
var i, result, input, output, coin;
|
var i, result, input, output, coin;
|
||||||
var prevout, key, spender, raw;
|
var prevout, key, spender, raw;
|
||||||
|
|
||||||
assert(!tx.mutable, 'Cannot add mutable TX to wallet.');
|
assert(!tx.mutable, 'Cannot add mutable TX to wallet.');
|
||||||
|
|
||||||
if (tx.height === -1) {
|
if (tx.height === -1) {
|
||||||
|
// We ignore double spends from the mempool.
|
||||||
if (yield this.isDoubleSpend(tx))
|
if (yield this.isDoubleSpend(tx))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// We ignore any unconfirmed txs
|
||||||
|
// that are replace-by-fee.
|
||||||
|
if (yield this.isRBF(tx)) {
|
||||||
|
this.put(layout.r(hash), DUMMY);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// This potentially removes double-spenders.
|
// This potentially removes double-spenders.
|
||||||
yield this.removeConflicts(tx, info);
|
yield this.removeConflicts(tx, info);
|
||||||
|
|
||||||
|
// Delete the replace-by-fee record.
|
||||||
|
this.del(layout.r(hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to confirm tx before adding it.
|
// Attempt to confirm tx before adding it.
|
||||||
@ -709,8 +724,6 @@ TXDB.prototype._add = co(function* add(tx, info) {
|
|||||||
if (result)
|
if (result)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
hash = tx.hash('hex');
|
|
||||||
|
|
||||||
this.put(layout.t(hash), tx.toExtended());
|
this.put(layout.t(hash), tx.toExtended());
|
||||||
|
|
||||||
if (tx.height === -1)
|
if (tx.height === -1)
|
||||||
@ -903,6 +916,29 @@ TXDB.prototype.isDoubleSpend = co(function* isDoubleSpend(tx) {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test an entire transaction to see
|
||||||
|
* if any of its outpoints are replace by fee.
|
||||||
|
* @param {TX} tx
|
||||||
|
* @returns {Promise} - Returns Boolean.
|
||||||
|
*/
|
||||||
|
|
||||||
|
TXDB.prototype.isRBF = co(function* isRBF(tx) {
|
||||||
|
var i, input, prevout;
|
||||||
|
|
||||||
|
if (tx.isRBF())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
for (i = 0; i < tx.inputs.length; i++) {
|
||||||
|
input = tx.inputs[i];
|
||||||
|
prevout = input.prevout;
|
||||||
|
if (yield this.has(layout.r(prevout.hash)))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test a whether a coin has been spent.
|
* Test a whether a coin has been spent.
|
||||||
* @param {Hash} hash
|
* @param {Hash} hash
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user