[FEATURE] check for valid ledger when using marker

when using a marker on an account request, a valid ledger_index or ledger_hash is required, otherwise the results can't be guaranteed to be reliable

consolidated test values for addresses, indexes and hashes
This commit is contained in:
Geert Weening
2014-11-07 11:18:24 -08:00
parent e42e67e259
commit 29e1423f84
2 changed files with 115 additions and 58 deletions

View File

@@ -23,6 +23,7 @@ var Server = require('./server').Server;
var Amount = require('./amount').Amount;
var Currency = require('./currency').Currency;
var UInt160 = require('./uint160').UInt160;
var UInt256 = require('./uint256').UInt256;
var Transaction = require('./transaction').Transaction;
var Account = require('./account').Account;
var Meta = require('./meta').Meta;
@@ -1203,6 +1204,10 @@ Remote.prototype.requestTx = function(hash, callback) {
* Optional paging with limit and marker options
* supported in rippled for 'account_lines' and 'account_offers'
*
* The paged responses aren't guaranteed to be reliable between
* ledger closes. You have to supply a ledger_index or ledger_hash
* when paging to ensure a complete response
*
* @param {String} type - request name, e.g. 'account_lines'
* @param {String} account - ripple address
* @param {Object} options - all optional
@@ -1223,6 +1228,14 @@ Remote.accountRequest = function(type, account, options, callback) {
marker = options.marker;
}
// if a marker is given, we need a ledger
// check if a valid ledger_index or ledger_hash is provided
if (marker) {
if(!(Number(ledger) > 0) && !UInt256.is_valid(ledger)) {
throw new Error('A ledger_index or ledger_hash must be provided when using a marker');
}
}
var lastArg = arguments[arguments.length - 1];
if (typeof lastArg === 'function') {
@@ -1299,6 +1312,13 @@ Remote.prototype.requestAccountCurrencies = function(account, options, callback)
/**
* Request account_lines
*
* Requests for account_lines support paging, provide a limit and marker
* to page through responses.
*
* The paged responses aren't guaranteed to be reliable between
* ledger closes. You have to supply a ledger_index or ledger_hash
* when paging to ensure a complete response
*
* @param {String} account - ripple address
* @param {Object} options
* @param {String} peer - ripple address
@@ -1319,6 +1339,13 @@ Remote.prototype.requestAccountLines = function(account, options, callback) {
/**
* Request account_offers
*
* Requests for account_offers support paging, provide a limit and marker
* to page through responses.
*
* The paged responses aren't guaranteed to be reliable between
* ledger closes. You have to supply a ledger_index or ledger_hash
* when paging to ensure a complete response
*
* @param {String} account - ripple address
* @param {Object} options
* @param [String|Number] ledger identifier