txdb: refactor.
This commit is contained in:
parent
d697684b83
commit
9fe6919416
@ -2285,7 +2285,7 @@ Balance.prototype.fromRaw = function fromRaw(data) {
|
|||||||
var p = new BufferReader(data);
|
var p = new BufferReader(data);
|
||||||
this.unconfirmed = p.readU53();
|
this.unconfirmed = p.readU53();
|
||||||
this.confirmed = p.readU53();
|
this.confirmed = p.readU53();
|
||||||
this.total += this.unconfirmed
|
this.total += this.unconfirmed;
|
||||||
this.total += this.confirmed;
|
this.total += this.confirmed;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
@ -2344,12 +2344,17 @@ TXDBState.prototype.commit = function commit() {
|
|||||||
return this.toRaw();
|
return this.toRaw();
|
||||||
};
|
};
|
||||||
|
|
||||||
TXDBState.prototype.toRaw = function toRaw() {
|
TXDBState.prototype.toRaw = function toRaw(writer) {
|
||||||
var p = new BufferWriter();
|
var p = new BufferWriter(writer);
|
||||||
|
|
||||||
p.writeU64(this.tx);
|
p.writeU64(this.tx);
|
||||||
p.writeU64(this.coin);
|
p.writeU64(this.coin);
|
||||||
this.balance.toRaw(p);
|
this.balance.toRaw(p);
|
||||||
return p.render();
|
|
||||||
|
if (!writer)
|
||||||
|
p = p.render();
|
||||||
|
|
||||||
|
return p;
|
||||||
};
|
};
|
||||||
|
|
||||||
TXDBState.prototype.fromRaw = function fromRaw(data) {
|
TXDBState.prototype.fromRaw = function fromRaw(data) {
|
||||||
@ -2382,11 +2387,15 @@ TXDBState.prototype.unconfirm = function unconfirm(value) {
|
|||||||
return this.balance.unconfirm(value);
|
return this.balance.unconfirm(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
TXDBState.prototype.toJSON = function toJSON() {
|
TXDBState.prototype.toJSON = function toJSON(minimal) {
|
||||||
return {
|
return {
|
||||||
|
wid: !minimal ? this.wid : undefined,
|
||||||
|
id: !minimal ? this.id : undefined,
|
||||||
tx: this.tx,
|
tx: this.tx,
|
||||||
coin: this.coin,
|
coin: this.coin,
|
||||||
balance: this.balance
|
unconfirmed: utils.btc(this.balance.unconfirmed),
|
||||||
|
confirmed: utils.btc(this.balance.confirmed),
|
||||||
|
total: utils.btc(this.balance.total)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -25,8 +25,6 @@ var WalletKey = require('./walletkey');
|
|||||||
var HD = require('../hd/hd');
|
var HD = require('../hd/hd');
|
||||||
var Account = require('./account');
|
var Account = require('./account');
|
||||||
var MasterKey = require('./masterkey');
|
var MasterKey = require('./masterkey');
|
||||||
var Input = require('../primitives/input');
|
|
||||||
var Output = require('../primitives/output');
|
|
||||||
var LRU = require('../utils/lru');
|
var LRU = require('../utils/lru');
|
||||||
var PathInfo = require('./pathinfo');
|
var PathInfo = require('./pathinfo');
|
||||||
|
|
||||||
@ -1551,31 +1549,20 @@ Wallet.prototype.getKey = co(function* getKey(address) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Map input addresses to paths.
|
* Map input addresses to paths.
|
||||||
* @param {TX|Input} tx
|
* @param {TX} tx
|
||||||
* @returns {Promise} - Returns {@link Path}[].
|
* @returns {Promise} - Returns {@link Path}[].
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getInputPaths = co(function* getInputPaths(tx) {
|
Wallet.prototype.getInputPaths = co(function* getInputPaths(tx) {
|
||||||
var paths = [];
|
var paths = [];
|
||||||
var hashes = [];
|
var i, hashes, hash, path;
|
||||||
var i, hash, path;
|
|
||||||
|
|
||||||
if (tx instanceof Input) {
|
yield this.fillCoins(tx);
|
||||||
if (!tx.coin)
|
|
||||||
throw new Error('Not all coins available.');
|
|
||||||
|
|
||||||
hash = tx.coin.getHash('hex');
|
if (!tx.hasCoins())
|
||||||
|
throw new Error('Not all coins available.');
|
||||||
|
|
||||||
if (hash)
|
hashes = tx.getInputHashes('hex');
|
||||||
hashes.push(hash);
|
|
||||||
} else {
|
|
||||||
yield this.fillCoins(tx);
|
|
||||||
|
|
||||||
if (!tx.hasCoins())
|
|
||||||
throw new Error('Not all coins available.');
|
|
||||||
|
|
||||||
hashes = tx.getInputHashes('hex');
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < hashes.length; i++) {
|
for (i = 0; i < hashes.length; i++) {
|
||||||
hash = hashes[i];
|
hash = hashes[i];
|
||||||
@ -1589,23 +1576,15 @@ Wallet.prototype.getInputPaths = co(function* getInputPaths(tx) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Map output addresses to paths.
|
* Map output addresses to paths.
|
||||||
* @param {TX|Output} tx
|
* @param {TX} tx
|
||||||
* @returns {Promise} - Returns {@link Path}[].
|
* @returns {Promise} - Returns {@link Path}[].
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getOutputPaths = co(function* getOutputPaths(tx) {
|
Wallet.prototype.getOutputPaths = co(function* getOutputPaths(tx) {
|
||||||
var paths = [];
|
var paths = [];
|
||||||
var hashes = [];
|
var hashes = tx.getOutputHashes('hex');
|
||||||
var i, hash, path;
|
var i, hash, path;
|
||||||
|
|
||||||
if (tx instanceof Output) {
|
|
||||||
hash = tx.getHash('hex');
|
|
||||||
if (hash)
|
|
||||||
hashes.push(hash);
|
|
||||||
} else {
|
|
||||||
hashes = tx.getOutputHashes('hex');
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < hashes.length; i++) {
|
for (i = 0; i < hashes.length; i++) {
|
||||||
hash = hashes[i];
|
hash = hashes[i];
|
||||||
path = yield this.getPath(hash);
|
path = yield this.getPath(hash);
|
||||||
@ -2362,7 +2341,7 @@ Wallet.prototype.inspect = function inspect() {
|
|||||||
accountDepth: this.accountDepth,
|
accountDepth: this.accountDepth,
|
||||||
token: this.token.toString('hex'),
|
token: this.token.toString('hex'),
|
||||||
tokenDepth: this.tokenDepth,
|
tokenDepth: this.tokenDepth,
|
||||||
state: this.state ? this.state.toJSON() : null,
|
state: this.state ? this.state.toJSON(true) : null,
|
||||||
master: this.master,
|
master: this.master,
|
||||||
account: this.account
|
account: this.account
|
||||||
};
|
};
|
||||||
@ -2385,7 +2364,7 @@ Wallet.prototype.toJSON = function toJSON() {
|
|||||||
accountDepth: this.accountDepth,
|
accountDepth: this.accountDepth,
|
||||||
token: this.token.toString('hex'),
|
token: this.token.toString('hex'),
|
||||||
tokenDepth: this.tokenDepth,
|
tokenDepth: this.tokenDepth,
|
||||||
balance: this.balance.toJSON(true),
|
state: this.state.toJSON(true),
|
||||||
master: this.master.toJSON(),
|
master: this.master.toJSON(),
|
||||||
account: this.account ? this.account.toJSON(true) : null
|
account: this.account ? this.account.toJSON(true) : null
|
||||||
};
|
};
|
||||||
|
|||||||
@ -96,7 +96,9 @@ var updateStates = co(function* updateStates() {
|
|||||||
wallets = yield db.keys({
|
wallets = yield db.keys({
|
||||||
gte: layout.w(0),
|
gte: layout.w(0),
|
||||||
lte: layout.w(0xffffffff),
|
lte: layout.w(0xffffffff),
|
||||||
parse: layout.pre
|
parse: function(key) {
|
||||||
|
return key.readUInt32LE(1, true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Updating states...');
|
console.log('Updating states...');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user