mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
[TASK] consolidate accountRequest and pagingAccountRequest
update `requestAccountCurrencies` and `requestAccountInfo`
This commit is contained in:
@@ -1198,48 +1198,14 @@ Remote.prototype.requestTx = function(hash, callback) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Account request abstraction
|
||||
* Account Request
|
||||
*
|
||||
* @this Remote
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Remote.accountRequest = function(type, account, ledger, peer, callback) {
|
||||
if (typeof account === 'object') {
|
||||
var options = account;
|
||||
callback = ledger;
|
||||
ledger = options.ledger;
|
||||
account = options.account || options.accountID;
|
||||
peer = options.peer;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
request.callback(callback);
|
||||
|
||||
return request;
|
||||
};
|
||||
|
||||
/**
|
||||
* Account Request for paging request
|
||||
* Optional paging with limit and marker options
|
||||
* supported in rippled for 'account_lines' and 'account_offers'
|
||||
*
|
||||
* @param {String} type - request name, e.g. 'account_lines'
|
||||
* @param {String} account - ripple address
|
||||
* @param {Object} options
|
||||
* @param {Object} options - all optional
|
||||
* @param {String} peer - ripple address
|
||||
* @param [String|Number] ledger identifier
|
||||
* @param [Number] limit - max results per response
|
||||
@@ -1247,7 +1213,7 @@ Remote.accountRequest = function(type, account, ledger, peer, callback) {
|
||||
* @param [Function] callback
|
||||
* @return {Request}
|
||||
*/
|
||||
Remote.pagingAccountRequest = function(type, account, options, callback) {
|
||||
Remote.accountRequest = function(type, account, options, callback) {
|
||||
var ledger, peer, limit, marker;
|
||||
|
||||
if (typeof options === 'object') {
|
||||
@@ -1301,13 +1267,15 @@ Remote.pagingAccountRequest = function(type, account, options, callback) {
|
||||
/**
|
||||
* Request account_info
|
||||
*
|
||||
* @param {String} ripple address
|
||||
* @param [String|Number] ledger identifier
|
||||
* @param {String} account - ripple address
|
||||
* @param {Object} options
|
||||
* @param {String} peer - ripple address
|
||||
* @param [String|Number] ledger identifier
|
||||
* @param [Function] callback
|
||||
* @return {Request}
|
||||
*/
|
||||
|
||||
Remote.prototype.requestAccountInfo = function(account, callback) {
|
||||
Remote.prototype.requestAccountInfo = function(account, options, callback) {
|
||||
var args = Array.prototype.concat.apply(['account_info'], arguments);
|
||||
return Remote.accountRequest.apply(this, args);
|
||||
};
|
||||
@@ -1315,13 +1283,15 @@ Remote.prototype.requestAccountInfo = function(account, callback) {
|
||||
/**
|
||||
* Request account_currencies
|
||||
*
|
||||
* @param {String} ripple address
|
||||
* @param [String|Number] ledger identifier
|
||||
* @param {String} account - ripple address
|
||||
* @param {Object} options
|
||||
* @param {String} peer - ripple address
|
||||
* @param [String|Number] ledger identifier
|
||||
* @param [Function] callback
|
||||
* @return {Request}
|
||||
*/
|
||||
|
||||
Remote.prototype.requestAccountCurrencies = function(account, callback) {
|
||||
Remote.prototype.requestAccountCurrencies = function(account, options, callback) {
|
||||
var args = Array.prototype.concat.apply(['account_currencies'], arguments);
|
||||
return Remote.accountRequest.apply(this, args);
|
||||
};
|
||||
@@ -1343,7 +1313,7 @@ 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.pagingAccountRequest.apply(this, args);
|
||||
return Remote.accountRequest.apply(this, args);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1360,7 +1330,7 @@ Remote.prototype.requestAccountLines = function(account, options, callback) {
|
||||
|
||||
Remote.prototype.requestAccountOffers = function(account, options, callback) {
|
||||
var args = Array.prototype.concat.apply(['account_offers'], arguments);
|
||||
return Remote.pagingAccountRequest.apply(this, args);
|
||||
return Remote.accountRequest.apply(this, args);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -185,20 +185,26 @@ describe('Remote', function () {
|
||||
assert(request instanceof Request);
|
||||
});
|
||||
|
||||
it('request account currencies with ledger index', function() {
|
||||
var request = remote.requestAccountCurrencies('r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS');
|
||||
assert.strictEqual(request.message.command, 'account_currencies');
|
||||
assert.strictEqual(request.message.account, 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS');
|
||||
});
|
||||
|
||||
it('request account info with ledger index', function() {
|
||||
var request = remote.requestAccountInfo('r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', 9592219);
|
||||
var request = remote.requestAccountInfo('r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {ledger: 9592219});
|
||||
assert.strictEqual(request.message.command, 'account_info');
|
||||
assert.strictEqual(request.message.account, 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS');
|
||||
assert.strictEqual(request.message.ledger_index, 9592219);
|
||||
});
|
||||
it('request account info with ledger hash', function() {
|
||||
var request = remote.requestAccountInfo('r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
|
||||
var request = remote.requestAccountInfo('r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {ledger: 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE'});
|
||||
assert.strictEqual(request.message.command, 'account_info');
|
||||
assert.strictEqual(request.message.account, 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS');
|
||||
assert.strictEqual(request.message.ledger_hash, 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
|
||||
});
|
||||
it('request account info with ledger identifier', function() {
|
||||
var request = remote.requestAccountInfo('r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', 'validated');
|
||||
var request = remote.requestAccountInfo('r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {ledger: 'validated'});
|
||||
assert.strictEqual(request.message.command, 'account_info');
|
||||
assert.strictEqual(request.message.account, 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS');
|
||||
assert.strictEqual(request.message.ledger_index, 'validated');
|
||||
@@ -225,7 +231,7 @@ describe('Remote', function () {
|
||||
});
|
||||
|
||||
it('pagingAccountRequest', function() {
|
||||
var request = Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS');
|
||||
var request = Remote.accountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS');
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_lines',
|
||||
id: undefined,
|
||||
@@ -234,7 +240,7 @@ describe('Remote', function () {
|
||||
});
|
||||
|
||||
it('pagingAccountRequest - limit', function() {
|
||||
var request = Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 100});
|
||||
var request = Remote.accountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 100});
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_lines',
|
||||
id: undefined,
|
||||
@@ -244,7 +250,7 @@ describe('Remote', function () {
|
||||
});
|
||||
|
||||
it('pagingAccountRequest - limit, marker', function() {
|
||||
var request = Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 100, marker: '29F992CC252056BF690107D1E8F2D9FBAFF29FF107B62B1D1F4E4E11ADF2CC73'});
|
||||
var request = Remote.accountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 100, marker: '29F992CC252056BF690107D1E8F2D9FBAFF29FF107B62B1D1F4E4E11ADF2CC73'});
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_lines',
|
||||
id: undefined,
|
||||
@@ -257,17 +263,17 @@ describe('Remote', function () {
|
||||
});
|
||||
|
||||
it('pagingAccountRequest - limit min', function() {
|
||||
assert.strictEqual(Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 0}).message.limit, 0);
|
||||
assert.strictEqual(Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: -1}).message.limit, 0);
|
||||
assert.strictEqual(Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: -1e9}).message.limit, 0);
|
||||
assert.strictEqual(Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: -1e24}).message.limit, 0);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 0}).message.limit, 0);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: -1}).message.limit, 0);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: -1e9}).message.limit, 0);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: -1e24}).message.limit, 0);
|
||||
});
|
||||
|
||||
it('pagingAccountRequest - limit max', function() {
|
||||
assert.strictEqual(Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 1e9}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 1e9+1}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 1e10}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 1e24}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 1e9}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 1e9+1}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 1e10}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 1e24}).message.limit, 1e9);
|
||||
});
|
||||
|
||||
it('requestAccountLines, account and callback', function() {
|
||||
|
||||
Reference in New Issue
Block a user