From 09d8ee224c979cd355f431295df7f719ea85ffca Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 12 Aug 2016 13:22:01 -0700 Subject: [PATCH] txdb: give txdb a reference to wallet. --- lib/bcoin/txdb.js | 27 ++++++++++++--------------- lib/bcoin/wallet.js | 5 +---- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/lib/bcoin/txdb.js b/lib/bcoin/txdb.js index d5d57a01..0f91c564 100644 --- a/lib/bcoin/txdb.js +++ b/lib/bcoin/txdb.js @@ -35,22 +35,19 @@ var BufferWriter = require('./writer'); * TXDB * @exports TXDB * @constructor - * @param {WalletDB} db - * @param {WalletID} id + * @param {Wallet} wallet */ -function TXDB(db, id) { +function TXDB(wallet) { if (!(this instanceof TXDB)) - return new TXDB(db, id); + return new TXDB(wallet); - this.id = id || null; - this.walletdb = db; - this.db = db.db; - this.logger = db.logger; - this.network = db.network; - this.options = db.options; - this.busy = false; - this.jobs = []; + this.wallet = wallet; + this.walletdb = wallet.db; + this.db = wallet.db.db; + this.logger = wallet.db.logger; + this.network = wallet.db.network; + this.options = wallet.db.options; this.locker = new bcoin.locker(this); this.current = null; this.coinCache = new bcoin.lru(10000, 1); @@ -62,8 +59,8 @@ function TXDB(db, id) { */ TXDB.prototype.prefix = function prefix(key) { - assert(this.id); - return 't/' + this.id + '/' + key; + assert(this.wallet.id); + return 't/' + this.wallet.id + '/' + key; }; /** @@ -207,7 +204,7 @@ TXDB.prototype.commit = function commit(callback) { */ TXDB.prototype.getInfo = function getInfo(tx, callback) { - this.walletdb.getPathInfo(this.id, tx, callback); + this.walletdb.getPathInfo(this.wallet.id, tx, callback); }; /** diff --git a/lib/bcoin/wallet.js b/lib/bcoin/wallet.js index 0a560d9b..9a0986e8 100644 --- a/lib/bcoin/wallet.js +++ b/lib/bcoin/wallet.js @@ -61,7 +61,7 @@ function Wallet(db, options) { this.accountDepth = 0; this.token = constants.ZERO_HASH; this.tokenDepth = 0; - this.tx = new TXDB(this.db); + this.tx = new TXDB(this); this.account = null; @@ -128,7 +128,6 @@ Wallet.prototype.fromOptions = function fromOptions(options) { this.id = id; this.token = token; - this.tx.id = this.id; return this; }; @@ -1792,7 +1791,6 @@ Wallet.prototype.fromJSON = function fromJSON(json) { this.accountDepth = json.accountDepth; this.token = new Buffer(json.token, 'hex'); this.master = MasterKey.fromJSON(json.master); - this.tx.id = this.id; return this; }; @@ -1834,7 +1832,6 @@ Wallet.prototype.fromRaw = function fromRaw(data) { this.token = p.readBytes(32); this.tokenDepth = p.readU32(); this.master = MasterKey.fromRaw(p.readVarBytes()); - this.tx.id = this.id; return this; };