@@ -40,14 +40,22 @@ var log = require('./log').internal.sub('remote');
40
40
/**
41
41
* Interface to manage connections to rippled servers
42
42
*
43
- * @param {Object } Connection options.
43
+ * @param {Object } Options
44
44
*/
45
45
46
46
function Remote ( opts ) {
47
47
EventEmitter . call ( this ) ;
48
48
49
49
var self = this ;
50
- var opts = lodash . extend ( this , Remote . DEFAULTS , opts ) ;
50
+ var opts = opts || { } ;
51
+
52
+ Object . keys ( Remote . DEFAULTS ) . forEach ( function ( config ) {
53
+ if ( opts . hasOwnProperty ( config ) ) {
54
+ this [ config ] = opts [ config ] ;
55
+ } else {
56
+ this [ config ] = Remote . DEFAULTS [ config ] ;
57
+ }
58
+ } , this ) ;
51
59
52
60
this . state = 'offline' ; // 'online', 'offline'
53
61
this . _server_fatal = false ; // server exited
@@ -102,13 +110,13 @@ function Remote(opts) {
102
110
}
103
111
} ;
104
112
105
- if ( typeof opts . trusted !== 'boolean' ) {
113
+ if ( typeof this . trusted !== 'boolean' ) {
106
114
throw new TypeError ( 'trusted must be a boolean' ) ;
107
115
}
108
- if ( typeof opts . trace !== 'boolean' ) {
116
+ if ( typeof this . trace !== 'boolean' ) {
109
117
throw new TypeError ( 'trace must be a boolean' ) ;
110
118
}
111
- if ( typeof opts . allow_partial_history !== 'boolean' ) {
119
+ if ( typeof this . allow_partial_history !== 'boolean' ) {
112
120
throw new TypeError ( 'allow_partial_history must be a boolean' ) ;
113
121
}
114
122
if ( typeof this . max_fee !== 'number' ) {
@@ -138,21 +146,21 @@ function Remote(opts) {
138
146
if ( typeof this . last_ledger_offset !== 'number' ) {
139
147
throw new TypeError ( 'last_ledger_offset must be a number' ) ;
140
148
}
141
- if ( ! Array . isArray ( opts . servers ) ) {
149
+ if ( ! Array . isArray ( this . servers ) ) {
142
150
throw new TypeError ( 'servers must be an array' ) ;
143
151
}
144
152
145
153
this . setMaxListeners ( this . max_listeners ) ;
146
154
147
- this . servers . forEach ( function ( server ) {
148
- var connection = self . addServer ( server ) ;
149
- connection . setMaxListeners ( self . max_listeners ) ;
155
+ this . servers . forEach ( function ( serverOptions ) {
156
+ var server = self . addServer ( serverOptions ) ;
157
+ server . setMaxListeners ( self . max_listeners ) ;
150
158
} ) ;
151
159
152
160
function listenersModified ( action , event ) {
153
161
// Automatically subscribe and unsubscribe to orderbook
154
162
// on the basis of existing event listeners
155
- if ( ~ Remote . TRANSACTION_EVENTS . indexOf ( event ) ) {
163
+ if ( lodash . contains ( Remote . TRANSACTION_EVENTS , event ) ) {
156
164
switch ( action ) {
157
165
case 'add' :
158
166
if ( ++ self . _transaction_listeners === 1 ) {
@@ -441,22 +449,13 @@ Remote.prototype.reconnect = function() {
441
449
* @api public
442
450
*/
443
451
444
- Remote . prototype . connect = function ( online ) {
452
+ Remote . prototype . connect = function ( callback ) {
445
453
if ( ! this . _servers . length ) {
446
454
throw new Error ( 'No servers available.' ) ;
447
455
}
448
456
449
- switch ( typeof online ) {
450
- case 'undefined' :
451
- break ;
452
- case 'function' :
453
- this . once ( 'connect' , online ) ;
454
- break ;
455
- default :
456
- // Downwards compatibility
457
- if ( ! Boolean ( online ) ) {
458
- return this . disconnect ( ) ;
459
- }
457
+ if ( typeof callback === 'function' ) {
458
+ this . once ( 'connect' , callback ) ;
460
459
}
461
460
462
461
this . _should_connect = true ;
@@ -482,13 +481,13 @@ Remote.prototype.disconnect = function(callback) {
482
481
483
482
var callback = ( typeof callback === 'function' ) ? callback : function ( ) { } ;
484
483
484
+ this . _should_connect = false ;
485
+
485
486
if ( ! this . isConnected ( ) ) {
486
487
callback ( ) ;
487
488
return this ;
488
489
}
489
490
490
- this . _should_connect = false ;
491
-
492
491
this . once ( 'disconnect' , callback ) ;
493
492
494
493
this . _servers . forEach ( function ( server ) {
@@ -865,6 +864,9 @@ Remote.prototype.requestLedger = function(options, callback) {
865
864
case 'accounts' :
866
865
request . message [ o ] = true ;
867
866
break ;
867
+ case 'ledger' :
868
+ request . selectLedger ( options . ledger ) ;
869
+ break ;
868
870
case 'ledger_index' :
869
871
case 'ledger_hash' :
870
872
request . message [ o ] = options [ o ] ;
@@ -1113,6 +1115,14 @@ Remote.prototype.requestTransactionEntry = function(hash, ledgerHash, callback)
1113
1115
// utils.assert(this.trusted);
1114
1116
var request = new Request ( this , 'transaction_entry' ) ;
1115
1117
1118
+ if ( typeof hash === 'object' ) {
1119
+ ledgerHash = hash . ledger || hash . ledger_hash || hash . ledger_index ;
1120
+ hash = hash . hash || hash . tx || hash . transaction ;
1121
+ } else {
1122
+ console . error ( 'DEPRECATED: First argument to request constructor should be'
1123
+ + ' an object containing request properties' ) ;
1124
+ }
1125
+
1116
1126
request . txHash ( hash ) ;
1117
1127
1118
1128
switch ( typeof ledgerHash ) {
@@ -1152,6 +1162,8 @@ Remote.prototype.requestTx = function(hash, callback) {
1152
1162
1153
1163
if ( typeof hash === 'string' ) {
1154
1164
options = { hash : hash } ;
1165
+ console . error ( 'DEPRECATED: First argument to request constructor should be'
1166
+ + ' an object containing request properties' ) ;
1155
1167
} else {
1156
1168
options = hash ;
1157
1169
}
@@ -1206,6 +1218,9 @@ Remote.accountRequest = function(type, options, callback) {
1206
1218
peer = options . peer ;
1207
1219
limit = options . limit ;
1208
1220
marker = options . marker ;
1221
+ } else {
1222
+ console . error ( 'DEPRECATED: First argument to request constructor should be'
1223
+ + ' an object containing request properties' ) ;
1209
1224
}
1210
1225
1211
1226
// if a marker is given, we need a ledger
@@ -1530,6 +1545,13 @@ Remote.prototype.requestTxHistory = function(start, callback) {
1530
1545
1531
1546
var request = new Request ( this , 'tx_history' ) ;
1532
1547
1548
+ if ( typeof start === 'object' ) {
1549
+ start = start . start ;
1550
+ } else {
1551
+ console . error ( 'DEPRECATED: First argument to request constructor should be'
1552
+ + ' an object containing request properties' ) ;
1553
+ }
1554
+
1533
1555
request . message . start = start ;
1534
1556
request . callback ( callback ) ;
1535
1557
@@ -1565,6 +1587,9 @@ Remote.prototype.requestBookOffers = function(gets, pays, taker, callback) {
1565
1587
gets = options . gets || options . taker_gets ;
1566
1588
ledger = options . ledger ;
1567
1589
limit = options . limit ;
1590
+ } else {
1591
+ console . error ( 'DEPRECATED: First argument to request constructor should be'
1592
+ + ' an object containing request properties' ) ;
1568
1593
}
1569
1594
1570
1595
if ( typeof lastArg === 'function' ) {
@@ -1625,6 +1650,14 @@ Remote.prototype.requestWalletAccounts = function(seed, callback) {
1625
1650
utils . assert ( this . trusted ) ; // Don't send secrets.
1626
1651
1627
1652
var request = new Request ( this , 'wallet_accounts' ) ;
1653
+
1654
+ if ( typeof seed === 'object' ) {
1655
+ seed = seed . seed ;
1656
+ } else {
1657
+ console . error ( 'DEPRECATED: First argument to request constructor should be'
1658
+ + ' an object containing request properties' ) ;
1659
+ }
1660
+
1628
1661
request . message . seed = seed ;
1629
1662
request . callback ( callback ) ;
1630
1663
@@ -1644,6 +1677,15 @@ Remote.prototype.requestSign = function(secret, tx_json, callback) {
1644
1677
utils . assert ( this . trusted ) ; // Don't send secrets.
1645
1678
1646
1679
var request = new Request ( this , 'sign' ) ;
1680
+
1681
+ if ( typeof secret === 'object' ) {
1682
+ tx_json = secret . tx_json ;
1683
+ secret = secret . secret ;
1684
+ } else {
1685
+ console . error ( 'DEPRECATED: First argument to request constructor should be'
1686
+ + ' an object containing request properties' ) ;
1687
+ }
1688
+
1647
1689
request . message . secret = secret ;
1648
1690
request . message . tx_json = tx_json ;
1649
1691
request . callback ( callback ) ;
@@ -1762,6 +1804,9 @@ Remote.accountRootRequest = function(type, responseFilter, account, ledger, call
1762
1804
callback = ledger ;
1763
1805
ledger = account . ledger ;
1764
1806
account = account . account ;
1807
+ } else {
1808
+ console . error ( 'DEPRECATED: First argument to request constructor should be'
1809
+ + ' an object containing request properties' ) ;
1765
1810
}
1766
1811
1767
1812
var lastArg = arguments [ arguments . length - 1 ] ;
@@ -1911,6 +1956,9 @@ Remote.prototype.createPathFind = function(src_account, dst_account, dst_amount,
1911
1956
dst_amount = options . dst_amount ;
1912
1957
dst_account = options . dst_account ;
1913
1958
src_account = options . src_account ;
1959
+ } else {
1960
+ console . error ( 'DEPRECATED: First argument to request constructor should be'
1961
+ + ' an object containing request properties' ) ;
1914
1962
}
1915
1963
1916
1964
var pathFind = new PathFind ( this ,
@@ -1949,6 +1997,9 @@ Remote.prototype.createOrderBook = function(currency_gets, issuer_gets, currency
1949
1997
currency_pays = options . currency_pays ;
1950
1998
issuer_gets = options . issuer_gets ;
1951
1999
currency_gets = options . currency_gets ;
2000
+ } else {
2001
+ console . error ( 'DEPRECATED: First argument to request constructor should be'
2002
+ + ' an object containing request properties' ) ;
1952
2003
}
1953
2004
1954
2005
var gets = Remote . prepareTrade ( currency_gets , issuer_gets ) ;
@@ -2029,6 +2080,9 @@ Remote.prototype.accountSeqCache = function(account, ledger, callback) {
2029
2080
callback = ledger ;
2030
2081
ledger = options . ledger ;
2031
2082
account = options . account ;
2083
+ } else {
2084
+ console . error ( 'DEPRECATED: First argument to request constructor should be'
2085
+ + ' an object containing request properties' ) ;
2032
2086
}
2033
2087
2034
2088
if ( ! this . accounts . hasOwnProperty ( account ) ) {
@@ -2135,6 +2189,9 @@ Remote.prototype.requestRippleBalance = function(account, issuer, currency, ledg
2135
2189
currency = options . currency ;
2136
2190
issuer = options . issuer ;
2137
2191
account = options . account ;
2192
+ } else {
2193
+ console . error ( 'DEPRECATED: First argument to request constructor should be'
2194
+ + ' an object containing request properties' ) ;
2138
2195
}
2139
2196
2140
2197
// YYY Could be cached per ledger.
@@ -2189,6 +2246,7 @@ Remote.prototype.requestRippleBalance = function(account, issuer, currency, ledg
2189
2246
return request ;
2190
2247
} ;
2191
2248
2249
+ Remote . prepareCurrency =
2192
2250
Remote . prepareCurrencies = function ( currency ) {
2193
2251
var newCurrency = { } ;
2194
2252
@@ -2220,6 +2278,9 @@ Remote.prototype.requestRipplePathFind = function(src_account, dst_account, dst_
2220
2278
dst_amount = options . dst_amount ;
2221
2279
dst_account = options . dst_account ;
2222
2280
src_account = options . src_account ;
2281
+ } else {
2282
+ console . error ( 'DEPRECATED: First argument to request constructor should be'
2283
+ + ' an object containing request properties' ) ;
2223
2284
}
2224
2285
2225
2286
var request = new Request ( this , 'ripple_path_find' ) ;
@@ -2254,6 +2315,9 @@ Remote.prototype.requestPathFindCreate = function(src_account, dst_account, dst_
2254
2315
dst_amount = options . dst_amount ;
2255
2316
dst_account = options . dst_account ;
2256
2317
src_account = options . src_account ;
2318
+ } else {
2319
+ console . error ( 'DEPRECATED: First argument to request constructor should be'
2320
+ + ' an object containing request properties' ) ;
2257
2321
}
2258
2322
2259
2323
var request = new Request ( this , 'path_find' ) ;
0 commit comments