From d1cf9deef00bfeefd0be13a765d2e58d1280d728 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Wed, 20 Apr 2016 15:35:43 -0400 Subject: [PATCH] bitcoind: parse ints for pagination --- lib/services/bitcoind.js | 6 ++++-- test/services/bitcoind.unit.js | 10 ++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/services/bitcoind.js b/lib/services/bitcoind.js index 96a17344..db33350d 100644 --- a/lib/services/bitcoind.js +++ b/lib/services/bitcoind.js @@ -1059,10 +1059,12 @@ Bitcoin.prototype._getAddressStrings = function(addresses) { return addressStrings; }; -Bitcoin.prototype._paginateTxids = function(fullTxids, from, to) { +Bitcoin.prototype._paginateTxids = function(fullTxids, fromArg, toArg) { var txids; + var from = parseInt(fromArg); + var to = parseInt(toArg); if (from >= 0 && to >= 0) { - $.checkState(from < to, '"from" is expected to be less than "to"'); + $.checkState(from < to, '"from" (' + from + ') is expected to be less than "to" (' + to + ')'); txids = fullTxids.slice(from, to); } else { txids = fullTxids; diff --git a/test/services/bitcoind.unit.js b/test/services/bitcoind.unit.js index 88cea586..80df5fc0 100644 --- a/test/services/bitcoind.unit.js +++ b/test/services/bitcoind.unit.js @@ -1992,8 +1992,14 @@ describe('Bitcoin Service', function() { var bitcoind = new BitcoinService(baseConfig); var txids = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; (function() { - var paginated = bitcoind._paginateTxids(txids, 1, 0); - }).should.throw('"from" is expected to be less than "to"'); + bitcoind._paginateTxids(txids, 1, 0); + }).should.throw('"from" (1) is expected to be less than "to"'); + }); + it('will handle string numbers', function() { + var bitcoind = new BitcoinService(baseConfig); + var txids = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + var paginated = bitcoind._paginateTxids(txids, '1', '3'); + paginated.should.deep.equal([1, 2]); }); });