a few formatting changes

This commit is contained in:
Andrey Fedorov
2012-10-04 21:17:40 -04:00
parent 0e3b4cc1a8
commit 0076130be1

View File

@@ -34,7 +34,6 @@ var Remote = function (trusted, websocket_ip, websocket_port, trace) {
var remoteConfig = function (config, server, trace) {
var serverConfig = config.servers[server];
return new Remote(serverConfig.trusted, serverConfig.websocket_ip, serverConfig.websocket_port, trace);
};
@@ -59,9 +58,7 @@ Remote.method('connect_helper', function () {
if (this.trace) console.log("remote: connect: %s", this.url);
this.ws = new WebSocket(this.url);
var ws = this.ws;
var ws = this.ws = new WebSocket(this.url);;
ws.response = {};
@@ -93,11 +90,8 @@ Remote.method('connect_helper', function () {
// Covers failure to open.
ws.onclose = function () {
if (this.trace)
console.log("remote: onclose: %s", ws.readyState);
if (this.trace) console.log("remote: onclose: %s", ws.readyState);
ws.onerror = undefined;
self.done(ws.readyState);
};
@@ -108,13 +102,10 @@ Remote.method('connect_helper', function () {
if (message.type !== 'response') {
console.log("unexpected message: %s", json);
} else {
var done = ws.response[message.id];
if (done) {
done(message);
} else {
console.log("unexpected message id: %s", json);
}
@@ -132,27 +123,20 @@ Remote.method('connect', function (done, timeout) {
this.done = done;
if (timeout) {
if (this.trace)
console.log("remote: expire: false");
if (this.trace) console.log("remote: expire: false");
this.expire = false;
setTimeout(function () {
if (this.trace)
console.log("remote: expire: timeout");
if (this.trace) console.log("remote: expire: timeout");
self.expire = true;
}, timeout);
}
else {
if (this.trace)
console.log("remote: expire: false");
} else {
if (this.trace) console.log("remote: expire: false");
this.expire = true;
}
this.connect_helper();
});
// Target stated is disconnected.
@@ -160,9 +144,7 @@ Remote.method('disconnect', function (done) {
var ws = this.ws;
ws.onclose = function () {
if (this.trace)
console.log("remote: onclose: %s", ws.readyState);
if (this.trace) console.log("remote: onclose: %s", ws.readyState);
done(ws.readyState);
};
@@ -179,8 +161,7 @@ Remote.method('request', function (request, onDone, onFailure) {
request.id = this.id;
ws.response[request.id] = function (response) {
if (this.trace)
console.log("remote: response: %s", JSON.stringify(response));
if (this.trace) console.log("remote: response: %s", JSON.stringify(response));
if (onFailure && response.error)
{
@@ -192,15 +173,13 @@ Remote.method('request', function (request, onDone, onFailure) {
}
};
if (this.trace)
console.log("remote: request: %s", JSON.stringify(request));
if (this.trace) console.log("remote: request: %s", JSON.stringify(request));
ws.send(JSON.stringify(request));
});
Remote.method('request_ledger_closed', function (onDone, onFailure) {
assert(this.trusted); // If not trusted, need to check proof.
this.request({ 'command' : 'ledger_closed' }, onDone, onFailure);
});
@@ -222,7 +201,6 @@ Remote.method('request_ledger_entry', function (req, onDone, onFailure) {
if (req.ledger_closed)
{
// XXX Initial implementation no caching.
this.request(req, onDone, onFailure);
}
else if (req.ledger_index)
@@ -299,15 +277,16 @@ Remote.method('submit', function (json, private_key, onDone, onFailure) {
// Subscribe to a server to get the current and closed ledger.
// XXX Set up routine to update on notification.
Remote.method('server_subscribe', function (onDone, onFailure) {
this.request({
'command' : 'server_subscribe'
}, function (r) {
this.request(
{ 'command' : 'server_subscribe' },
function (r) {
this.ledger_current_index = r.ledger_current_index;
this.ledger_closed = r.ledger_closed;
this.stand_alone = r.stand_alone;
onDone();
}, onFailure);
},
onFailure
);
});
// Refresh accounts[account].seq
@@ -322,16 +301,18 @@ Remote.method('account_seq', function (account, onDone, onFailure) {
else
{
// Need to get the ledger entry.
this.request_ledger_entry({
this.request_ledger_entry(
{
'ledger' : this.ledger_closed,
'account_root' : account
}, function (r) {
},
function (r) {
// Extract the seqence number from the account root entry.
this.accounts[account].seq = r.seq;
onDone(r.seq);
}, onFailure);
},
onFailure
);
}
});