From c3ba9808b1449b28579cb532b0c68a232b239b12 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 1 Jun 2016 10:44:22 -0700 Subject: [PATCH] refactor account. --- lib/bcoin/wallet.js | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/bcoin/wallet.js b/lib/bcoin/wallet.js index 1008100e..7d627ee6 100644 --- a/lib/bcoin/wallet.js +++ b/lib/bcoin/wallet.js @@ -375,7 +375,7 @@ Wallet.prototype.getAccount = function getAccount(account, callback) { if (account === 0 || account === 'default') return callback(null, this.account); } - this.db.getAccount(this.id, account, callback); + return this.db.getAccount(this.id, account, callback); }; /** @@ -1980,15 +1980,22 @@ Account.prototype.deriveChange = function deriveChange(index) { */ Account.prototype.deriveAddress = function deriveAddress(change, index) { - var i, key, options; + var keys = []; + var i, key, shared; - assert(this.initialized); + assert(this.initialized, 'Account is not initialized.'); change = +change; key = this.accountKey.derive(change).derive(index); - options = { + for (i = 0; i < this.keys.length; i++) { + shared = this.keys[i]; + shared = shared.derive(change).derive(index); + keys.push(shared.publicKey); + } + + return new bcoin.keyring({ network: this.network, key: key.publicKey, account: this.accountIndex, @@ -1999,16 +2006,8 @@ Account.prototype.deriveAddress = function deriveAddress(change, index) { witness: this.witness, m: this.m, n: this.n, - keys: [] - }; - - for (i = 0; i < this.keys.length; i++) { - key = this.keys[i]; - key = key.derive(change).derive(index); - options.keys.push(key.publicKey); - } - - return new bcoin.keyring(options); + keys: keys + }); }; /** @@ -2018,7 +2017,7 @@ Account.prototype.deriveAddress = function deriveAddress(change, index) { */ Account.prototype.save = function save(callback) { - this.db.saveAccount(this, callback); + return this.db.saveAccount(this, callback); }; /** @@ -2028,7 +2027,7 @@ Account.prototype.save = function save(callback) { */ Account.prototype.saveAddress = function saveAddress(address, callback) { - this.db.saveAddress(this.id, address, callback); + return this.db.saveAddress(this.id, address, callback); }; /**