diff --git a/lib/wallet/rpc.js b/lib/wallet/rpc.js index 8870973e..3ad05d1c 100644 --- a/lib/wallet/rpc.js +++ b/lib/wallet/rpc.js @@ -49,7 +49,6 @@ function RPC(wdb) { this.client = wdb.client; this.wallet = null; - this.feeRate = null; this.init(); } @@ -152,16 +151,14 @@ RPC.prototype.fundRawTransaction = async function fundRawTransaction(args, help) 'TX must have at least one output.'); } - let rate = this.feeRate; - let change; + let rate = null; + let change = null; + if (options) { const valid = new Validator([options]); - if (valid.has('feeRate')) - rate = valid.ufixed('feeRate', 8); - - if (valid.has('changeAddress')) - change = valid.str('changeAddress'); + rate = valid.ufixed('feeRate', 8); + change = valid.str('changeAddress'); if (change) change = parseAddress(change, this.network); @@ -658,9 +655,7 @@ RPC.prototype.getWalletInfo = async function getWalletInfo(args, help) { keypoololdest: 0, keypoolsize: 0, unlocked_until: wallet.master.until, - paytxfee: this.feeRate != null - ? Amount.btc(this.feeRate, true) - : 0 + paytxfee: Amount.btc(this.wdb.feeRate, true) }; }; @@ -1261,7 +1256,6 @@ RPC.prototype.sendFrom = async function sendFrom(args, help) { const options = { account: name, - rate: this.feeRate, depth: minconf, outputs: [{ address: addr, @@ -1349,7 +1343,6 @@ RPC.prototype.sendToAddress = async function sendToAddress(args, help) { const options = { subtractFee: subtract, - rate: this.feeRate, outputs: [{ address: addr, value: value @@ -1381,7 +1374,7 @@ RPC.prototype.setTXFee = async function setTXFee(args, help) { if (rate == null) throw new RPCError(errs.TYPE_ERROR, 'Invalid parameter.'); - this.feeRate = rate; + this.wdb.feeRate = rate; return true; }; diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index e7336f4d..f2f2c4ff 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -65,6 +65,8 @@ function WalletDB(options) { this.workers = this.options.workers; this.client = this.options.client; + this.feeRate = this.options.feeRate; + this.db = LDB(this.options); this.rpc = new RPC(this); this.primary = null; @@ -515,6 +517,9 @@ WalletDB.prototype.send = async function send(tx) { */ WalletDB.prototype.estimateFee = async function estimateFee(blocks) { + if (this.feeRate > 0) + return this.feeRate; + if (!this.client) return this.network.feeRate; @@ -2155,6 +2160,7 @@ function WalletOptions(options) { this.logger = Logger.global; this.workers = null; this.client = null; + this.feeRate = 0; this.prefix = null; this.location = null; @@ -2211,6 +2217,11 @@ WalletOptions.prototype.fromOptions = function fromOptions(options) { this.client = options.client; } + if (options.feeRate != null) { + assert(util.isU64(options.feeRate)); + this.feeRate = options.feeRate; + } + if (options.prefix != null) { assert(typeof options.prefix === 'string'); this.prefix = options.prefix;