Skip to content

Commit

Permalink
wallet: fix configurable txs limits
Browse files Browse the repository at this point in the history
  • Loading branch information
braydonf committed Dec 20, 2018
1 parent d08aff7 commit 05f4898
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
5 changes: 3 additions & 2 deletions lib/wallet/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class Plugin extends EventEmitter {
witness: this.config.bool('witness'),
checkpoints: this.config.bool('checkpoints'),
wipeNoReally: this.config.bool('wipe-no-really'),
spv: node.spv
spv: node.spv,
maxTxs: this.config.uint('max-txs')
});

this.rpc = new RPC(this);
Expand All @@ -74,7 +75,7 @@ class Plugin extends EventEmitter {
noAuth: this.config.bool('no-auth'),
cors: this.config.bool('cors'),
adminToken: this.config.str('admin-token'),
maxTxs: this.config.uint('http-max-txs')
maxTxs: this.config.uint('max-txs')
});

this.init();
Expand Down
2 changes: 1 addition & 1 deletion lib/wallet/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class RPC extends RPCBase {

this.wallet = null;

this.maxTxs = node.config.uint('rpc-max-txs', 100);
this.maxTxs = node.config.uint('max-txs', 100);

this.init();
}
Expand Down
30 changes: 18 additions & 12 deletions lib/wallet/txdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ class TXDB {
this.wdb = wdb;
this.db = wdb.db;
this.logger = wdb.logger;
this.maxTxs = 100;

this.wid = wid || 0;
this.bucket = null;
this.wallet = null;
this.locked = new BufferSet();

if (this.wdb.options.maxTxs != null) {
assert(Number.isSafeInteger(this.wdb.options.maxTxs));
this.maxTxs = this.wdb.options.maxTxs;
}
}

/**
Expand Down Expand Up @@ -1776,8 +1782,8 @@ class TXDB {
assert(typeof options.limit === 'number');
assert(typeof options.reverse === 'boolean');

if (options.limit > 100)
throw new Error('Limit exceeds max of 100.');
if (options.limit > this.maxTxs)
throw new Error(`Limit exceeds max of ${this.maxTxs}.`);

let hashes = [];

Expand Down Expand Up @@ -1821,8 +1827,8 @@ class TXDB {
assert(typeof options.limit === 'number');
assert(typeof options.reverse === 'boolean');

if (options.limit > 100)
throw new Error('Limit exceeds max of 100.');
if (options.limit > this.maxTxs)
throw new Error('Limit exceeds max of ${this.maxTxs}.');

let max = null;
let min = null;
Expand Down Expand Up @@ -1925,8 +1931,8 @@ class TXDB {
assert(typeof options.reverse === 'boolean');
assert(typeof options.inclusive === 'boolean');

if (options.limit > 100)
throw new Error('Limit exceeds max of 100.');
if (options.limit > this.maxTxs)
throw new Error(`Limit exceeds max of ${this.maxTxs}.`);

const count = await this.getCountForTX(options.txid);

Expand Down Expand Up @@ -1979,8 +1985,8 @@ class TXDB {
assert(typeof options.limit === 'number');
assert(typeof options.reverse === 'boolean');

if (options.limit > 100)
throw new Error('Limit exceeds max of 100.');
if (options.limit > this.maxTxs)
throw new Error(`Limit exceeds max of ${this.maxTxs}.`);

let hashes = [];

Expand Down Expand Up @@ -2024,8 +2030,8 @@ class TXDB {
assert(typeof options.limit === 'number');
assert(typeof options.reverse === 'boolean');

if (options.limit > 100)
throw new Error('Limit exceeds max of 100.');
if (options.limit > this.maxTxs)
throw new Error(`Limit exceeds max of ${this.maxTxs}.`);

let max = null;
let min = null;
Expand Down Expand Up @@ -2131,8 +2137,8 @@ class TXDB {
assert(typeof options.reverse === 'boolean');
assert(typeof options.inclusive === 'boolean');

if (options.limit > 100)
throw new Error('Limit exceeds max of 100.');
if (options.limit > this.maxTxs)
throw new Error(`Limit exceeds max of ${this.maxTxs}.`);

const count = await this.getUnconfirmedCountForTX(acct, options.txid);

Expand Down
6 changes: 6 additions & 0 deletions lib/wallet/walletdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2223,6 +2223,7 @@ class WalletOptions {
this.maxFiles = 64;
this.cacheSize = 16 << 20;
this.compression = true;
this.maxTxs = 100;

this.spv = false;
this.witness = false;
Expand Down Expand Up @@ -2295,6 +2296,11 @@ class WalletOptions {
this.compression = options.compression;
}

if (options.maxTxs != null) {
assert(Number.isSafeInteger(options.maxTxs));
this.maxTxs = options.maxTxs;
}

if (options.spv != null) {
assert(typeof options.spv === 'boolean');
this.spv = options.spv;
Expand Down

0 comments on commit 05f4898

Please sign in to comment.