txdb: optimize.
This commit is contained in:
parent
9c94fae2a8
commit
817a6c3031
@ -215,7 +215,7 @@ TXDB.prototype.mapAddresses = function mapAddresses(address, callback) {
|
|||||||
* @param {Function} callback - Returns [Error, Buffer].
|
* @param {Function} callback - Returns [Error, Buffer].
|
||||||
*/
|
*/
|
||||||
|
|
||||||
TXDB.prototype._addOrphan = function _addOrphan(key, hash, index, callback) {
|
TXDB.prototype._addOrphan = function _addOrphan(key, outpoint, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var p;
|
var p;
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ TXDB.prototype._addOrphan = function _addOrphan(key, hash, index, callback) {
|
|||||||
if (buf)
|
if (buf)
|
||||||
p.writeBytes(buf);
|
p.writeBytes(buf);
|
||||||
|
|
||||||
bcoin.outpoint(hash, index).toRaw(p);
|
p.writeBytes(outpoint);
|
||||||
|
|
||||||
self.batch().put('o/' + key, p.render());
|
self.batch().put('o/' + key, p.render());
|
||||||
|
|
||||||
@ -631,8 +631,7 @@ TXDB.prototype._add = function add(tx, info, callback) {
|
|||||||
|
|
||||||
hash = tx.hash('hex');
|
hash = tx.hash('hex');
|
||||||
|
|
||||||
self.start();
|
batch = self.start();
|
||||||
batch = self.batch();
|
|
||||||
batch.put('t/' + hash, tx.toExtended());
|
batch.put('t/' + hash, tx.toExtended());
|
||||||
|
|
||||||
if (tx.ts === 0)
|
if (tx.ts === 0)
|
||||||
@ -655,7 +654,7 @@ TXDB.prototype._add = function add(tx, info, callback) {
|
|||||||
// Consume unspent money or add orphans
|
// Consume unspent money or add orphans
|
||||||
utils.forEachSerial(tx.inputs, function(input, next, i) {
|
utils.forEachSerial(tx.inputs, function(input, next, i) {
|
||||||
var prevout = input.prevout;
|
var prevout = input.prevout;
|
||||||
var key, address;
|
var key, address, outpoint;
|
||||||
|
|
||||||
if (tx.isCoinbase())
|
if (tx.isCoinbase())
|
||||||
return next();
|
return next();
|
||||||
@ -670,11 +669,12 @@ TXDB.prototype._add = function add(tx, info, callback) {
|
|||||||
key = prevout.hash + '/' + prevout.index;
|
key = prevout.hash + '/' + prevout.index;
|
||||||
|
|
||||||
// s/[outpoint-key] -> [spender-hash]|[spender-input-index]
|
// s/[outpoint-key] -> [spender-hash]|[spender-input-index]
|
||||||
batch.put('s/' + key, bcoin.outpoint.fromTX(tx, i).toRaw());
|
outpoint = bcoin.outpoint.fromTX(tx, i).toRaw();
|
||||||
|
batch.put('s/' + key, outpoint);
|
||||||
|
|
||||||
if (!input.coin) {
|
if (!input.coin) {
|
||||||
// Add orphan, if no parent transaction is yet known
|
// Add orphan, if no parent transaction is yet known
|
||||||
return self._addOrphan(key, hash, i, next);
|
return self._addOrphan(key, outpoint, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
updated = true;
|
updated = true;
|
||||||
@ -943,8 +943,7 @@ TXDB.prototype._confirm = function _confirm(tx, info, callback) {
|
|||||||
// and remove pending flag to mark as confirmed.
|
// and remove pending flag to mark as confirmed.
|
||||||
assert(tx.height >= 0);
|
assert(tx.height >= 0);
|
||||||
|
|
||||||
self.start();
|
batch = self.start();
|
||||||
batch = self.batch();
|
|
||||||
batch.put('t/' + hash, tx.toExtended());
|
batch.put('t/' + hash, tx.toExtended());
|
||||||
|
|
||||||
batch.del('p/' + hash);
|
batch.del('p/' + hash);
|
||||||
@ -1129,7 +1128,7 @@ TXDB.prototype._remove = function remove(tx, info, callback) {
|
|||||||
coin = input.coin.toRaw();
|
coin = input.coin.toRaw();
|
||||||
|
|
||||||
batch.put('c/' + key, coin);
|
batch.put('c/' + key, coin);
|
||||||
batch.del('d/' + tx.hash('hex') + '/' + pad32(i));
|
batch.del('d/' + hash + '/' + pad32(i));
|
||||||
batch.del('s/' + key);
|
batch.del('s/' + key);
|
||||||
batch.del('o/' + key);
|
batch.del('o/' + key);
|
||||||
|
|
||||||
@ -1232,8 +1231,6 @@ TXDB.prototype._unconfirm = function unconfirm(tx, info, callback, force) {
|
|||||||
hash = tx.hash('hex');
|
hash = tx.hash('hex');
|
||||||
height = tx.height;
|
height = tx.height;
|
||||||
|
|
||||||
batch = this.db.batch();
|
|
||||||
|
|
||||||
if (height !== -1)
|
if (height !== -1)
|
||||||
return callback(null, false, info);
|
return callback(null, false, info);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user