bitcoind: parse ints for pagination

This commit is contained in:
Braydon Fuller 2016-04-20 15:35:43 -04:00
parent 587602d080
commit d1cf9deef0
2 changed files with 12 additions and 4 deletions

View File

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

View File

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