mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
a few formatting changes
This commit is contained in:
63
js/remote.js
63
js/remote.js
@@ -34,7 +34,6 @@ var Remote = function (trusted, websocket_ip, websocket_port, trace) {
|
|||||||
|
|
||||||
var remoteConfig = function (config, server, trace) {
|
var remoteConfig = function (config, server, trace) {
|
||||||
var serverConfig = config.servers[server];
|
var serverConfig = config.servers[server];
|
||||||
|
|
||||||
return new Remote(serverConfig.trusted, serverConfig.websocket_ip, serverConfig.websocket_port, trace);
|
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);
|
if (this.trace) console.log("remote: connect: %s", this.url);
|
||||||
|
|
||||||
this.ws = new WebSocket(this.url);
|
var ws = this.ws = new WebSocket(this.url);;
|
||||||
|
|
||||||
var ws = this.ws;
|
|
||||||
|
|
||||||
ws.response = {};
|
ws.response = {};
|
||||||
|
|
||||||
@@ -93,11 +90,8 @@ Remote.method('connect_helper', function () {
|
|||||||
|
|
||||||
// Covers failure to open.
|
// Covers failure to open.
|
||||||
ws.onclose = function () {
|
ws.onclose = function () {
|
||||||
if (this.trace)
|
if (this.trace) console.log("remote: onclose: %s", ws.readyState);
|
||||||
console.log("remote: onclose: %s", ws.readyState);
|
|
||||||
|
|
||||||
ws.onerror = undefined;
|
ws.onerror = undefined;
|
||||||
|
|
||||||
self.done(ws.readyState);
|
self.done(ws.readyState);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -108,13 +102,10 @@ Remote.method('connect_helper', function () {
|
|||||||
|
|
||||||
if (message.type !== 'response') {
|
if (message.type !== 'response') {
|
||||||
console.log("unexpected message: %s", json);
|
console.log("unexpected message: %s", json);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
var done = ws.response[message.id];
|
var done = ws.response[message.id];
|
||||||
|
|
||||||
if (done) {
|
if (done) {
|
||||||
done(message);
|
done(message);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log("unexpected message id: %s", json);
|
console.log("unexpected message id: %s", json);
|
||||||
}
|
}
|
||||||
@@ -132,27 +123,20 @@ Remote.method('connect', function (done, timeout) {
|
|||||||
this.done = done;
|
this.done = done;
|
||||||
|
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
if (this.trace)
|
if (this.trace) console.log("remote: expire: false");
|
||||||
console.log("remote: expire: false");
|
|
||||||
|
|
||||||
this.expire = false;
|
this.expire = false;
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
if (this.trace)
|
if (this.trace) console.log("remote: expire: timeout");
|
||||||
console.log("remote: expire: timeout");
|
|
||||||
|
|
||||||
self.expire = true;
|
self.expire = true;
|
||||||
}, timeout);
|
}, timeout);
|
||||||
}
|
} else {
|
||||||
else {
|
if (this.trace) console.log("remote: expire: false");
|
||||||
if (this.trace)
|
|
||||||
console.log("remote: expire: false");
|
|
||||||
|
|
||||||
this.expire = true;
|
this.expire = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.connect_helper();
|
this.connect_helper();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Target stated is disconnected.
|
// Target stated is disconnected.
|
||||||
@@ -160,9 +144,7 @@ Remote.method('disconnect', function (done) {
|
|||||||
var ws = this.ws;
|
var ws = this.ws;
|
||||||
|
|
||||||
ws.onclose = function () {
|
ws.onclose = function () {
|
||||||
if (this.trace)
|
if (this.trace) console.log("remote: onclose: %s", ws.readyState);
|
||||||
console.log("remote: onclose: %s", ws.readyState);
|
|
||||||
|
|
||||||
done(ws.readyState);
|
done(ws.readyState);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -179,8 +161,7 @@ Remote.method('request', function (request, onDone, onFailure) {
|
|||||||
request.id = this.id;
|
request.id = this.id;
|
||||||
|
|
||||||
ws.response[request.id] = function (response) {
|
ws.response[request.id] = function (response) {
|
||||||
if (this.trace)
|
if (this.trace) console.log("remote: response: %s", JSON.stringify(response));
|
||||||
console.log("remote: response: %s", JSON.stringify(response));
|
|
||||||
|
|
||||||
if (onFailure && response.error)
|
if (onFailure && response.error)
|
||||||
{
|
{
|
||||||
@@ -192,15 +173,13 @@ Remote.method('request', function (request, onDone, onFailure) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.trace)
|
if (this.trace) console.log("remote: request: %s", JSON.stringify(request));
|
||||||
console.log("remote: request: %s", JSON.stringify(request));
|
|
||||||
|
|
||||||
ws.send(JSON.stringify(request));
|
ws.send(JSON.stringify(request));
|
||||||
});
|
});
|
||||||
|
|
||||||
Remote.method('request_ledger_closed', function (onDone, onFailure) {
|
Remote.method('request_ledger_closed', function (onDone, onFailure) {
|
||||||
assert(this.trusted); // If not trusted, need to check proof.
|
assert(this.trusted); // If not trusted, need to check proof.
|
||||||
|
|
||||||
this.request({ 'command' : 'ledger_closed' }, onDone, onFailure);
|
this.request({ 'command' : 'ledger_closed' }, onDone, onFailure);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -222,7 +201,6 @@ Remote.method('request_ledger_entry', function (req, onDone, onFailure) {
|
|||||||
if (req.ledger_closed)
|
if (req.ledger_closed)
|
||||||
{
|
{
|
||||||
// XXX Initial implementation no caching.
|
// XXX Initial implementation no caching.
|
||||||
|
|
||||||
this.request(req, onDone, onFailure);
|
this.request(req, onDone, onFailure);
|
||||||
}
|
}
|
||||||
else if (req.ledger_index)
|
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.
|
// Subscribe to a server to get the current and closed ledger.
|
||||||
// XXX Set up routine to update on notification.
|
// XXX Set up routine to update on notification.
|
||||||
Remote.method('server_subscribe', function (onDone, onFailure) {
|
Remote.method('server_subscribe', function (onDone, onFailure) {
|
||||||
this.request({
|
this.request(
|
||||||
'command' : 'server_subscribe'
|
{ 'command' : 'server_subscribe' },
|
||||||
}, function (r) {
|
function (r) {
|
||||||
this.ledger_current_index = r.ledger_current_index;
|
this.ledger_current_index = r.ledger_current_index;
|
||||||
this.ledger_closed = r.ledger_closed;
|
this.ledger_closed = r.ledger_closed;
|
||||||
this.stand_alone = r.stand_alone;
|
this.stand_alone = r.stand_alone;
|
||||||
|
|
||||||
onDone();
|
onDone();
|
||||||
}, onFailure);
|
},
|
||||||
|
onFailure
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Refresh accounts[account].seq
|
// Refresh accounts[account].seq
|
||||||
@@ -322,16 +301,18 @@ Remote.method('account_seq', function (account, onDone, onFailure) {
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Need to get the ledger entry.
|
// Need to get the ledger entry.
|
||||||
this.request_ledger_entry({
|
this.request_ledger_entry(
|
||||||
|
{
|
||||||
'ledger' : this.ledger_closed,
|
'ledger' : this.ledger_closed,
|
||||||
'account_root' : account
|
'account_root' : account
|
||||||
}, function (r) {
|
},
|
||||||
|
function (r) {
|
||||||
// Extract the seqence number from the account root entry.
|
// Extract the seqence number from the account root entry.
|
||||||
this.accounts[account].seq = r.seq;
|
this.accounts[account].seq = r.seq;
|
||||||
|
|
||||||
onDone(r.seq);
|
onDone(r.seq);
|
||||||
|
},
|
||||||
}, onFailure);
|
onFailure
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user