mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 12:45:50 +00:00
Cleanup
This commit is contained in:
@@ -103,6 +103,7 @@ Request.prototype.ledger_select = function (ledger_spec) {
|
|||||||
case 'verified':
|
case 'verified':
|
||||||
this.message.ledger_index = ledger_spec;
|
this.message.ledger_index = ledger_spec;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// XXX Better test needed
|
// XXX Better test needed
|
||||||
if (String(ledger_spec).length > 12) {
|
if (String(ledger_spec).length > 12) {
|
||||||
@@ -110,6 +111,7 @@ Request.prototype.ledger_select = function (ledger_spec) {
|
|||||||
} else {
|
} else {
|
||||||
this.message.ledger_index = ledger_spec;
|
this.message.ledger_index = ledger_spec;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@@ -185,15 +187,15 @@ Request.prototype.ripple_state = function (account, issuer, currency) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Request.prototype.accounts = function (accounts, realtime) {
|
Request.prototype.accounts = function (accounts, realtime) {
|
||||||
if (typeof accounts !== 'object') {
|
if (!Array.isArray(accounts)) {
|
||||||
accounts = [accounts];
|
accounts = [ accounts ];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process accounts parameters
|
// Process accounts parameters
|
||||||
var procAccounts = [];
|
var procAccounts = accounts.map(function(account) {
|
||||||
for (var i = 0, l = accounts.length; i < l; i++) {
|
return UInt160.json_rewrite(account);
|
||||||
procAccounts.push(UInt160.json_rewrite(accounts[i]));
|
});
|
||||||
}
|
|
||||||
if (realtime) {
|
if (realtime) {
|
||||||
this.message.rt_accounts = procAccounts;
|
this.message.rt_accounts = procAccounts;
|
||||||
} else {
|
} else {
|
||||||
@@ -281,13 +283,11 @@ var Remote = function (opts, trace) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.trusted = opts.trusted;
|
this.trusted = opts.trusted;
|
||||||
this.websocket_ip = opts.websocket_ip;
|
|
||||||
this.websocket_port = opts.websocket_port;
|
|
||||||
this.websocket_ssl = opts.websocket_ssl;
|
|
||||||
this.local_sequence = opts.local_sequence; // Locally track sequence numbers
|
this.local_sequence = opts.local_sequence; // Locally track sequence numbers
|
||||||
this.local_fee = opts.local_fee; // Locally set fees
|
this.local_fee = opts.local_fee; // Locally set fees
|
||||||
this.local_signing = ('undefined' === typeof opts.local_signing)
|
this.local_signing = ('undefined' === typeof opts.local_signing)
|
||||||
? true : opts.local_signing;
|
? true : opts.local_signing;
|
||||||
|
|
||||||
this.id = 0;
|
this.id = 0;
|
||||||
this.trace = opts.trace || trace;
|
this.trace = opts.trace || trace;
|
||||||
this._server_fatal = false; // True, if we know server exited.
|
this._server_fatal = false; // True, if we know server exited.
|
||||||
@@ -310,6 +310,8 @@ var Remote = function (opts, trace) {
|
|||||||
this._reserve_base = void(0);
|
this._reserve_base = void(0);
|
||||||
this._reserve_inc = void(0);
|
this._reserve_inc = void(0);
|
||||||
this._connection_count = 0;
|
this._connection_count = 0;
|
||||||
|
this._connected = false;
|
||||||
|
|
||||||
|
|
||||||
this._last_tx = null;
|
this._last_tx = null;
|
||||||
|
|
||||||
@@ -328,7 +330,6 @@ var Remote = function (opts, trace) {
|
|||||||
// Otherwise, clear it to have it automatically refreshed from the network.
|
// Otherwise, clear it to have it automatically refreshed from the network.
|
||||||
|
|
||||||
// account : { seq : __ }
|
// account : { seq : __ }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Hash map of Account objects by AccountId.
|
// Hash map of Account objects by AccountId.
|
||||||
@@ -352,12 +353,6 @@ var Remote = function (opts, trace) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// XXX Add support for multiple servers
|
|
||||||
var url = (this.websocket_ssl ? 'wss://' : 'ws://') +
|
|
||||||
this.websocket_ip + ':' + this.websocket_port;
|
|
||||||
|
|
||||||
var server = new Server (this, {url: url})
|
|
||||||
|
|
||||||
if (!('servers' in opts)) {
|
if (!('servers' in opts)) {
|
||||||
opts.servers = [
|
opts.servers = [
|
||||||
{
|
{
|
||||||
@@ -383,9 +378,8 @@ var Remote = function (opts, trace) {
|
|||||||
|
|
||||||
this.on('newListener', function (type, listener) {
|
this.on('newListener', function (type, listener) {
|
||||||
if ('transaction_all' === type) {
|
if ('transaction_all' === type) {
|
||||||
if (!self._transaction_subs && 'open' === self._online_state) {
|
if (!self._transaction_subs && self._connected) {
|
||||||
self.request_subscribe([ 'transactions' ])
|
self.request_subscribe('transactions').request();
|
||||||
.request();
|
|
||||||
}
|
}
|
||||||
self._transaction_subs += 1;
|
self._transaction_subs += 1;
|
||||||
}
|
}
|
||||||
@@ -394,10 +388,8 @@ var Remote = function (opts, trace) {
|
|||||||
this.on('removeListener', function (type, listener) {
|
this.on('removeListener', function (type, listener) {
|
||||||
if ('transaction_all' === type) {
|
if ('transaction_all' === type) {
|
||||||
self._transaction_subs -= 1;
|
self._transaction_subs -= 1;
|
||||||
|
if (!self._transaction_subs && self._connected) {
|
||||||
if (!self._transaction_subs && 'open' === self._online_state) {
|
self.request_unsubscribe('transactions').request();
|
||||||
self.request_unsubscribe([ 'transactions' ])
|
|
||||||
.request();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -491,12 +483,14 @@ Remote.prototype._set_state = function (state) {
|
|||||||
switch (state) {
|
switch (state) {
|
||||||
case 'online':
|
case 'online':
|
||||||
this._online_state = 'open';
|
this._online_state = 'open';
|
||||||
|
this._connected = true;
|
||||||
this.emit('connect');
|
this.emit('connect');
|
||||||
this.emit('connected');
|
this.emit('connected');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'offline':
|
case 'offline':
|
||||||
this._online_state = 'closed';
|
this._online_state = 'closed';
|
||||||
|
this._connected = false;
|
||||||
this.emit('disconnect');
|
this.emit('disconnect');
|
||||||
this.emit('disconnected');
|
this.emit('disconnected');
|
||||||
break;
|
break;
|
||||||
@@ -1037,12 +1031,9 @@ Remote.prototype._server_prepare_subscribe = function ()
|
|||||||
// A good way to be notified of the result of this is:
|
// A good way to be notified of the result of this is:
|
||||||
// remote.once('ledger_closed', function (ledger_closed, ledger_index) { ... } );
|
// remote.once('ledger_closed', function (ledger_closed, ledger_index) { ... } );
|
||||||
Remote.prototype.ledger_accept = function () {
|
Remote.prototype.ledger_accept = function () {
|
||||||
if (this._stand_alone || undefined === this._stand_alone)
|
if (this._stand_alone || undefined === this._stand_alone) {
|
||||||
{
|
|
||||||
var request = new Request(this, 'ledger_accept');
|
var request = new Request(this, 'ledger_accept');
|
||||||
|
request .request();
|
||||||
request
|
|
||||||
.request();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.emit('error', {
|
this.emit('error', {
|
||||||
@@ -1135,16 +1126,14 @@ Remote.prototype.account_seq = function (account, advance) {
|
|||||||
var account_info = this.accounts[account];
|
var account_info = this.accounts[account];
|
||||||
var seq;
|
var seq;
|
||||||
|
|
||||||
if (account_info && account_info.seq)
|
if (account_info && account_info.seq) {
|
||||||
{
|
|
||||||
seq = account_info.seq;
|
seq = account_info.seq;
|
||||||
|
|
||||||
if (advance === 'ADVANCE') account_info.seq += 1;
|
if (advance === 'ADVANCE') account_info.seq += 1;
|
||||||
if (advance === 'REWIND') account_info.seq -= 1;
|
if (advance === 'REWIND') account_info.seq -= 1;
|
||||||
|
|
||||||
// console.log('cached: %s current=%d next=%d', account, seq, account_info.seq);
|
// console.log('cached: %s current=%d next=%d', account, seq, account_info.seq);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// console.log('uncached: %s', account);
|
// console.log('uncached: %s', account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user