bitcoind: limit tx history range
This commit is contained in:
parent
c6e543c2a1
commit
c63e98f061
|
@ -48,6 +48,7 @@ function Bitcoin(options) {
|
|||
this.subscriptions.hashblock = [];
|
||||
|
||||
// limits
|
||||
this.maxTransactionHistory = options.maxTransactionHistory || Bitcoin.DEFAULT_MAX_HISTORY;
|
||||
this.maxAddressesQuery = options.maxAddressesQuery || Bitcoin.DEFAULT_MAX_ADDRESSES_QUERY;
|
||||
this.shutdownTimeout = options.shutdownTimeout || Bitcoin.DEFAULT_SHUTDOWN_TIMEOUT;
|
||||
|
||||
|
@ -62,6 +63,7 @@ util.inherits(Bitcoin, Service);
|
|||
|
||||
Bitcoin.dependencies = [];
|
||||
|
||||
Bitcoin.DEFAULT_MAX_HISTORY = 10;
|
||||
Bitcoin.DEFAULT_SHUTDOWN_TIMEOUT = 15000;
|
||||
Bitcoin.DEFAULT_MAX_ADDRESSES_QUERY = 10000;
|
||||
Bitcoin.DEFAULT_TRY_ALL_INTERVAL = 1000;
|
||||
|
@ -1132,6 +1134,10 @@ Bitcoin.prototype._paginateTxids = function(fullTxids, fromArg, toArg) {
|
|||
var to = parseInt(toArg);
|
||||
if (from >= 0 && to >= 0) {
|
||||
$.checkState(from < to, '"from" (' + from + ') is expected to be less than "to" (' + to + ')');
|
||||
$.checkState(
|
||||
(to - from) <= this.maxTransactionHistory,
|
||||
'"from" (' + from + ') and "to" (' + to + ') range should be less than or equal to ' + this.maxTransactionHistory
|
||||
);
|
||||
txids = fullTxids.slice(from, to);
|
||||
} else {
|
||||
txids = fullTxids;
|
||||
|
|
|
@ -2054,11 +2054,18 @@ describe('Bitcoin Service', function() {
|
|||
});
|
||||
|
||||
describe('#_paginateTxids', function() {
|
||||
it('slice txids based on "from" and "to" (3 to 13)', function() {
|
||||
var bitcoind = new BitcoinService(baseConfig);
|
||||
var txids = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
var paginated = bitcoind._paginateTxids(txids, 3, 13);
|
||||
paginated.should.deep.equal([3, 4, 5, 6, 7, 8, 9, 10]);
|
||||
});
|
||||
it('slice txids based on "from" and "to" (3 to 30)', function() {
|
||||
var bitcoind = new BitcoinService(baseConfig);
|
||||
var txids = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
var paginated = bitcoind._paginateTxids(txids, 3, 30);
|
||||
paginated.should.deep.equal([3, 4, 5, 6, 7, 8, 9, 10]);
|
||||
(function() {
|
||||
bitcoind._paginateTxids(txids, 3, 30);
|
||||
}).should.throw(Error);
|
||||
});
|
||||
it('slice txids based on "from" and "to" (0 to 3)', function() {
|
||||
var bitcoind = new BitcoinService(baseConfig);
|
||||
|
|
Loading…
Reference in New Issue