bitcoind: parse ints for pagination
This commit is contained in:
parent
587602d080
commit
d1cf9deef0
@ -1059,10 +1059,12 @@ Bitcoin.prototype._getAddressStrings = function(addresses) {
|
|||||||
return addressStrings;
|
return addressStrings;
|
||||||
};
|
};
|
||||||
|
|
||||||
Bitcoin.prototype._paginateTxids = function(fullTxids, from, to) {
|
Bitcoin.prototype._paginateTxids = function(fullTxids, fromArg, toArg) {
|
||||||
var txids;
|
var txids;
|
||||||
|
var from = parseInt(fromArg);
|
||||||
|
var to = parseInt(toArg);
|
||||||
if (from >= 0 && to >= 0) {
|
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);
|
txids = fullTxids.slice(from, to);
|
||||||
} else {
|
} else {
|
||||||
txids = fullTxids;
|
txids = fullTxids;
|
||||||
|
|||||||
@ -1992,8 +1992,14 @@ describe('Bitcoin Service', function() {
|
|||||||
var bitcoind = new BitcoinService(baseConfig);
|
var bitcoind = new BitcoinService(baseConfig);
|
||||||
var txids = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
var txids = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||||
(function() {
|
(function() {
|
||||||
var paginated = bitcoind._paginateTxids(txids, 1, 0);
|
bitcoind._paginateTxids(txids, 1, 0);
|
||||||
}).should.throw('"from" is expected to be less than "to"');
|
}).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]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user