wallet: enforce settxfee for all functions.

This commit is contained in:
Christopher Jeffrey 2017-08-26 01:35:36 -07:00
parent 6742482445
commit 26f6fb5277
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 18 additions and 14 deletions

View File

@ -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;
};

View File

@ -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;