txdb: refactor x3.
This commit is contained in:
parent
62c59cc4f5
commit
519280e1bd
@ -1800,8 +1800,8 @@ TXDB.prototype.getHistory = function getHistory(account) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
TXDB.prototype.getAccountHistory = co(function* getAccountHistory(account) {
|
TXDB.prototype.getAccountHistory = co(function* getAccountHistory(account) {
|
||||||
var txs = [];
|
|
||||||
var hashes = yield this.getHistoryHashes(account);
|
var hashes = yield this.getHistoryHashes(account);
|
||||||
|
var txs = [];
|
||||||
var i, hash, tx;
|
var i, hash, tx;
|
||||||
|
|
||||||
for (i = 0; i < hashes.length; i++) {
|
for (i = 0; i < hashes.length; i++) {
|
||||||
@ -1824,8 +1824,8 @@ TXDB.prototype.getAccountHistory = co(function* getAccountHistory(account) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
TXDB.prototype.getPending = co(function* getPending(account) {
|
TXDB.prototype.getPending = co(function* getPending(account) {
|
||||||
var txs = [];
|
|
||||||
var hashes = yield this.getPendingHashes(account);
|
var hashes = yield this.getPendingHashes(account);
|
||||||
|
var txs = [];
|
||||||
var i, hash, tx;
|
var i, hash, tx;
|
||||||
|
|
||||||
for (i = 0; i < hashes.length; i++) {
|
for (i = 0; i < hashes.length; i++) {
|
||||||
@ -1868,7 +1868,7 @@ TXDB.prototype.getCoins = co(function* getCoins(account, all) {
|
|||||||
|
|
||||||
TXDB.prototype.getCredits = co(function* getCredits(account, all) {
|
TXDB.prototype.getCredits = co(function* getCredits(account, all) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var out = [];
|
var unspent = [];
|
||||||
var i, credits, credit;
|
var i, credits, credit;
|
||||||
|
|
||||||
// Slow case
|
// Slow case
|
||||||
@ -1899,10 +1899,10 @@ TXDB.prototype.getCredits = co(function* getCredits(account, all) {
|
|||||||
credit = credits[i];
|
credit = credits[i];
|
||||||
if (credit.spent)
|
if (credit.spent)
|
||||||
continue;
|
continue;
|
||||||
out.push(credit);
|
unspent.push(credit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return unspent;
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1960,30 +1960,24 @@ TXDB.prototype.getAccountCredits = co(function* getAccountCredits(account, all)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
TXDB.prototype.fillHistory = co(function* fillHistory(tx) {
|
TXDB.prototype.fillHistory = co(function* fillHistory(tx) {
|
||||||
var coins = [];
|
var i, input, credits, credit;
|
||||||
var hash;
|
|
||||||
|
|
||||||
if (tx.isCoinbase())
|
if (tx.isCoinbase())
|
||||||
return coins;
|
return tx;
|
||||||
|
|
||||||
hash = tx.hash('hex');
|
credits = yield this.getSpentCredits(tx);
|
||||||
|
|
||||||
yield this.range({
|
for (i = 0; i < tx.inputs.length; i++) {
|
||||||
gte: layout.d(hash, 0x00000000),
|
input = tx.inputs[i];
|
||||||
lte: layout.d(hash, 0xffffffff),
|
credit = credits[i];
|
||||||
parse: function(key, value) {
|
|
||||||
var index = layout.dd(key)[1];
|
|
||||||
var coin = Coin.fromRaw(value);
|
|
||||||
var input = tx.inputs[index];
|
|
||||||
assert(input);
|
|
||||||
coin.hash = input.prevout.hash;
|
|
||||||
coin.index = input.prevout.index;
|
|
||||||
input.coin = coin;
|
|
||||||
coins[index] = coin;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return coins;
|
if (!credit)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
input.coin = credit.coin;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tx;
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1994,7 +1988,10 @@ TXDB.prototype.fillHistory = co(function* fillHistory(tx) {
|
|||||||
|
|
||||||
TXDB.prototype.getSpentCredits = co(function* getSpentCredits(tx) {
|
TXDB.prototype.getSpentCredits = co(function* getSpentCredits(tx) {
|
||||||
var credits = [];
|
var credits = [];
|
||||||
var hash;
|
var i, hash;
|
||||||
|
|
||||||
|
for (i = 0; i < tx.inputs.length; i++)
|
||||||
|
credits.push(null);
|
||||||
|
|
||||||
if (tx.isCoinbase())
|
if (tx.isCoinbase())
|
||||||
return credits;
|
return credits;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user