From 4058bba9079b2567070b48040522df1d7a2d4044 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 31 May 2016 06:10:42 -0700 Subject: [PATCH] coin filling. --- lib/bcoin/wallet.js | 53 +++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/lib/bcoin/wallet.js b/lib/bcoin/wallet.js index a8621d1e..98ef90c2 100644 --- a/lib/bcoin/wallet.js +++ b/lib/bcoin/wallet.js @@ -457,32 +457,43 @@ Wallet.prototype.fill = function fill(tx, options, callback) { if (!this.initialized) return callback(new Error('Wallet is not initialized.')); - this.getCoins(options.account, function(err, coins) { + this.getAccount(options.account, function(err, account) { if (err) return callback(err); - try { - tx.fill(coins, { - selection: options.selection || 'age', - round: options.round, - confirmed: options.confirmed, - free: options.free, - fee: options.fee, - subtractFee: options.subtractFee, - changeAddress: self.account.changeAddress.getAddress(), - height: self.network.height, - rate: options.rate != null - ? options.rate - : self.network.getRate(), - wallet: self, - m: self.m, - n: self.n - }); - } catch (e) { - return callback(e); + if (!account) { + if (options.account != null) + return callback(new Error('Account not found.')); + account = self.account; } - return callback(); + self.getCoins(options.account, function(err, coins) { + if (err) + return callback(err); + + try { + tx.fill(coins, { + selection: options.selection || 'age', + round: options.round, + confirmed: options.confirmed, + free: options.free, + fee: options.fee, + subtractFee: options.subtractFee, + changeAddress: account.changeAddress.getAddress(), + height: self.network.height, + rate: options.rate != null + ? options.rate + : self.network.getRate(), + wallet: self, + m: self.m, + n: self.n + }); + } catch (e) { + return callback(e); + } + + return callback(); + }); }); };