mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-24 06:05:51 +00:00
Merge pull request #403 from clark800/no-limit
Get all results when limit is not specified
This commit is contained in:
@@ -10,7 +10,7 @@ function requestAccountOffers(remote, address, ledgerVersion, options,
|
||||
remote.requestAccountOffers({
|
||||
account: address,
|
||||
marker: marker,
|
||||
limit: limit,
|
||||
limit: utils.clamp(limit, 10, 400),
|
||||
ledger: ledgerVersion
|
||||
},
|
||||
composeAsync((data) => ({
|
||||
@@ -23,13 +23,11 @@ function getOrders(account, options, callback) {
|
||||
validate.address(account);
|
||||
validate.getOrdersOptions(options);
|
||||
|
||||
const defaultLimit = 100;
|
||||
const limit = options.limit || defaultLimit;
|
||||
const ledgerVersion = options.ledgerVersion
|
||||
|| this.remote.getLedgerSequence();
|
||||
const getter = _.partial(requestAccountOffers, this.remote, account,
|
||||
ledgerVersion, options);
|
||||
utils.getRecursive(getter, limit,
|
||||
utils.getRecursive(getter, options.limit,
|
||||
composeAsync((orders) => _.sortBy(orders,
|
||||
(order) => order.properties.sequence), callback));
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ const parseTransaction = require('./parse/transaction');
|
||||
const getTransaction = require('./transaction');
|
||||
const validate = utils.common.validate;
|
||||
const composeAsync = utils.common.composeAsync;
|
||||
const DEFAULT_LIMIT = 100;
|
||||
|
||||
function parseAccountTxTransaction(tx) {
|
||||
// rippled uses a different response format for 'account_tx' than 'tx'
|
||||
@@ -47,7 +46,7 @@ function getAccountTx(remote, address, options, marker, limit, callback) {
|
||||
ledger_index_max: options.maxLedgerVersion || -1,
|
||||
forward: options.earliestFirst,
|
||||
binary: options.binary,
|
||||
limit: Math.max(limit || DEFAULT_LIMIT, 10),
|
||||
limit: utils.clamp(limit, 10, 400),
|
||||
marker: marker
|
||||
};
|
||||
|
||||
@@ -64,11 +63,10 @@ function getAccountTx(remote, address, options, marker, limit, callback) {
|
||||
}
|
||||
|
||||
function getTransactionsInternal(remote, address, options, callback) {
|
||||
const limit = options.limit || DEFAULT_LIMIT;
|
||||
const compare = options.earliestFirst ? utils.compareTransactions :
|
||||
_.rearg(utils.compareTransactions, 1, 0);
|
||||
const getter = _.partial(getAccountTx, remote, address, options);
|
||||
utils.getRecursive(getter, limit,
|
||||
utils.getRecursive(getter, options.limit,
|
||||
composeAsync((txs) => txs.sort(compare), callback));
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ function getAccountLines(remote, address, ledgerVersion, options, marker, limit,
|
||||
account: address,
|
||||
ledger: ledgerVersion,
|
||||
marker: marker,
|
||||
limit: Math.max(limit, 10),
|
||||
limit: utils.clamp(limit, 10, 400),
|
||||
peer: options.counterparty
|
||||
};
|
||||
|
||||
@@ -40,13 +40,11 @@ function getTrustlines(
|
||||
validate.address(account);
|
||||
validate.getTrustlinesOptions(options);
|
||||
|
||||
const defaultLimit = 100;
|
||||
const limit = options.limit || defaultLimit;
|
||||
const ledgerVersion = options.ledgerVersion
|
||||
|| this.remote.getLedgerSequence();
|
||||
const getter = _.partial(getAccountLines, this.remote, account,
|
||||
ledgerVersion, options);
|
||||
utils.getRecursive(getter, limit, callback);
|
||||
utils.getRecursive(getter, options.limit, callback);
|
||||
}
|
||||
|
||||
module.exports = utils.wrapCatch(getTrustlines);
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
'use strict';
|
||||
const _ = require('lodash');
|
||||
const assert = require('assert');
|
||||
const common = require('../common');
|
||||
const dropsToXrp = common.dropsToXrp;
|
||||
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) {
|
||||
remote.requestAccountInfo({account: address, ledger: ledgerVersion},
|
||||
composeAsync((data) => dropsToXrp(data.account_data.Balance), callback));
|
||||
@@ -29,7 +35,7 @@ function getRecursiveRecur(getter, marker, limit, callback) {
|
||||
}
|
||||
|
||||
function getRecursive(getter, limit, callback) {
|
||||
getRecursiveRecur(getter, undefined, limit, callback);
|
||||
getRecursiveRecur(getter, undefined, limit || Infinity, callback);
|
||||
}
|
||||
|
||||
function renameCounterpartyToIssuer(amount) {
|
||||
@@ -86,6 +92,7 @@ module.exports = {
|
||||
getRecursive,
|
||||
hasCompleteLedgerRange,
|
||||
wrapCatch: common.wrapCatch,
|
||||
clamp: clamp,
|
||||
common: common
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user