txdb: cleanup.
This commit is contained in:
parent
0bf384b84a
commit
a80c438995
@ -693,12 +693,12 @@ TXDB.prototype.removeCredit = function removeCredit(credit, path) {
|
|||||||
* Spend credit.
|
* Spend credit.
|
||||||
* @param {Credit} credit
|
* @param {Credit} credit
|
||||||
* @param {TX} tx
|
* @param {TX} tx
|
||||||
* @param {Number} i
|
* @param {Number} index
|
||||||
*/
|
*/
|
||||||
|
|
||||||
TXDB.prototype.spendCredit = function spendCredit(credit, tx, i) {
|
TXDB.prototype.spendCredit = function spendCredit(credit, tx, index) {
|
||||||
var prevout = tx.inputs[i].prevout;
|
var prevout = tx.inputs[index].prevout;
|
||||||
var spender = Outpoint.fromTX(tx, i);
|
var spender = Outpoint.fromTX(tx, index);
|
||||||
this.put(layout.s(prevout.hash, prevout.index), spender.toRaw());
|
this.put(layout.s(prevout.hash, prevout.index), spender.toRaw());
|
||||||
this.put(layout.d(spender.hash, spender.index), credit.coin.toRaw());
|
this.put(layout.d(spender.hash, spender.index), credit.coin.toRaw());
|
||||||
};
|
};
|
||||||
@ -706,12 +706,12 @@ TXDB.prototype.spendCredit = function spendCredit(credit, tx, i) {
|
|||||||
/**
|
/**
|
||||||
* Unspend credit.
|
* Unspend credit.
|
||||||
* @param {TX} tx
|
* @param {TX} tx
|
||||||
* @param {Number} i
|
* @param {Number} index
|
||||||
*/
|
*/
|
||||||
|
|
||||||
TXDB.prototype.unspendCredit = function unspendCredit(tx, i) {
|
TXDB.prototype.unspendCredit = function unspendCredit(tx, index) {
|
||||||
var prevout = tx.inputs[i].prevout;
|
var prevout = tx.inputs[index].prevout;
|
||||||
var spender = Outpoint.fromTX(tx, i);
|
var spender = Outpoint.fromTX(tx, index);
|
||||||
this.del(layout.s(prevout.hash, prevout.index));
|
this.del(layout.s(prevout.hash, prevout.index));
|
||||||
this.del(layout.d(spender.hash, spender.index));
|
this.del(layout.d(spender.hash, spender.index));
|
||||||
};
|
};
|
||||||
@ -719,37 +719,37 @@ TXDB.prototype.unspendCredit = function unspendCredit(tx, i) {
|
|||||||
/**
|
/**
|
||||||
* Write input record.
|
* Write input record.
|
||||||
* @param {TX} tx
|
* @param {TX} tx
|
||||||
* @param {Number} i
|
* @param {Number} index
|
||||||
*/
|
*/
|
||||||
|
|
||||||
TXDB.prototype.writeInput = function writeInput(tx, i) {
|
TXDB.prototype.writeInput = function writeInput(tx, index) {
|
||||||
var prevout = tx.inputs[i].prevout;
|
var prevout = tx.inputs[index].prevout;
|
||||||
var spender = Outpoint.fromTX(tx, i);
|
var spender = Outpoint.fromTX(tx, index);
|
||||||
this.put(layout.s(prevout.hash, prevout.index), spender.toRaw());
|
this.put(layout.s(prevout.hash, prevout.index), spender.toRaw());
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove input record.
|
* Remove input record.
|
||||||
* @param {TX} tx
|
* @param {TX} tx
|
||||||
* @param {Number} i
|
* @param {Number} index
|
||||||
*/
|
*/
|
||||||
|
|
||||||
TXDB.prototype.removeInput = function removeInput(tx, i) {
|
TXDB.prototype.removeInput = function removeInput(tx, index) {
|
||||||
var prevout = tx.inputs[i].prevout;
|
var prevout = tx.inputs[index].prevout;
|
||||||
this.del(layout.s(prevout.hash, prevout.index));
|
this.del(layout.s(prevout.hash, prevout.index));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve orphan input.
|
* Resolve orphan input.
|
||||||
* @param {TX} tx
|
* @param {TX} tx
|
||||||
* @param {Number} i
|
* @param {Number} index
|
||||||
* @param {Path} path
|
* @param {Path} path
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
TXDB.prototype.resolveInput = co(function* resolveInput(tx, i, path) {
|
TXDB.prototype.resolveInput = co(function* resolveInput(tx, index, path) {
|
||||||
var hash = tx.hash('hex');
|
var hash = tx.hash('hex');
|
||||||
var spent = yield this.getSpent(hash, i);
|
var spent = yield this.getSpent(hash, index);
|
||||||
var stx, credit;
|
var stx, credit;
|
||||||
|
|
||||||
if (!spent)
|
if (!spent)
|
||||||
@ -766,7 +766,7 @@ TXDB.prototype.resolveInput = co(function* resolveInput(tx, i, path) {
|
|||||||
assert(stx);
|
assert(stx);
|
||||||
|
|
||||||
// Crete the credit and add the undo coin.
|
// Crete the credit and add the undo coin.
|
||||||
credit = Credit.fromTX(tx, i);
|
credit = Credit.fromTX(tx, index);
|
||||||
|
|
||||||
this.spendCredit(credit, stx, spent.index);
|
this.spendCredit(credit, stx, spent.index);
|
||||||
|
|
||||||
@ -1470,6 +1470,7 @@ TXDB.prototype.disconnect = co(function* disconnect(tx) {
|
|||||||
|
|
||||||
credit = yield this.getCredit(hash, i);
|
credit = yield this.getCredit(hash, i);
|
||||||
|
|
||||||
|
// Potentially update undo coin height.
|
||||||
if (!credit) {
|
if (!credit) {
|
||||||
yield this.updateSpentCoin(tx, i);
|
yield this.updateSpentCoin(tx, i);
|
||||||
continue;
|
continue;
|
||||||
@ -2446,8 +2447,8 @@ TXDB.prototype.hasSpentCoin = function hasSpentCoin(spent) {
|
|||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
TXDB.prototype.updateSpentCoin = co(function* updateSpentCoin(tx, i) {
|
TXDB.prototype.updateSpentCoin = co(function* updateSpentCoin(tx, index) {
|
||||||
var prevout = Outpoint.fromTX(tx, i);
|
var prevout = Outpoint.fromTX(tx, index);
|
||||||
var spent = yield this.getSpent(prevout.hash, prevout.index);
|
var spent = yield this.getSpent(prevout.hash, prevout.index);
|
||||||
var coin;
|
var coin;
|
||||||
|
|
||||||
@ -2849,12 +2850,12 @@ Credit.prototype.toRaw = function toRaw(writer) {
|
|||||||
* Inject properties from tx object.
|
* Inject properties from tx object.
|
||||||
* @private
|
* @private
|
||||||
* @param {TX} tx
|
* @param {TX} tx
|
||||||
* @param {Number} i
|
* @param {Number} index
|
||||||
* @returns {Credit}
|
* @returns {Credit}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Credit.prototype.fromTX = function fromTX(tx, i) {
|
Credit.prototype.fromTX = function fromTX(tx, index) {
|
||||||
this.coin.fromTX(tx, i);
|
this.coin.fromTX(tx, index);
|
||||||
this.spent = false;
|
this.spent = false;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
@ -2862,12 +2863,12 @@ Credit.prototype.fromTX = function fromTX(tx, i) {
|
|||||||
/**
|
/**
|
||||||
* Instantiate credit from transaction.
|
* Instantiate credit from transaction.
|
||||||
* @param {TX} tx
|
* @param {TX} tx
|
||||||
* @param {Number} i
|
* @param {Number} index
|
||||||
* @returns {Credit}
|
* @returns {Credit}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Credit.fromTX = function fromTX(tx, i) {
|
Credit.fromTX = function fromTX(tx, index) {
|
||||||
return new Credit().fromTX(tx, i);
|
return new Credit().fromTX(tx, index);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3059,10 +3060,10 @@ DetailsMember.prototype.toJSON = function toJSON(network) {
|
|||||||
* Helpers
|
* Helpers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function Orphan(tx, i) {
|
function Orphan(tx, index) {
|
||||||
this.tx = tx;
|
this.tx = tx;
|
||||||
this.hash = tx.hash('hex');
|
this.hash = tx.hash('hex');
|
||||||
this.index = i;
|
this.index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
function cmp(a, b) {
|
function cmp(a, b) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user