Get all results when limit is not specified

This commit is contained in:
Chris Clark
2015-07-08 15:13:20 -07:00
parent a464ca2368
commit f3a54bf02a
4 changed files with 14 additions and 13 deletions

View File

@@ -10,7 +10,7 @@ function requestAccountOffers(remote, address, ledgerVersion, options,
remote.requestAccountOffers({ remote.requestAccountOffers({
account: address, account: address,
marker: marker, marker: marker,
limit: limit, limit: utils.clamp(limit, 10, 400),
ledger: ledgerVersion ledger: ledgerVersion
}, },
composeAsync((data) => ({ composeAsync((data) => ({
@@ -23,13 +23,11 @@ function getAccountOrders(account, options, callback) {
validate.address(account); validate.address(account);
validate.options(options); validate.options(options);
const defaultLimit = 100;
const limit = options.limit || defaultLimit;
const ledgerVersion = options.ledgerVersion const ledgerVersion = options.ledgerVersion
|| this.remote.getLedgerSequence(); || this.remote.getLedgerSequence();
const getter = _.partial(requestAccountOffers, this.remote, account, const getter = _.partial(requestAccountOffers, this.remote, account,
ledgerVersion, options); ledgerVersion, options);
utils.getRecursive(getter, limit, utils.getRecursive(getter, options.limit,
composeAsync((orders) => _.sortBy(orders, composeAsync((orders) => _.sortBy(orders,
(order) => order.properties.sequence), callback)); (order) => order.properties.sequence), callback));
} }

View File

@@ -5,7 +5,6 @@ const parseTransaction = require('./parse/transaction');
const getTransaction = require('./transaction'); const getTransaction = require('./transaction');
const validate = utils.common.validate; const validate = utils.common.validate;
const composeAsync = utils.common.composeAsync; const composeAsync = utils.common.composeAsync;
const DEFAULT_LIMIT = 100;
function parseAccountTxTransaction(tx) { function parseAccountTxTransaction(tx) {
// rippled uses a different response format for 'account_tx' than 'tx' // rippled uses a different response format for 'account_tx' than 'tx'
@@ -43,7 +42,7 @@ function getAccountTx(remote, address, options, marker, limit, callback) {
ledger_index_max: options.maxLedgerVersion || -1, ledger_index_max: options.maxLedgerVersion || -1,
forward: options.earliestFirst, forward: options.earliestFirst,
binary: options.binary, binary: options.binary,
limit: Math.max(limit || DEFAULT_LIMIT, 10), limit: utils.clamp(limit, 10, 400),
marker: marker marker: marker
}; };
@@ -60,11 +59,10 @@ function getAccountTx(remote, address, options, marker, limit, callback) {
} }
function getTransactionsInternal(remote, address, options, callback) { function getTransactionsInternal(remote, address, options, callback) {
const limit = options.limit || DEFAULT_LIMIT;
const compare = options.earliestFirst ? utils.compareTransactions : const compare = options.earliestFirst ? utils.compareTransactions :
_.rearg(utils.compareTransactions, 1, 0); _.rearg(utils.compareTransactions, 1, 0);
const getter = _.partial(getAccountTx, remote, address, options); const getter = _.partial(getAccountTx, remote, address, options);
utils.getRecursive(getter, limit, utils.getRecursive(getter, options.limit,
composeAsync((txs) => txs.sort(compare), callback)); composeAsync((txs) => txs.sort(compare), callback));
} }

View File

@@ -16,7 +16,7 @@ function getAccountLines(remote, address, ledgerVersion, options, marker, limit,
account: address, account: address,
ledger: ledgerVersion, ledger: ledgerVersion,
marker: marker, marker: marker,
limit: Math.max(limit, 10), limit: utils.clamp(limit, 10, 400),
peer: options.counterparty peer: options.counterparty
}; };
@@ -40,13 +40,11 @@ function getTrustlines(
validate.address(account); validate.address(account);
validate.options(options); validate.options(options);
const defaultLimit = 100;
const limit = options.limit || defaultLimit;
const ledgerVersion = options.ledgerVersion const ledgerVersion = options.ledgerVersion
|| this.remote.getLedgerSequence(); || this.remote.getLedgerSequence();
const getter = _.partial(getAccountLines, this.remote, account, const getter = _.partial(getAccountLines, this.remote, account,
ledgerVersion, options); ledgerVersion, options);
utils.getRecursive(getter, limit, callback); utils.getRecursive(getter, options.limit, callback);
} }
module.exports = utils.wrapCatch(getTrustlines); module.exports = utils.wrapCatch(getTrustlines);

View File

@@ -1,9 +1,15 @@
'use strict'; 'use strict';
const _ = require('lodash'); const _ = require('lodash');
const assert = require('assert');
const common = require('../common'); const common = require('../common');
const dropsToXrp = common.dropsToXrp; const dropsToXrp = common.dropsToXrp;
const composeAsync = common.composeAsync; const composeAsync = common.composeAsync;
function clamp(value, min, max) {
assert(min <= max, 'Illegal clamp bounds');
return Math.min(Math.max(value, min), max);
}
function getXRPBalance(remote, address, ledgerVersion, callback) { function getXRPBalance(remote, address, ledgerVersion, callback) {
remote.requestAccountInfo({account: address, ledger: ledgerVersion}, remote.requestAccountInfo({account: address, ledger: ledgerVersion},
composeAsync((data) => dropsToXrp(data.account_data.Balance), callback)); composeAsync((data) => dropsToXrp(data.account_data.Balance), callback));
@@ -29,7 +35,7 @@ function getRecursiveRecur(getter, marker, limit, callback) {
} }
function getRecursive(getter, limit, callback) { function getRecursive(getter, limit, callback) {
getRecursiveRecur(getter, undefined, limit, callback); getRecursiveRecur(getter, undefined, limit || Infinity, callback);
} }
function renameCounterpartyToIssuer(amount) { function renameCounterpartyToIssuer(amount) {
@@ -78,6 +84,7 @@ module.exports = {
renameCounterpartyToIssuerInOrder: renameCounterpartyToIssuerInOrder, renameCounterpartyToIssuerInOrder: renameCounterpartyToIssuerInOrder,
getRecursive: getRecursive, getRecursive: getRecursive,
wrapCatch: common.wrapCatch, wrapCatch: common.wrapCatch,
clamp: clamp,
common: common common: common
}; };