txdb: make ps constant.
This commit is contained in:
parent
4893c7dba5
commit
d26787b389
@ -137,9 +137,7 @@ TX.prototype.fromOptions = function fromOptions(options) {
|
|||||||
|
|
||||||
if (options.ps != null) {
|
if (options.ps != null) {
|
||||||
assert(utils.isNumber(options.ps));
|
assert(utils.isNumber(options.ps));
|
||||||
this.ps = this.ts === 0
|
this.ps = options.ps;
|
||||||
? options.ps
|
|
||||||
: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.height != null) {
|
if (options.height != null) {
|
||||||
@ -180,7 +178,6 @@ TX.prototype.setBlock = function setBlock(block, index) {
|
|||||||
this.block = block.hash('hex');
|
this.block = block.hash('hex');
|
||||||
this.height = block.height;
|
this.height = block.height;
|
||||||
this.index = index == null ? -1 : index;
|
this.index = index == null ? -1 : index;
|
||||||
this.ps = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -192,7 +189,6 @@ TX.prototype.unsetBlock = function unsetBlock() {
|
|||||||
this.block = null;
|
this.block = null;
|
||||||
this.height = -1;
|
this.height = -1;
|
||||||
this.index = -1;
|
this.index = -1;
|
||||||
this.ps = utils.now();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -458,25 +458,22 @@ TXDB.prototype._add = function add(tx, map, callback, force) {
|
|||||||
|
|
||||||
batch.put('t/' + hash, tx.toExtended());
|
batch.put('t/' + hash, tx.toExtended());
|
||||||
|
|
||||||
if (tx.ts === 0) {
|
if (tx.ts === 0)
|
||||||
batch.put('p/' + hash, DUMMY);
|
batch.put('p/' + hash, DUMMY);
|
||||||
batch.put('m/' + pad32(tx.ps) + '/' + hash, DUMMY);
|
else
|
||||||
} else {
|
|
||||||
batch.put('h/' + pad32(tx.height) + '/' + hash, DUMMY);
|
batch.put('h/' + pad32(tx.height) + '/' + hash, DUMMY);
|
||||||
batch.put('m/' + pad32(tx.ts) + '/' + hash, DUMMY);
|
|
||||||
}
|
batch.put('m/' + pad32(tx.ps) + '/' + hash, DUMMY);
|
||||||
|
|
||||||
for (i = 0; i < map.accounts.length; i++) {
|
for (i = 0; i < map.accounts.length; i++) {
|
||||||
path = map.accounts[i];
|
path = map.accounts[i];
|
||||||
id = path.id + '/' + path.account;
|
id = path.id + '/' + path.account;
|
||||||
batch.put('T/' + id + '/' + hash, DUMMY);
|
batch.put('T/' + id + '/' + hash, DUMMY);
|
||||||
if (tx.ts === 0) {
|
if (tx.ts === 0)
|
||||||
batch.put('P/' + id + '/' + hash, DUMMY);
|
batch.put('P/' + id + '/' + hash, DUMMY);
|
||||||
batch.put('M/' + id + '/' + pad32(tx.ps) + '/' + hash, DUMMY);
|
else
|
||||||
} else {
|
|
||||||
batch.put('H/' + id + '/' + pad32(tx.height) + '/' + hash, DUMMY);
|
batch.put('H/' + id + '/' + pad32(tx.height) + '/' + hash, DUMMY);
|
||||||
batch.put('M/' + id + '/' + pad32(tx.ts) + '/' + hash, DUMMY);
|
batch.put('M/' + id + '/' + pad32(tx.ps) + '/' + hash, DUMMY);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Consume unspent money or add orphans
|
// Consume unspent money or add orphans
|
||||||
@ -875,22 +872,17 @@ TXDB.prototype._confirm = function _confirm(tx, map, callback, force) {
|
|||||||
// Tricky - update the tx and coin in storage,
|
// Tricky - update the tx and coin in storage,
|
||||||
// and remove pending flag to mark as confirmed.
|
// and remove pending flag to mark as confirmed.
|
||||||
assert(tx.height >= 0);
|
assert(tx.height >= 0);
|
||||||
assert(existing.ps > 0);
|
|
||||||
|
|
||||||
batch.put('t/' + hash, tx.toExtended());
|
batch.put('t/' + hash, tx.toExtended());
|
||||||
|
|
||||||
batch.del('p/' + hash);
|
batch.del('p/' + hash);
|
||||||
batch.put('h/' + pad32(tx.height) + '/' + hash, DUMMY);
|
batch.put('h/' + pad32(tx.height) + '/' + hash, DUMMY);
|
||||||
batch.del('m/' + pad32(existing.ps) + '/' + hash);
|
|
||||||
batch.put('m/' + pad32(tx.ts) + '/' + hash, DUMMY);
|
|
||||||
|
|
||||||
for (i = 0; i < map.accounts.length; i++) {
|
for (i = 0; i < map.accounts.length; i++) {
|
||||||
path = map.accounts[i];
|
path = map.accounts[i];
|
||||||
id = path.id + '/' + path.account;
|
id = path.id + '/' + path.account;
|
||||||
batch.del('P/' + id + '/' + hash);
|
batch.del('P/' + id + '/' + hash);
|
||||||
batch.put('H/' + id + '/' + pad32(tx.height) + '/' + hash, DUMMY);
|
batch.put('H/' + id + '/' + pad32(tx.height) + '/' + hash, DUMMY);
|
||||||
batch.del('M/' + id + '/' + pad32(existing.ps) + '/' + hash);
|
|
||||||
batch.put('M/' + id + '/' + pad32(tx.ts) + '/' + hash, DUMMY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.forEachSerial(tx.outputs, function(output, next, i) {
|
utils.forEachSerial(tx.outputs, function(output, next, i) {
|
||||||
@ -1020,25 +1012,22 @@ TXDB.prototype._remove = function remove(tx, map, callback, force) {
|
|||||||
|
|
||||||
batch.del('t/' + hash);
|
batch.del('t/' + hash);
|
||||||
|
|
||||||
if (tx.ts === 0) {
|
if (tx.ts === 0)
|
||||||
batch.del('p/' + hash);
|
batch.del('p/' + hash);
|
||||||
batch.del('m/' + pad32(tx.ps) + '/' + hash);
|
else
|
||||||
} else {
|
|
||||||
batch.del('h/' + pad32(tx.height) + '/' + hash);
|
batch.del('h/' + pad32(tx.height) + '/' + hash);
|
||||||
batch.del('m/' + pad32(tx.ts) + '/' + hash);
|
|
||||||
}
|
batch.del('m/' + pad32(tx.ps) + '/' + hash);
|
||||||
|
|
||||||
for (i = 0; i < map.accounts.length; i++) {
|
for (i = 0; i < map.accounts.length; i++) {
|
||||||
path = map.accounts[i];
|
path = map.accounts[i];
|
||||||
id = path.id + '/' + path.account;
|
id = path.id + '/' + path.account;
|
||||||
batch.del('T/' + id + '/' + hash);
|
batch.del('T/' + id + '/' + hash);
|
||||||
if (tx.ts === 0) {
|
if (tx.ts === 0)
|
||||||
batch.del('P/' + id + '/' + hash);
|
batch.del('P/' + id + '/' + hash);
|
||||||
batch.del('M/' + id + '/' + pad32(tx.ps) + '/' + hash);
|
else
|
||||||
} else {
|
|
||||||
batch.del('H/' + id + '/' + pad32(tx.height) + '/' + hash);
|
batch.del('H/' + id + '/' + pad32(tx.height) + '/' + hash);
|
||||||
batch.del('M/' + id + '/' + pad32(tx.ts) + '/' + hash);
|
batch.del('M/' + id + '/' + pad32(tx.ps) + '/' + hash);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fillHistory(tx, function(err) {
|
this.fillHistory(tx, function(err) {
|
||||||
@ -1155,7 +1144,7 @@ TXDB.prototype.unconfirm = function unconfirm(hash, callback, force) {
|
|||||||
|
|
||||||
TXDB.prototype._unconfirm = function unconfirm(tx, map, callback, force) {
|
TXDB.prototype._unconfirm = function unconfirm(tx, map, callback, force) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var batch, unlock, hash, height, ts, i, path, id;
|
var batch, unlock, hash, height, i, path, id;
|
||||||
|
|
||||||
unlock = this._lock(unconfirm, [tx, map, callback], force);
|
unlock = this._lock(unconfirm, [tx, map, callback], force);
|
||||||
|
|
||||||
@ -1166,7 +1155,6 @@ TXDB.prototype._unconfirm = function unconfirm(tx, map, callback, force) {
|
|||||||
|
|
||||||
hash = tx.hash('hex');
|
hash = tx.hash('hex');
|
||||||
height = tx.height;
|
height = tx.height;
|
||||||
ts = tx.ts;
|
|
||||||
|
|
||||||
batch = this.db.batch();
|
batch = this.db.batch();
|
||||||
|
|
||||||
@ -1174,7 +1162,6 @@ TXDB.prototype._unconfirm = function unconfirm(tx, map, callback, force) {
|
|||||||
return callback(null, false, map);
|
return callback(null, false, map);
|
||||||
|
|
||||||
tx.height = -1;
|
tx.height = -1;
|
||||||
tx.ps = utils.now();
|
|
||||||
tx.ts = 0;
|
tx.ts = 0;
|
||||||
tx.index = -1;
|
tx.index = -1;
|
||||||
tx.block = null;
|
tx.block = null;
|
||||||
@ -1183,16 +1170,12 @@ TXDB.prototype._unconfirm = function unconfirm(tx, map, callback, force) {
|
|||||||
|
|
||||||
batch.put('p/' + hash, DUMMY);
|
batch.put('p/' + hash, DUMMY);
|
||||||
batch.del('h/' + pad32(height) + '/' + hash);
|
batch.del('h/' + pad32(height) + '/' + hash);
|
||||||
batch.del('m/' + pad32(ts) + '/' + hash);
|
|
||||||
batch.put('m/' + pad32(tx.ps) + '/' + hash, DUMMY);
|
|
||||||
|
|
||||||
for (i = 0; i < map.accounts.length; i++) {
|
for (i = 0; i < map.accounts.length; i++) {
|
||||||
path = map.accounts[i];
|
path = map.accounts[i];
|
||||||
id = path.id + '/' + path.account;
|
id = path.id + '/' + path.account;
|
||||||
batch.put('P/' + id + '/' + hash, DUMMY);
|
batch.put('P/' + id + '/' + hash, DUMMY);
|
||||||
batch.del('H/' + id + '/' + pad32(height) + '/' + hash);
|
batch.del('H/' + id + '/' + pad32(height) + '/' + hash);
|
||||||
batch.del('M/' + id + '/' + pad32(ts) + '/' + hash);
|
|
||||||
batch.put('M/' + id + '/' + pad32(tx.ps) + '/' + hash, DUMMY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.forEachSerial(tx.outputs, function(output, next, i) {
|
utils.forEachSerial(tx.outputs, function(output, next, i) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user