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