mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 04:05:52 +00:00
[TASK] change accountRequest method signature
`(type, options, callback)` where the last argument will be considered for callback if it's a function
This commit is contained in:
@@ -211,7 +211,7 @@ Account.prototype.lines = function(callback) {
|
||||
}
|
||||
}
|
||||
|
||||
this._remote.requestAccountLines(this._account_id, accountLines);
|
||||
this._remote.requestAccountLines({account: this._account_id}, accountLines);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -344,7 +344,7 @@ OrderBook.prototype.requestTransferRate = function(callback) {
|
||||
return this.emit('transfer_rate', this._issuerTransferRate);
|
||||
}
|
||||
|
||||
this._remote.requestAccountInfo(issuer, function(err, info) {
|
||||
this._remote.requestAccountInfo({account: issuer}, function(err, info) {
|
||||
if (err) {
|
||||
// XXX What now?
|
||||
return callback(err);
|
||||
@@ -447,7 +447,7 @@ OrderBook.prototype.requestFundedAmount = function(account, callback) {
|
||||
}
|
||||
|
||||
function requestNativeBalance(callback) {
|
||||
self._remote.requestAccountInfo(account, function(err, info) {
|
||||
self._remote.requestAccountInfo({account: account}, function(err, info) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
@@ -458,8 +458,8 @@ OrderBook.prototype.requestFundedAmount = function(account, callback) {
|
||||
|
||||
function requestLineBalance(callback) {
|
||||
var request = self._remote.requestAccountLines(
|
||||
account,
|
||||
{
|
||||
account: account,
|
||||
ledger: 'validated',
|
||||
peer: self._issuerGets
|
||||
}
|
||||
|
||||
@@ -1218,10 +1218,11 @@ Remote.prototype.requestTx = function(hash, callback) {
|
||||
* @param [Function] callback
|
||||
* @return {Request}
|
||||
*/
|
||||
Remote.accountRequest = function(type, account, options, callback) {
|
||||
var ledger, peer, limit, marker;
|
||||
Remote.accountRequest = function(type, options, callback) {
|
||||
var account, ledger, peer, limit, marker;
|
||||
|
||||
if (typeof options === 'object') {
|
||||
account = options.account;
|
||||
ledger = options.ledger;
|
||||
peer = options.peer;
|
||||
limit = options.limit;
|
||||
@@ -1243,9 +1244,12 @@ Remote.accountRequest = function(type, account, options, callback) {
|
||||
}
|
||||
|
||||
var request = new Request(this, type);
|
||||
var account = UInt160.json_rewrite(account);
|
||||
|
||||
if (account) {
|
||||
account = UInt160.json_rewrite(account);
|
||||
request.message.account = account;
|
||||
}
|
||||
|
||||
request.ledgerSelect(ledger);
|
||||
|
||||
if (UInt160.is_valid(peer)) {
|
||||
@@ -1280,15 +1284,15 @@ Remote.accountRequest = function(type, account, options, callback) {
|
||||
/**
|
||||
* Request account_info
|
||||
*
|
||||
* @param {String} account - ripple address
|
||||
* @param {Object} options
|
||||
* @param {String} account - ripple address
|
||||
* @param {String} peer - ripple address
|
||||
* @param [String|Number] ledger identifier
|
||||
* @param [Function] callback
|
||||
* @return {Request}
|
||||
*/
|
||||
|
||||
Remote.prototype.requestAccountInfo = function(account, options, callback) {
|
||||
Remote.prototype.requestAccountInfo = function(options, callback) {
|
||||
var args = Array.prototype.concat.apply(['account_info'], arguments);
|
||||
return Remote.accountRequest.apply(this, args);
|
||||
};
|
||||
@@ -1296,15 +1300,15 @@ Remote.prototype.requestAccountInfo = function(account, options, callback) {
|
||||
/**
|
||||
* Request account_currencies
|
||||
*
|
||||
* @param {String} account - ripple address
|
||||
* @param {Object} options
|
||||
* @param {String} account - ripple address
|
||||
* @param {String} peer - ripple address
|
||||
* @param [String|Number] ledger identifier
|
||||
* @param [Function] callback
|
||||
* @return {Request}
|
||||
*/
|
||||
|
||||
Remote.prototype.requestAccountCurrencies = function(account, options, callback) {
|
||||
Remote.prototype.requestAccountCurrencies = function(options, callback) {
|
||||
var args = Array.prototype.concat.apply(['account_currencies'], arguments);
|
||||
return Remote.accountRequest.apply(this, args);
|
||||
};
|
||||
@@ -1319,8 +1323,8 @@ Remote.prototype.requestAccountCurrencies = function(account, options, callback)
|
||||
* 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} account - ripple address
|
||||
* @param {String} peer - ripple address
|
||||
* @param [String|Number] ledger identifier
|
||||
* @param [Number] limit - max results per response
|
||||
@@ -1329,7 +1333,7 @@ Remote.prototype.requestAccountCurrencies = function(account, options, callback)
|
||||
* @return {Request}
|
||||
*/
|
||||
|
||||
Remote.prototype.requestAccountLines = function(account, options, callback) {
|
||||
Remote.prototype.requestAccountLines = function(options, callback) {
|
||||
// XXX Does this require the server to be trusted?
|
||||
//utils.assert(this.trusted);
|
||||
var args = Array.prototype.concat.apply(['account_lines'], arguments);
|
||||
@@ -1346,8 +1350,8 @@ Remote.prototype.requestAccountLines = function(account, options, callback) {
|
||||
* 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} account - ripple address
|
||||
* @param [String|Number] ledger identifier
|
||||
* @param [Number] limit - max results per response
|
||||
* @param {String} marker - start position in response paging
|
||||
@@ -1355,7 +1359,7 @@ Remote.prototype.requestAccountLines = function(account, options, callback) {
|
||||
* @return {Request}
|
||||
*/
|
||||
|
||||
Remote.prototype.requestAccountOffers = function(account, options, callback) {
|
||||
Remote.prototype.requestAccountOffers = function(options, callback) {
|
||||
var args = Array.prototype.concat.apply(['account_offers'], arguments);
|
||||
return Remote.accountRequest.apply(this, args);
|
||||
};
|
||||
|
||||
@@ -193,25 +193,25 @@ describe('Remote', function () {
|
||||
});
|
||||
|
||||
it('request account currencies with ledger index', function() {
|
||||
var request = remote.requestAccountCurrencies(ADDRESS);
|
||||
var request = remote.requestAccountCurrencies({account: ADDRESS});
|
||||
assert.strictEqual(request.message.command, 'account_currencies');
|
||||
assert.strictEqual(request.message.account, ADDRESS);
|
||||
});
|
||||
|
||||
it('request account info with ledger index', function() {
|
||||
var request = remote.requestAccountInfo(ADDRESS, {ledger: 9592219});
|
||||
var request = remote.requestAccountInfo({account: ADDRESS, ledger: 9592219});
|
||||
assert.strictEqual(request.message.command, 'account_info');
|
||||
assert.strictEqual(request.message.account, ADDRESS);
|
||||
assert.strictEqual(request.message.ledger_index, 9592219);
|
||||
});
|
||||
it('request account info with ledger hash', function() {
|
||||
var request = remote.requestAccountInfo(ADDRESS, {ledger: LEDGER_HASH});
|
||||
var request = remote.requestAccountInfo({account: ADDRESS, ledger: LEDGER_HASH});
|
||||
assert.strictEqual(request.message.command, 'account_info');
|
||||
assert.strictEqual(request.message.account, ADDRESS);
|
||||
assert.strictEqual(request.message.ledger_hash, LEDGER_HASH);
|
||||
});
|
||||
it('request account info with ledger identifier', function() {
|
||||
var request = remote.requestAccountInfo(ADDRESS, {ledger: 'validated'});
|
||||
var request = remote.requestAccountInfo({account: ADDRESS, ledger: 'validated'});
|
||||
assert.strictEqual(request.message.command, 'account_info');
|
||||
assert.strictEqual(request.message.account, ADDRESS);
|
||||
assert.strictEqual(request.message.ledger_index, 'validated');
|
||||
@@ -238,7 +238,7 @@ describe('Remote', function () {
|
||||
});
|
||||
|
||||
it('pagingAccountRequest', function() {
|
||||
var request = Remote.accountRequest('account_lines', ADDRESS);
|
||||
var request = Remote.accountRequest('account_lines', {account: ADDRESS});
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_lines',
|
||||
id: undefined,
|
||||
@@ -247,7 +247,7 @@ describe('Remote', function () {
|
||||
});
|
||||
|
||||
it('pagingAccountRequest - limit', function() {
|
||||
var request = Remote.accountRequest('account_lines', ADDRESS, {limit: 100});
|
||||
var request = Remote.accountRequest('account_lines', {account: ADDRESS, limit: 100});
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_lines',
|
||||
id: undefined,
|
||||
@@ -257,7 +257,7 @@ describe('Remote', function () {
|
||||
});
|
||||
|
||||
it('pagingAccountRequest - limit, marker', function() {
|
||||
var request = Remote.accountRequest('account_lines', ADDRESS, {limit: 100, marker: PAGING_MARKER, ledger: 9592219});
|
||||
var request = Remote.accountRequest('account_lines', {account: ADDRESS, limit: 100, marker: PAGING_MARKER, ledger: 9592219});
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_lines',
|
||||
id: undefined,
|
||||
@@ -271,38 +271,38 @@ describe('Remote', function () {
|
||||
});
|
||||
|
||||
it('accountRequest - limit min', function() {
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', ADDRESS, {limit: 0}).message.limit, 0);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', ADDRESS, {limit: -1}).message.limit, 0);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', ADDRESS, {limit: -1e9}).message.limit, 0);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', ADDRESS, {limit: -1e24}).message.limit, 0);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: 0}).message.limit, 0);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: -1}).message.limit, 0);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: -1e9}).message.limit, 0);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: -1e24}).message.limit, 0);
|
||||
});
|
||||
|
||||
it('accountRequest - limit max', function() {
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', ADDRESS, {limit: 1e9}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', ADDRESS, {limit: 1e9+1}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', ADDRESS, {limit: 1e10}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', ADDRESS, {limit: 1e24}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: 1e9}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: 1e9+1}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: 1e10}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: 1e24}).message.limit, 1e9);
|
||||
});
|
||||
|
||||
it('accountRequest - a valid ledger is required when using a marker', function() {
|
||||
assert.throws(function() {
|
||||
Remote.accountRequest('account_lines', ADDRESS, {marker: PAGING_MARKER})
|
||||
Remote.accountRequest('account_lines', {account: ADDRESS, marker: PAGING_MARKER})
|
||||
},'A ledger_index or ledger_hash must be provided when using a marker');
|
||||
|
||||
assert.throws(function() {
|
||||
Remote.accountRequest('account_lines', ADDRESS, {marker: PAGING_MARKER, ledger:'validated'})
|
||||
Remote.accountRequest('account_lines', {account: ADDRESS, marker: PAGING_MARKER, ledger:'validated'})
|
||||
},'A ledger_index or ledger_hash must be provided when using a marker');
|
||||
|
||||
assert.throws(function() {
|
||||
Remote.accountRequest('account_lines', ADDRESS, {marker: PAGING_MARKER, ledger:NaN})
|
||||
Remote.accountRequest('account_lines', {account: ADDRESS, marker: PAGING_MARKER, ledger:NaN})
|
||||
},'A ledger_index or ledger_hash must be provided when using a marker');
|
||||
|
||||
assert.throws(function() {
|
||||
Remote.accountRequest('account_lines', ADDRESS, {marker: PAGING_MARKER, ledger:LEDGER_HASH.substr(0,63)})
|
||||
Remote.accountRequest('account_lines', {account: ADDRESS, marker: PAGING_MARKER, ledger:LEDGER_HASH.substr(0,63)})
|
||||
},'A ledger_index or ledger_hash must be provided when using a marker');
|
||||
|
||||
assert.throws(function() {
|
||||
Remote.accountRequest('account_lines', ADDRESS, {marker: PAGING_MARKER, ledger:LEDGER_HASH+'F'})
|
||||
Remote.accountRequest('account_lines', {account: ADDRESS, marker: PAGING_MARKER, ledger:LEDGER_HASH+'F'})
|
||||
},'A ledger_index or ledger_hash must be provided when using a marker');
|
||||
});
|
||||
|
||||
@@ -312,7 +312,7 @@ describe('Remote', function () {
|
||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
||||
});
|
||||
var request = remote.requestAccountLines(
|
||||
ADDRESS,
|
||||
{account: ADDRESS},
|
||||
callback
|
||||
);
|
||||
|
||||
@@ -331,8 +331,8 @@ describe('Remote', function () {
|
||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
||||
});
|
||||
var request = remote.requestAccountLines(
|
||||
ADDRESS,
|
||||
{
|
||||
account: ADDRESS,
|
||||
ledger: LEDGER_HASH,
|
||||
peer: PEER_ADDRESS
|
||||
},
|
||||
@@ -356,8 +356,8 @@ describe('Remote', function () {
|
||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
||||
});
|
||||
var request = remote.requestAccountLines(
|
||||
ADDRESS,
|
||||
{
|
||||
account: ADDRESS,
|
||||
ledger: LEDGER_INDEX,
|
||||
peer: PEER_ADDRESS,
|
||||
limit: 200,
|
||||
@@ -385,8 +385,8 @@ describe('Remote', function () {
|
||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
||||
});
|
||||
var request = remote.requestAccountOffers(
|
||||
ADDRESS,
|
||||
{
|
||||
account: ADDRESS,
|
||||
ledger: LEDGER_HASH,
|
||||
peer: PEER_ADDRESS,
|
||||
limit: 32,
|
||||
|
||||
Reference in New Issue
Block a user