mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
[FEATURE] add paging account request
some requests return results that can be paged through, e.g. `account_lines` use `limit` and `marker` options to specify results per response and position change `requestAccountLines` and `requestAccountOffers` to use the `pagingAccountRequest`
This commit is contained in:
@@ -458,10 +458,11 @@ OrderBook.prototype.requestFundedAmount = function(account, callback) {
|
||||
|
||||
function requestLineBalance(callback) {
|
||||
var request = self._remote.requestAccountLines(
|
||||
account, // account
|
||||
void(0), // account index
|
||||
'VALIDATED', // ledger
|
||||
self._issuerGets //peer
|
||||
account,
|
||||
{
|
||||
ledger: 'validated',
|
||||
peer: self._issuerGets
|
||||
}
|
||||
);
|
||||
|
||||
request.request(function(err, res) {
|
||||
|
||||
@@ -1234,6 +1234,70 @@ Remote.accountRequest = function(type, account, ledger, peer, callback) {
|
||||
return request;
|
||||
};
|
||||
|
||||
/**
|
||||
* Account Request for paging request
|
||||
*
|
||||
* @param {String} type - request name, e.g. 'account_lines'
|
||||
* @param {String} account - ripple address
|
||||
* @param {Object} options
|
||||
* @param {String} peer - ripple address
|
||||
* @param [String|Number] ledger identifier
|
||||
* @param [Number] limit - max results per response
|
||||
* @param {String} marker - start position in response paging
|
||||
* @param [Function] callback
|
||||
* @return {Request}
|
||||
*/
|
||||
Remote.pagingAccountRequest = function(type, account, options, callback) {
|
||||
var ledger, peer, limit, marker;
|
||||
|
||||
if (typeof options === 'object') {
|
||||
ledger = options.ledger;
|
||||
peer = options.peer;
|
||||
limit = options.limit;
|
||||
marker = options.marker;
|
||||
}
|
||||
|
||||
var lastArg = arguments[arguments.length - 1];
|
||||
|
||||
if (typeof lastArg === 'function') {
|
||||
callback = lastArg;
|
||||
}
|
||||
|
||||
var request = new Request(this, type);
|
||||
var account = UInt160.json_rewrite(account);
|
||||
|
||||
request.message.account = account;
|
||||
request.ledgerSelect(ledger);
|
||||
|
||||
if (UInt160.is_valid(peer)) {
|
||||
request.message.peer = UInt160.json_rewrite(peer);
|
||||
}
|
||||
|
||||
if (!isNaN(Number(limit))) {
|
||||
limit = Number(limit);
|
||||
|
||||
// max for 32-bit unsigned int is 4294967295
|
||||
// we'll clamp to 1e9
|
||||
if (limit > 1e9) {
|
||||
limit = 1e9;
|
||||
}
|
||||
// min for 32-bit unsigned int is 0
|
||||
// we'll clamp to 0
|
||||
if (limit < 0) {
|
||||
limit = 0;
|
||||
}
|
||||
|
||||
request.message.limit = limit;
|
||||
}
|
||||
|
||||
if (marker) {
|
||||
request.message.marker = marker;
|
||||
}
|
||||
|
||||
request.callback(callback);
|
||||
return request;
|
||||
};
|
||||
|
||||
/**
|
||||
* Request account_info
|
||||
*
|
||||
@@ -1265,32 +1329,38 @@ Remote.prototype.requestAccountCurrencies = function(account, callback) {
|
||||
/**
|
||||
* Request account_lines
|
||||
*
|
||||
* @param {String} ripple address
|
||||
* @param [String|Number] ledger identifier
|
||||
* @param [String] peer
|
||||
* @param {String} account - ripple address
|
||||
* @param {Object} options
|
||||
* @param {String} peer - ripple address
|
||||
* @param [String|Number] ledger identifier
|
||||
* @param [Number] limit - max results per response
|
||||
* @param {String} marker - start position in response paging
|
||||
* @param [Function] callback
|
||||
* @return {Request}
|
||||
*/
|
||||
|
||||
Remote.prototype.requestAccountLines = function(account, peer, callback) {
|
||||
Remote.prototype.requestAccountLines = function(account, options, callback) {
|
||||
// XXX Does this require the server to be trusted?
|
||||
//utils.assert(this.trusted);
|
||||
var args = Array.prototype.concat.apply(['account_lines'], arguments);
|
||||
return Remote.accountRequest.apply(this, args);
|
||||
return Remote.pagingAccountRequest.apply(this, args);
|
||||
};
|
||||
|
||||
/**
|
||||
* Request account_offers
|
||||
*
|
||||
* @param {String} ripple address
|
||||
* @param [String|Number] ledger identifier
|
||||
* @param {String} account - ripple address
|
||||
* @param {Object} options
|
||||
* @param [String|Number] ledger identifier
|
||||
* @param [Number] limit - max results per response
|
||||
* @param {String} marker - start position in response paging
|
||||
* @param [Function] callback
|
||||
* @return {Request}
|
||||
*/
|
||||
|
||||
Remote.prototype.requestAccountOffers = function(account, callback) {
|
||||
Remote.prototype.requestAccountOffers = function(account, options, callback) {
|
||||
var args = Array.prototype.concat.apply(['account_offers'], arguments);
|
||||
return Remote.accountRequest.apply(this, args);
|
||||
return Remote.pagingAccountRequest.apply(this, args);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -564,7 +564,7 @@ Server.prototype._handleServerStatus = function(message) {
|
||||
this._remote.emit('load', message, this);
|
||||
|
||||
var loadChanged = message.load_base !== this._load_base
|
||||
|| message.load_factor !== this._load_factor
|
||||
|| message.load_factor !== this._load_factor;
|
||||
|
||||
if (loadChanged) {
|
||||
this._load_base = message.load_base;
|
||||
|
||||
Reference in New Issue
Block a user