txdb: give txdb a reference to wallet.

This commit is contained in:
Christopher Jeffrey 2016-08-12 13:22:01 -07:00
parent 827f72ebc0
commit 09d8ee224c
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 13 additions and 19 deletions

View File

@ -35,22 +35,19 @@ var BufferWriter = require('./writer');
* TXDB * TXDB
* @exports TXDB * @exports TXDB
* @constructor * @constructor
* @param {WalletDB} db * @param {Wallet} wallet
* @param {WalletID} id
*/ */
function TXDB(db, id) { function TXDB(wallet) {
if (!(this instanceof TXDB)) if (!(this instanceof TXDB))
return new TXDB(db, id); return new TXDB(wallet);
this.id = id || null; this.wallet = wallet;
this.walletdb = db; this.walletdb = wallet.db;
this.db = db.db; this.db = wallet.db.db;
this.logger = db.logger; this.logger = wallet.db.logger;
this.network = db.network; this.network = wallet.db.network;
this.options = db.options; this.options = wallet.db.options;
this.busy = false;
this.jobs = [];
this.locker = new bcoin.locker(this); this.locker = new bcoin.locker(this);
this.current = null; this.current = null;
this.coinCache = new bcoin.lru(10000, 1); this.coinCache = new bcoin.lru(10000, 1);
@ -62,8 +59,8 @@ function TXDB(db, id) {
*/ */
TXDB.prototype.prefix = function prefix(key) { TXDB.prototype.prefix = function prefix(key) {
assert(this.id); assert(this.wallet.id);
return 't/' + this.id + '/' + key; return 't/' + this.wallet.id + '/' + key;
}; };
/** /**
@ -207,7 +204,7 @@ TXDB.prototype.commit = function commit(callback) {
*/ */
TXDB.prototype.getInfo = function getInfo(tx, callback) { TXDB.prototype.getInfo = function getInfo(tx, callback) {
this.walletdb.getPathInfo(this.id, tx, callback); this.walletdb.getPathInfo(this.wallet.id, tx, callback);
}; };
/** /**

View File

@ -61,7 +61,7 @@ function Wallet(db, options) {
this.accountDepth = 0; this.accountDepth = 0;
this.token = constants.ZERO_HASH; this.token = constants.ZERO_HASH;
this.tokenDepth = 0; this.tokenDepth = 0;
this.tx = new TXDB(this.db); this.tx = new TXDB(this);
this.account = null; this.account = null;
@ -128,7 +128,6 @@ Wallet.prototype.fromOptions = function fromOptions(options) {
this.id = id; this.id = id;
this.token = token; this.token = token;
this.tx.id = this.id;
return this; return this;
}; };
@ -1792,7 +1791,6 @@ Wallet.prototype.fromJSON = function fromJSON(json) {
this.accountDepth = json.accountDepth; this.accountDepth = json.accountDepth;
this.token = new Buffer(json.token, 'hex'); this.token = new Buffer(json.token, 'hex');
this.master = MasterKey.fromJSON(json.master); this.master = MasterKey.fromJSON(json.master);
this.tx.id = this.id;
return this; return this;
}; };
@ -1834,7 +1832,6 @@ Wallet.prototype.fromRaw = function fromRaw(data) {
this.token = p.readBytes(32); this.token = p.readBytes(32);
this.tokenDepth = p.readU32(); this.tokenDepth = p.readU32();
this.master = MasterKey.fromRaw(p.readVarBytes()); this.master = MasterKey.fromRaw(p.readVarBytes());
this.tx.id = this.id;
return this; return this;
}; };