Skip to content

Commit

Permalink
Add deprecation warnings to request constructors
Browse files Browse the repository at this point in the history
The first argument to request constructor functions should be an
object containing request properties
  • Loading branch information
wltsmrz committed Jan 27, 2015
1 parent 2833a7b commit eaa4c5d
Show file tree
Hide file tree
Showing 4 changed files with 1,719 additions and 568 deletions.
68 changes: 66 additions & 2 deletions src/js/ripple/remote.js
Expand Up @@ -482,13 +482,13 @@ Remote.prototype.disconnect = function(callback) {

var callback = (typeof callback === 'function') ? callback : function(){};

this._should_connect = false;

if (!this.isConnected()) {
callback();
return this;
}

this._should_connect = false;

this.once('disconnect', callback);

this._servers.forEach(function(server) {
Expand Down Expand Up @@ -865,6 +865,9 @@ Remote.prototype.requestLedger = function(options, callback) {
case 'accounts':
request.message[o] = true;
break;
case 'ledger':
request.selectLedger(options.ledger);
break;
case 'ledger_index':
case 'ledger_hash':
request.message[o] = options[o];
Expand Down Expand Up @@ -1113,6 +1116,14 @@ Remote.prototype.requestTransactionEntry = function(hash, ledgerHash, callback)
// utils.assert(this.trusted);
var request = new Request(this, 'transaction_entry');

if (typeof hash === 'object') {
ledgerHash = hash.ledger || hash.ledger_hash || hash.ledger_index;
hash = hash.hash || hash.tx || hash.transaction;
} else {
console.error('DEPRECATED: First argument to request constructor should be'
+ ' an object containing request properties');
}

request.txHash(hash);

switch (typeof ledgerHash) {
Expand Down Expand Up @@ -1152,6 +1163,8 @@ Remote.prototype.requestTx = function(hash, callback) {

if (typeof hash === 'string') {
options = { hash: hash };
console.error('DEPRECATED: First argument to request constructor should be'
+ ' an object containing request properties');
} else {
options = hash;
}
Expand Down Expand Up @@ -1206,6 +1219,9 @@ Remote.accountRequest = function(type, options, callback) {
peer = options.peer;
limit = options.limit;
marker = options.marker;
} else {
console.error('DEPRECATED: First argument to request constructor should be'
+ ' an object containing request properties');
}

// if a marker is given, we need a ledger
Expand Down Expand Up @@ -1530,6 +1546,13 @@ Remote.prototype.requestTxHistory = function(start, callback) {

var request = new Request(this, 'tx_history');

if (typeof start === 'object') {
start = start.start;
} else {
console.error('DEPRECATED: First argument to request constructor should be'
+ ' an object containing request properties');
}

request.message.start = start;
request.callback(callback);

Expand Down Expand Up @@ -1565,6 +1588,9 @@ Remote.prototype.requestBookOffers = function(gets, pays, taker, callback) {
gets = options.gets || options.taker_gets;
ledger = options.ledger;
limit = options.limit;
} else {
console.error('DEPRECATED: First argument to request constructor should be'
+ ' an object containing request properties');
}

if (typeof lastArg === 'function') {
Expand Down Expand Up @@ -1625,6 +1651,14 @@ Remote.prototype.requestWalletAccounts = function(seed, callback) {
utils.assert(this.trusted); // Don't send secrets.

var request = new Request(this, 'wallet_accounts');

if (typeof seed === 'object') {
seed = seed.seed;
} else {
console.error('DEPRECATED: First argument to request constructor should be'
+ ' an object containing request properties');
}

request.message.seed = seed;
request.callback(callback);

Expand All @@ -1644,6 +1678,15 @@ Remote.prototype.requestSign = function(secret, tx_json, callback) {
utils.assert(this.trusted); // Don't send secrets.

var request = new Request(this, 'sign');

if (typeof secret === 'object') {
tx_json = secret.tx_json;
secret = secret.secret;
} else {
console.error('DEPRECATED: First argument to request constructor should be'
+ ' an object containing request properties');
}

request.message.secret = secret;
request.message.tx_json = tx_json;
request.callback(callback);
Expand Down Expand Up @@ -1762,6 +1805,9 @@ Remote.accountRootRequest = function(type, responseFilter, account, ledger, call
callback = ledger;
ledger = account.ledger;
account = account.account;
} else {
console.error('DEPRECATED: First argument to request constructor should be'
+ ' an object containing request properties');
}

var lastArg = arguments[arguments.length - 1];
Expand Down Expand Up @@ -1911,6 +1957,9 @@ Remote.prototype.createPathFind = function(src_account, dst_account, dst_amount,
dst_amount = options.dst_amount;
dst_account = options.dst_account;
src_account = options.src_account;
} else {
console.error('DEPRECATED: First argument to request constructor should be'
+ ' an object containing request properties');
}

var pathFind = new PathFind(this,
Expand Down Expand Up @@ -1949,6 +1998,9 @@ Remote.prototype.createOrderBook = function(currency_gets, issuer_gets, currency
currency_pays = options.currency_pays;
issuer_gets = options.issuer_gets;
currency_gets = options.currency_gets;
} else {
console.error('DEPRECATED: First argument to request constructor should be'
+ ' an object containing request properties');
}

var gets = Remote.prepareTrade(currency_gets, issuer_gets);
Expand Down Expand Up @@ -2029,6 +2081,9 @@ Remote.prototype.accountSeqCache = function(account, ledger, callback) {
callback = ledger;
ledger = options.ledger;
account = options.account;
} else {
console.error('DEPRECATED: First argument to request constructor should be'
+ ' an object containing request properties');
}

if (!this.accounts.hasOwnProperty(account)) {
Expand Down Expand Up @@ -2135,6 +2190,9 @@ Remote.prototype.requestRippleBalance = function(account, issuer, currency, ledg
currency = options.currency;
issuer = options.issuer;
account = options.account;
} else {
console.error('DEPRECATED: First argument to request constructor should be'
+ ' an object containing request properties');
}

// YYY Could be cached per ledger.
Expand Down Expand Up @@ -2220,6 +2278,9 @@ Remote.prototype.requestRipplePathFind = function(src_account, dst_account, dst_
dst_amount = options.dst_amount;
dst_account = options.dst_account;
src_account = options.src_account;
} else {
console.error('DEPRECATED: First argument to request constructor should be'
+ ' an object containing request properties');
}

var request = new Request(this, 'ripple_path_find');
Expand Down Expand Up @@ -2254,6 +2315,9 @@ Remote.prototype.requestPathFindCreate = function(src_account, dst_account, dst_
dst_amount = options.dst_amount;
dst_account = options.dst_account;
src_account = options.src_account;
} else {
console.error('DEPRECATED: First argument to request constructor should be'
+ ' an object containing request properties');
}

var request = new Request(this, 'path_find');
Expand Down

0 comments on commit eaa4c5d

Please sign in to comment.