mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-27 07:35:52 +00:00
Refactor API deprecation, fix request constructors with positional args
This commit is contained in:
@@ -13,12 +13,12 @@
|
|||||||
// has not yet been implemented. However, this class has been designed for it
|
// has not yet been implemented. However, this class has been designed for it
|
||||||
// to be a very simple drop option.
|
// to be a very simple drop option.
|
||||||
|
|
||||||
const EventEmitter = require('events').EventEmitter;
|
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const _ = require('lodash');
|
||||||
const LRU = require('lru-cache');
|
const LRU = require('lru-cache');
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const lodash = require('lodash');
|
const EventEmitter = require('events').EventEmitter;
|
||||||
const Server = require('./server').Server;
|
const Server = require('./server').Server;
|
||||||
const Request = require('./request').Request;
|
const Request = require('./request').Request;
|
||||||
const Amount = require('./amount').Amount;
|
const Amount = require('./amount').Amount;
|
||||||
@@ -47,7 +47,7 @@ function Remote(options = {}) {
|
|||||||
|
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
lodash.merge(this, lodash.defaults(options, Remote.DEFAULTS));
|
_.merge(this, _.defaults(options, Remote.DEFAULTS));
|
||||||
|
|
||||||
this.state = 'offline'; // 'online', 'offline'
|
this.state = 'offline'; // 'online', 'offline'
|
||||||
this._server_fatal = false; // server exited
|
this._server_fatal = false; // server exited
|
||||||
@@ -152,7 +152,7 @@ function Remote(options = {}) {
|
|||||||
function listenersModified(action, event) {
|
function listenersModified(action, event) {
|
||||||
// Automatically subscribe and unsubscribe to orderbook
|
// Automatically subscribe and unsubscribe to orderbook
|
||||||
// on the basis of existing event listeners
|
// on the basis of existing event listeners
|
||||||
if (lodash.contains(Remote.TRANSACTION_EVENTS, event)) {
|
if (_.contains(Remote.TRANSACTION_EVENTS, event)) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'add':
|
case 'add':
|
||||||
if (++self._transaction_listeners === 1) {
|
if (++self._transaction_listeners === 1) {
|
||||||
@@ -448,7 +448,7 @@ Remote.prototype.disconnect = function(callback_) {
|
|||||||
throw new Error('No servers available, not disconnecting');
|
throw new Error('No servers available, not disconnecting');
|
||||||
}
|
}
|
||||||
|
|
||||||
const callback = lodash.isFunction(callback_)
|
const callback = _.isFunction(callback_)
|
||||||
? callback_
|
? callback_
|
||||||
: function() {};
|
: function() {};
|
||||||
|
|
||||||
@@ -737,7 +737,7 @@ Remote.prototype.request = function(request_) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof this[request] === 'function') {
|
if (typeof this[request] === 'function') {
|
||||||
const args = Array.prototype.slice.call(arguments, 1);
|
const args = _.slice(arguments, 1);
|
||||||
return this[request].apply(this, args);
|
return this[request].apply(this, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -766,6 +766,31 @@ Remote.prototype.request = function(request_) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create options object from positional function arguments
|
||||||
|
*
|
||||||
|
* @param {Array} params function parameters
|
||||||
|
* @param {Array} args function arguments
|
||||||
|
* @return {Object} keyed options
|
||||||
|
*/
|
||||||
|
|
||||||
|
function makeOptions(command, params, args) {
|
||||||
|
const result = {};
|
||||||
|
|
||||||
|
log.warn(
|
||||||
|
'DEPRECATED: First argument to ' + command
|
||||||
|
+ ' request constructor must be an object containing'
|
||||||
|
+ ' request properties: '
|
||||||
|
+ params.join(', ')
|
||||||
|
);
|
||||||
|
|
||||||
|
if (_.isFunction(_.last(args))) {
|
||||||
|
result.callback = args.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
return _.merge(result, _.zipObject(params, args));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request ping
|
* Request ping
|
||||||
*
|
*
|
||||||
@@ -981,7 +1006,7 @@ Remote.prototype.requestLedgerEntry = function(type, callback_) {
|
|||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
const request = new Request(this, 'ledger_entry');
|
const request = new Request(this, 'ledger_entry');
|
||||||
const callback = lodash.isFunction(type) ? type : callback_;
|
const callback = _.isFunction(type) ? type : callback_;
|
||||||
|
|
||||||
// Transparent caching. When .request() is invoked, look in the Remote object
|
// Transparent caching. When .request() is invoked, look in the Remote object
|
||||||
// for the result. If not found, listen, cache result, and emit it.
|
// for the result. If not found, listen, cache result, and emit it.
|
||||||
@@ -1006,7 +1031,6 @@ Remote.prototype.requestLedgerEntry = function(type, callback_) {
|
|||||||
|
|
||||||
if (node) {
|
if (node) {
|
||||||
// Emulate fetch of ledger entry.
|
// Emulate fetch of ledger entry.
|
||||||
// console.log('request_ledger_entry: emulating');
|
|
||||||
// YYY Missing lots of fields.
|
// YYY Missing lots of fields.
|
||||||
request.emit('success', {node: node});
|
request.emit('success', {node: node});
|
||||||
bDefault = false;
|
bDefault = false;
|
||||||
@@ -1016,7 +1040,6 @@ Remote.prototype.requestLedgerEntry = function(type, callback_) {
|
|||||||
case 'account_root':
|
case 'account_root':
|
||||||
request.once('success', function(message) {
|
request.once('success', function(message) {
|
||||||
// Cache node.
|
// Cache node.
|
||||||
// console.log('request_ledger_entry: caching');
|
|
||||||
self.ledgers.current
|
self.ledgers.current
|
||||||
.account_root[message.node.Account] = message.node;
|
.account_root[message.node.Account] = message.node;
|
||||||
});
|
});
|
||||||
@@ -1024,13 +1047,11 @@ Remote.prototype.requestLedgerEntry = function(type, callback_) {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
// This type not cached.
|
// This type not cached.
|
||||||
// console.log('request_ledger_entry: non-cached type');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bDefault) {
|
if (bDefault) {
|
||||||
// console.log('request_ledger_entry: invoking');
|
|
||||||
request.request_default();
|
request.request_default();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1093,26 +1114,17 @@ Remote.prototype.requestUnsubscribe = function(streams, callback) {
|
|||||||
Remote.prototype.requestTransactionEntry = function(options_, callback_) {
|
Remote.prototype.requestTransactionEntry = function(options_, callback_) {
|
||||||
// If not trusted, need to check proof, maybe talk packet protocol.
|
// If not trusted, need to check proof, maybe talk packet protocol.
|
||||||
// utils.assert(this.trusted);
|
// utils.assert(this.trusted);
|
||||||
let options, callback = callback_;
|
const options = {callback: callback_};
|
||||||
|
|
||||||
if (lodash.isPlainObject(options_)) {
|
if (_.isPlainObject(options_)) {
|
||||||
options = lodash.merge({
|
_.merge(options, {
|
||||||
ledger: options_.ledger_index || options_.ledger_hash
|
ledger: options_.ledger_index || options_.ledger_hash
|
||||||
}, options_);
|
}, options_);
|
||||||
} else {
|
} else {
|
||||||
log.warn('DEPRECATED: First argument to request constructor should be'
|
_.merge(options, makeOptions(
|
||||||
+ ' an object containing request properties');
|
'transaction_entry',
|
||||||
|
['hash', 'ledger'],
|
||||||
const args = Array.prototype.slice.call(arguments);
|
_.slice(arguments)));
|
||||||
|
|
||||||
if (lodash.isFunction(lodash.last(args))) {
|
|
||||||
callback = args.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
options = {
|
|
||||||
hash: args.shift(),
|
|
||||||
ledger: args.shift()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const request = new Request(this, 'transaction_entry');
|
const request = new Request(this, 'transaction_entry');
|
||||||
@@ -1130,7 +1142,7 @@ Remote.prototype.requestTransactionEntry = function(options_, callback_) {
|
|||||||
throw new Error('ledger must be a ledger index or hash');
|
throw new Error('ledger must be a ledger index or hash');
|
||||||
}
|
}
|
||||||
|
|
||||||
request.callback(callback);
|
request.callback(options.callback);
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
@@ -1148,24 +1160,16 @@ Remote.prototype.requestTransactionEntry = function(options_, callback_) {
|
|||||||
|
|
||||||
Remote.prototype.requestTransaction =
|
Remote.prototype.requestTransaction =
|
||||||
Remote.prototype.requestTx = function(options_, callback_) {
|
Remote.prototype.requestTx = function(options_, callback_) {
|
||||||
let options, callback = callback_;
|
const options = {callback: callback_};
|
||||||
|
|
||||||
if (lodash.isPlainObject(options_)) {
|
if (_.isPlainObject(options_)) {
|
||||||
options = lodash.merge({}, options_);
|
_.merge(options, options_);
|
||||||
} else {
|
} else {
|
||||||
log.warn('DEPRECATED: First argument to request constructor should be'
|
_.merge(options, makeOptions(
|
||||||
+ ' an object containing request properties');
|
'tx',
|
||||||
|
['hash', 'binary'],
|
||||||
const args = Array.prototype.slice.call(arguments);
|
_.slice(arguments)
|
||||||
|
));
|
||||||
if (lodash.isFunction(lodash.last(args))) {
|
|
||||||
callback = args.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
options = {
|
|
||||||
hash: args.shift(),
|
|
||||||
binary: args.shift()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const request = new Request(this, 'tx');
|
const request = new Request(this, 'tx');
|
||||||
@@ -1175,13 +1179,12 @@ Remote.prototype.requestTx = function(options_, callback_) {
|
|||||||
request.once('success', function(res) {
|
request.once('success', function(res) {
|
||||||
if (options.binary === false) {
|
if (options.binary === false) {
|
||||||
request.emit('transaction', res);
|
request.emit('transaction', res);
|
||||||
return;
|
} else {
|
||||||
|
request.emit('transaction', Remote.parseBinaryTransaction(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
request.emit('transaction', Remote.parseBinaryTransaction(res));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
request.callback(callback, 'transaction');
|
request.callback(options.callback, 'transaction');
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
@@ -1196,7 +1199,7 @@ Remote.prototype.requestTx = function(options_, callback_) {
|
|||||||
* ledger closes. You have to supply a ledger_index or ledger_hash
|
* ledger closes. You have to supply a ledger_index or ledger_hash
|
||||||
* when paging to ensure a complete response
|
* when paging to ensure a complete response
|
||||||
*
|
*
|
||||||
* @param {String} type - request name, e.g. 'account_lines'
|
* @param {String} command - request command, e.g. 'account_lines'
|
||||||
* @param {Object} options - all optional
|
* @param {Object} options - all optional
|
||||||
* @param {String} account - ripple address
|
* @param {String} account - ripple address
|
||||||
* @param {String} peer - ripple address
|
* @param {String} peer - ripple address
|
||||||
@@ -1209,35 +1212,21 @@ Remote.prototype.requestTx = function(options_, callback_) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Remote.accountRequest = function(command, options_, callback_) {
|
Remote.accountRequest = function(command, options_, callback_) {
|
||||||
let options, callback = callback_;
|
const options = {callback: callback_};
|
||||||
|
|
||||||
if (lodash.isPlainObject(options_)) {
|
if (_.isPlainObject(options_)) {
|
||||||
options = lodash.merge({}, options_);
|
_.merge(options, options_);
|
||||||
} else {
|
} else {
|
||||||
log.warn('DEPRECATED: First argument to request constructor should be'
|
_.merge(options, makeOptions(
|
||||||
+ ' an object containing request properties');
|
command,
|
||||||
|
['account', 'ledger', 'peer', 'limit', 'marker'],
|
||||||
const args = Array.prototype.slice.call(arguments);
|
_.slice(arguments, 1)));
|
||||||
|
|
||||||
if (lodash.isFunction(lodash.last(args))) {
|
|
||||||
callback = args.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
options = {
|
|
||||||
account: args.shift(),
|
|
||||||
peer: args.shift(),
|
|
||||||
ledger: args.shift(),
|
|
||||||
limit: args.shift(),
|
|
||||||
marker: args.shift()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const {account, ledger, peer, limit, marker} = options;
|
|
||||||
|
|
||||||
// if a marker is given, we need a ledger
|
// if a marker is given, we need a ledger
|
||||||
// check if a valid ledger_index or ledger_hash is provided
|
// check if a valid ledger_index or ledger_hash is provided
|
||||||
if (marker) {
|
if (options.marker) {
|
||||||
if (!(Number(ledger) > 0) && !UInt256.is_valid(ledger)) {
|
if (!(Number(options.ledger) > 0) && !UInt256.is_valid(options.ledger)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'A ledger_index or ledger_hash must be provided when using a marker');
|
'A ledger_index or ledger_hash must be provided when using a marker');
|
||||||
}
|
}
|
||||||
@@ -1245,18 +1234,15 @@ Remote.accountRequest = function(command, options_, callback_) {
|
|||||||
|
|
||||||
const request = new Request(this, command);
|
const request = new Request(this, command);
|
||||||
|
|
||||||
if (account) {
|
request.message.account = UInt160.json_rewrite(options.account);
|
||||||
request.message.account = UInt160.json_rewrite(account);
|
request.selectLedger(options.ledger);
|
||||||
|
|
||||||
|
if (UInt160.is_valid(options.peer)) {
|
||||||
|
request.message.peer = UInt160.json_rewrite(options.peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
request.selectLedger(ledger);
|
if (!isNaN(options.limit)) {
|
||||||
|
let _limit = Number(options.limit);
|
||||||
if (UInt160.is_valid(peer)) {
|
|
||||||
request.message.peer = UInt160.json_rewrite(peer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isNaN(limit)) {
|
|
||||||
let _limit = Number(limit);
|
|
||||||
|
|
||||||
// max for 32-bit unsigned int is 4294967295
|
// max for 32-bit unsigned int is 4294967295
|
||||||
// we'll clamp to 1e9
|
// we'll clamp to 1e9
|
||||||
@@ -1272,11 +1258,11 @@ Remote.accountRequest = function(command, options_, callback_) {
|
|||||||
request.message.limit = _limit;
|
request.message.limit = _limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (marker) {
|
if (options.marker) {
|
||||||
request.message.marker = marker;
|
request.message.marker = options.marker;
|
||||||
}
|
}
|
||||||
|
|
||||||
request.callback(callback);
|
request.callback(options.callback);
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
@@ -1336,7 +1322,20 @@ Remote.prototype.requestAccountCurrencies = function(...args) {
|
|||||||
Remote.prototype.requestAccountLines = function(...args) {
|
Remote.prototype.requestAccountLines = function(...args) {
|
||||||
// XXX Does this require the server to be trusted?
|
// XXX Does this require the server to be trusted?
|
||||||
// utils.assert(this.trusted);
|
// utils.assert(this.trusted);
|
||||||
const options = ['account_lines', ...args];
|
let options = ['account_lines'];
|
||||||
|
|
||||||
|
if (_.isPlainObject(args[0])) {
|
||||||
|
options = options.concat(args);
|
||||||
|
} else {
|
||||||
|
const [account, peer, ledger] = args;
|
||||||
|
options = options.concat([
|
||||||
|
account,
|
||||||
|
ledger,
|
||||||
|
peer,
|
||||||
|
...args.slice(3)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
return Remote.accountRequest.apply(this, options);
|
return Remote.accountRequest.apply(this, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1549,18 +1548,17 @@ Remote.prototype.requestTxHistory = function(start_, callback_) {
|
|||||||
// utils.assert(this.trusted);
|
// utils.assert(this.trusted);
|
||||||
|
|
||||||
const request = new Request(this, 'tx_history');
|
const request = new Request(this, 'tx_history');
|
||||||
let start = start_;
|
const options = {start: start_, callback: callback_};
|
||||||
const callback = callback_;
|
|
||||||
|
|
||||||
if (lodash.isPlainObject(start)) {
|
if (_.isPlainObject(start_)) {
|
||||||
start = start.start;
|
_.merge(options, start_);
|
||||||
} else {
|
} else {
|
||||||
log.warn('DEPRECATED: First argument to request constructor should be'
|
_.merge(options, makeOptions(
|
||||||
+ ' an object containing request properties');
|
'tx_history', ['start'], _.slice(arguments)));
|
||||||
}
|
}
|
||||||
|
|
||||||
request.message.start = start;
|
request.message.start = options.start;
|
||||||
request.callback(callback);
|
request.callback(options.callback);
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
@@ -1579,34 +1577,22 @@ Remote.prototype.requestTxHistory = function(start_, callback_) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Remote.prototype.requestBookOffers = function(options_, callback_) {
|
Remote.prototype.requestBookOffers = function(options_, callback_) {
|
||||||
let options, callback = callback_;
|
const options = {callback: callback_};
|
||||||
|
|
||||||
if (options_.gets || options_.taker_gets) {
|
if (options_.gets || options_.taker_gets) {
|
||||||
options = lodash.merge({
|
_.merge(options, {
|
||||||
pays: options_.taker_pays,
|
pays: options_.taker_pays,
|
||||||
gets: options_.taker_gets
|
gets: options_.taker_gets
|
||||||
}, options_);
|
}, options_);
|
||||||
} else {
|
} else {
|
||||||
log.warn('DEPRECATED: First argument to request constructor should be'
|
_.merge(options, makeOptions(
|
||||||
+ ' an object containing request properties');
|
'book_offers',
|
||||||
|
['gets', 'pays', 'taker', 'ledger', 'limit'],
|
||||||
const args = Array.prototype.slice.call(arguments);
|
_.slice(arguments)
|
||||||
|
));
|
||||||
if (lodash.isFunction(lodash.last(args))) {
|
|
||||||
callback = args.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
options = {
|
|
||||||
gets: args.shift(),
|
|
||||||
pays: args.shift(),
|
|
||||||
taker: args.shift(),
|
|
||||||
ledger: args.shift(),
|
|
||||||
limit: args.shift()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const {gets, pays, taker, ledger, limit} = options;
|
const {gets, pays, taker, ledger, limit} = options;
|
||||||
|
|
||||||
const request = new Request(this, 'book_offers');
|
const request = new Request(this, 'book_offers');
|
||||||
|
|
||||||
request.message.taker_gets = {
|
request.message.taker_gets = {
|
||||||
@@ -1645,7 +1631,7 @@ Remote.prototype.requestBookOffers = function(options_, callback_) {
|
|||||||
request.message.limit = _limit;
|
request.message.limit = _limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
request.callback(callback);
|
request.callback(options.callback);
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1660,23 +1646,21 @@ Remote.prototype.requestBookOffers = function(options_, callback_) {
|
|||||||
Remote.prototype.requestWalletAccounts = function(options_, callback_) {
|
Remote.prototype.requestWalletAccounts = function(options_, callback_) {
|
||||||
utils.assert(this.trusted); // Don't send secrets.
|
utils.assert(this.trusted); // Don't send secrets.
|
||||||
|
|
||||||
let options;
|
const options = {callback: callback_};
|
||||||
const callback = callback_;
|
|
||||||
|
|
||||||
if (lodash.isPlainObject(options_)) {
|
if (_.isPlainObject(options_)) {
|
||||||
options = lodash.merge({}, options_);
|
_.merge(options, options_);
|
||||||
} else {
|
} else {
|
||||||
log.warn('DEPRECATED: First argument to request constructor should be'
|
_.merge(options, makeOptions(
|
||||||
+ ' an object containing request properties');
|
'wallet_accounts',
|
||||||
|
['seed'],
|
||||||
options = {
|
_.slice(arguments)
|
||||||
seed: arguments[0]
|
));
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const request = new Request(this, 'wallet_accounts');
|
const request = new Request(this, 'wallet_accounts');
|
||||||
request.message.seed = options.seed;
|
request.message.seed = options.seed;
|
||||||
request.callback(callback);
|
request.callback(options.callback);
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
@@ -1693,26 +1677,22 @@ Remote.prototype.requestWalletAccounts = function(options_, callback_) {
|
|||||||
Remote.prototype.requestSign = function(options_, callback_) {
|
Remote.prototype.requestSign = function(options_, callback_) {
|
||||||
utils.assert(this.trusted); // Don't send secrets.
|
utils.assert(this.trusted); // Don't send secrets.
|
||||||
|
|
||||||
let options, callback = callback_;
|
const options = {callback: callback_};
|
||||||
|
|
||||||
if (lodash.isPlainObject(options_)) {
|
if (_.isPlainObject(options_)) {
|
||||||
options = lodash.merge({}, options_);
|
_.merge(options, options_);
|
||||||
} else {
|
} else {
|
||||||
log.warn('DEPRECATED: First argument to request constructor should be'
|
_.merge(options, makeOptions(
|
||||||
+ ' an object containing request properties');
|
'sign',
|
||||||
|
['secret', 'tx_json'],
|
||||||
options = {
|
_.slice(arguments)
|
||||||
secret: arguments[0],
|
));
|
||||||
tx_json: arguments[1]
|
|
||||||
};
|
|
||||||
|
|
||||||
callback = arguments[2];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const request = new Request(this, 'sign');
|
const request = new Request(this, 'sign');
|
||||||
request.message.secret = options.secret;
|
request.message.secret = options.secret;
|
||||||
request.message.tx_json = options.tx_json;
|
request.message.tx_json = options.tx_json;
|
||||||
request.callback(callback);
|
request.callback(options.callback);
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
@@ -1743,7 +1723,7 @@ Remote.prototype.requestSubmit = function(callback) {
|
|||||||
Remote.prototype._serverPrepareSubscribe = function(server, callback_) {
|
Remote.prototype._serverPrepareSubscribe = function(server, callback_) {
|
||||||
const self = this;
|
const self = this;
|
||||||
const feeds = ['ledger', 'server'];
|
const feeds = ['ledger', 'server'];
|
||||||
const callback = lodash.isFunction(server) ? server : callback_;
|
const callback = _.isFunction(server) ? server : callback_;
|
||||||
|
|
||||||
if (this._transaction_listeners) {
|
if (this._transaction_listeners) {
|
||||||
feeds.push('transactions');
|
feeds.push('transactions');
|
||||||
@@ -1812,24 +1792,15 @@ Remote.prototype.requestLedgerAccept = function(callback) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Remote.accountRootRequest = function(command, filter, options_, callback_) {
|
Remote.accountRootRequest = function(command, filter, options_, callback_) {
|
||||||
let options, callback = callback_;
|
const options = {callback: callback_};
|
||||||
|
|
||||||
if (lodash.isPlainObject(options_)) {
|
if (_.isPlainObject(options_)) {
|
||||||
options = lodash.merge({}, options_);
|
_.merge(options, options_);
|
||||||
} else {
|
} else {
|
||||||
log.warn('DEPRECATED: First argument to request constructor should be'
|
_.merge(options, makeOptions(
|
||||||
+ ' an object containing request properties');
|
command,
|
||||||
|
['account', 'ledger'],
|
||||||
const args = Array.prototype.slice.call(arguments);
|
_.slice(arguments, 2)));
|
||||||
|
|
||||||
if (lodash.isFunction(lodash.last(args))) {
|
|
||||||
callback = args.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
options = {
|
|
||||||
account: args.shift(),
|
|
||||||
ledger: args.shift()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const request = this.requestLedgerEntry('account_root');
|
const request = this.requestLedgerEntry('account_root');
|
||||||
@@ -1840,7 +1811,7 @@ Remote.accountRootRequest = function(command, filter, options_, callback_) {
|
|||||||
request.emit(command, filter(message));
|
request.emit(command, filter(message));
|
||||||
});
|
});
|
||||||
|
|
||||||
request.callback(callback, command);
|
request.callback(options.callback, command);
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
@@ -1950,20 +1921,16 @@ Remote.prototype.findAccount = function(accountID) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function createPathFind(options_) {
|
function createPathFind(options_) {
|
||||||
let options;
|
const options = {};
|
||||||
|
|
||||||
if (lodash.isPlainObject(options_)) {
|
if (_.isPlainObject(options_)) {
|
||||||
options = lodash.merge({}, options_);
|
_.merge(options, options_);
|
||||||
} else {
|
} else {
|
||||||
log.warn('DEPRECATED: First argument to request constructor should be'
|
_.merge(options, makeOptions(
|
||||||
+ ' an object containing request properties');
|
'pathfind',
|
||||||
|
['src_account', 'dst_account', 'dst_amount', 'src_currencies'],
|
||||||
options = {
|
_.slice(arguments)
|
||||||
src_account: arguments[0],
|
));
|
||||||
dst_account: arguments[1],
|
|
||||||
dst_amount: arguments[2],
|
|
||||||
src_currencies: arguments[3]
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const pathFind = new PathFind(this,
|
const pathFind = new PathFind(this,
|
||||||
@@ -1997,19 +1964,16 @@ Remote.prepareTrade = function(currency, issuer) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Remote.prototype.book = Remote.prototype.createOrderBook = function(options_) {
|
Remote.prototype.book = Remote.prototype.createOrderBook = function(options_) {
|
||||||
let options;
|
const options = {};
|
||||||
|
|
||||||
if (arguments.length === 1) {
|
if (arguments.length === 1) {
|
||||||
options = lodash.merge({}, options_);
|
_.merge(options, options_);
|
||||||
} else {
|
} else {
|
||||||
log.warn('DEPRECATED: First argument to request constructor should be'
|
_.merge(options, makeOptions(
|
||||||
+ ' an object containing request properties');
|
'orderbook',
|
||||||
options = {
|
['currency_gets', 'issuer_gets', 'currency_pays', 'issuer_pays'],
|
||||||
currency_gets: arguments[0],
|
_.slice(arguments)
|
||||||
issuer_gets: arguments[1],
|
));
|
||||||
currency_pays: arguments[2],
|
|
||||||
issuer_pays: arguments[3]
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const gets = Remote.prepareTrade(options.currency_gets, options.issuer_gets);
|
const gets = Remote.prepareTrade(options.currency_gets, options.issuer_gets);
|
||||||
@@ -2085,24 +2049,15 @@ Remote.prototype.setAccountSeq = function(account_, sequence) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Remote.prototype.accountSeqCache = function(options_, callback_) {
|
Remote.prototype.accountSeqCache = function(options_, callback_) {
|
||||||
let options, callback = callback_;
|
const options = {callback: callback_};
|
||||||
|
|
||||||
if (lodash.isPlainObject(options_)) {
|
if (_.isPlainObject(options_)) {
|
||||||
options = lodash.merge({}, options_);
|
_.merge(options, options_);
|
||||||
} else {
|
} else {
|
||||||
log.warn('DEPRECATED: First argument to request constructor should be'
|
_.merge(options, makeOptions(
|
||||||
+ ' an object containing request properties');
|
'accountseqcache',
|
||||||
|
['account', 'ledger']
|
||||||
const args = Array.prototype.slice.call(arguments);
|
));
|
||||||
|
|
||||||
if (lodash.isFunction(lodash.last(args))) {
|
|
||||||
callback = args.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
options = {
|
|
||||||
account: args.shift(),
|
|
||||||
ledger: args.shift()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.accounts.hasOwnProperty(options.account)) {
|
if (!this.accounts.hasOwnProperty(options.account)) {
|
||||||
@@ -2131,7 +2086,7 @@ Remote.prototype.accountSeqCache = function(options_, callback_) {
|
|||||||
request = this.requestLedgerEntry('account_root');
|
request = this.requestLedgerEntry('account_root');
|
||||||
request.accountRoot(options.account);
|
request.accountRoot(options.account);
|
||||||
|
|
||||||
if (!lodash.isUndefined(options.ledger)) {
|
if (!_.isUndefined(options.ledger)) {
|
||||||
request.selectLedger(options.ledger);
|
request.selectLedger(options.ledger);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2141,7 +2096,7 @@ Remote.prototype.accountSeqCache = function(options_, callback_) {
|
|||||||
account_info.caching_seq_request = request;
|
account_info.caching_seq_request = request;
|
||||||
}
|
}
|
||||||
|
|
||||||
request.callback(callback, 'success_cache', 'error_cache');
|
request.callback(options.callback, 'success_cache', 'error_cache');
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
@@ -2207,33 +2162,24 @@ Remote.prototype.requestOffer = function(options, callback) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Remote.prototype.requestRippleBalance = function(options_, callback_) {
|
Remote.prototype.requestRippleBalance = function(options_, callback_) {
|
||||||
let options, callback = callback_;
|
const options = {callback: callback_};
|
||||||
|
|
||||||
if (lodash.isPlainObject(options_)) {
|
if (_.isPlainObject(options_)) {
|
||||||
options = lodash.merge({}, options_);
|
_.merge(options, options_);
|
||||||
} else {
|
} else {
|
||||||
log.warn('DEPRECATED: First argument to request constructor should be'
|
_.merge(options, makeOptions(
|
||||||
+ ' an object containing request properties');
|
'ripplebalance',
|
||||||
|
['account', 'issuer', 'currency', 'ledger'],
|
||||||
|
_.slice(arguments)
|
||||||
|
));
|
||||||
|
|
||||||
const args = Array.prototype.slice.call(arguments);
|
|
||||||
|
|
||||||
if (lodash.isFunction(lodash.last(args))) {
|
|
||||||
callback = args.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
options = {
|
|
||||||
account: args.shift(),
|
|
||||||
issuer: args.shift(),
|
|
||||||
currency: args.shift(),
|
|
||||||
ledger: args.shift()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// YYY Could be cached per ledger.
|
// YYY Could be cached per ledger.
|
||||||
const request = this.requestLedgerEntry('ripple_state');
|
const request = this.requestLedgerEntry('ripple_state');
|
||||||
request.rippleState(options.account, options.issuer, options.currency);
|
request.rippleState(options.account, options.issuer, options.currency);
|
||||||
|
|
||||||
if (!lodash.isUndefined(options.ledger)) {
|
if (!_.isUndefined(options.ledger)) {
|
||||||
request.selectLedger(options.ledger);
|
request.selectLedger(options.ledger);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2279,7 +2225,7 @@ Remote.prototype.requestRippleBalance = function(options_, callback_) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
request.once('success', rippleState);
|
request.once('success', rippleState);
|
||||||
request.callback(callback, 'ripple_state');
|
request.callback(options.callback, 'ripple_state');
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
@@ -2309,31 +2255,23 @@ Remote.prepareCurrencies = function(currency) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Remote.prototype.requestRipplePathFind = function(options_, callback_) {
|
Remote.prototype.requestRipplePathFind = function(options_, callback_) {
|
||||||
let options, callback = callback_;
|
const options = {callback: callback_};
|
||||||
|
|
||||||
if (lodash.isPlainObject(options_)) {
|
if (_.isPlainObject(options_)) {
|
||||||
options = lodash.merge({
|
_.merge(options, {
|
||||||
source_account: options_.src_account,
|
source_account: options_.src_account,
|
||||||
destination_account: options_.dst_account,
|
destination_account: options_.dst_account,
|
||||||
destination_amount: options_.dst_amount,
|
destination_amount: options_.dst_amount,
|
||||||
source_currencies: options_.src_currencies
|
source_currencies: options_.src_currencies
|
||||||
}, options_);
|
}, options_);
|
||||||
} else {
|
} else {
|
||||||
log.warn('DEPRECATED: First argument to request constructor should be'
|
_.merge(options, makeOptions(
|
||||||
+ ' an object containing request properties');
|
'ripple_path_find',
|
||||||
|
/* eslint-disable max-len */
|
||||||
const args = Array.prototype.slice.call(arguments);
|
['source_account', 'destination_account', 'destination_amount', 'source_currencies'],
|
||||||
|
/* eslint-enable max-len */
|
||||||
if (lodash.isFunction(lodash.last(args))) {
|
_.slice(arguments)
|
||||||
callback = args.pop();
|
));
|
||||||
}
|
|
||||||
|
|
||||||
options = {
|
|
||||||
source_account: args.shift(),
|
|
||||||
destination_account: args.shift(),
|
|
||||||
destination_amount: args.shift(),
|
|
||||||
source_currencies: args.shift()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const request = new Request(this, 'ripple_path_find');
|
const request = new Request(this, 'ripple_path_find');
|
||||||
@@ -2351,7 +2289,7 @@ Remote.prototype.requestRipplePathFind = function(options_, callback_) {
|
|||||||
options.source_currencies.map(Remote.prepareCurrency);
|
options.source_currencies.map(Remote.prepareCurrency);
|
||||||
}
|
}
|
||||||
|
|
||||||
request.callback(callback);
|
request.callback(options.callback);
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
@@ -2365,31 +2303,23 @@ Remote.prototype.requestRipplePathFind = function(options_, callback_) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Remote.prototype.requestPathFindCreate = function(options_, callback_) {
|
Remote.prototype.requestPathFindCreate = function(options_, callback_) {
|
||||||
let options, callback = callback_;
|
const options = {callback: callback_};
|
||||||
|
|
||||||
if (lodash.isPlainObject(options_)) {
|
if (_.isPlainObject(options_)) {
|
||||||
options = lodash.merge({
|
_.merge(options, {
|
||||||
source_account: options_.src_account,
|
source_account: options_.src_account,
|
||||||
destination_account: options_.dst_account,
|
destination_account: options_.dst_account,
|
||||||
destination_amount: options_.dst_amount,
|
destination_amount: options_.dst_amount,
|
||||||
source_currencies: options_.src_currencies
|
source_currencies: options_.src_currencies
|
||||||
}, options_);
|
}, options_);
|
||||||
} else {
|
} else {
|
||||||
log.warn('DEPRECATED: First argument to request constructor should be'
|
_.merge(options, makeOptions(
|
||||||
+ ' an object containing request properties');
|
'path_find',
|
||||||
|
/* eslint-disable max-len */
|
||||||
const args = Array.prototype.slice.call(arguments);
|
['source_account', 'destination_account', 'destination_amount', 'source_currencies'],
|
||||||
|
/* eslint-enable max-len */
|
||||||
if (lodash.isFunction(lodash.last(args))) {
|
_.slice(arguments)
|
||||||
callback = args.pop();
|
));
|
||||||
}
|
|
||||||
|
|
||||||
options = {
|
|
||||||
source_account: args.shift(),
|
|
||||||
destination_account: args.shift(),
|
|
||||||
destination_amount: args.shift(),
|
|
||||||
source_currencies: args.shift()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const request = new Request(this, 'path_find');
|
const request = new Request(this, 'path_find');
|
||||||
@@ -2408,7 +2338,7 @@ Remote.prototype.requestPathFindCreate = function(options_, callback_) {
|
|||||||
options.source_currencies.map(Remote.prepareCurrency);
|
options.source_currencies.map(Remote.prepareCurrency);
|
||||||
}
|
}
|
||||||
|
|
||||||
request.callback(callback);
|
request.callback(options.callback);
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
|
|||||||
1141
test/remote-test.js
1141
test/remote-test.js
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user