Permalink
Browse files

tweaking electrum connection logic to try to deal with disconnect errors

  • Loading branch information...
janoside committed Sep 24, 2018
1 parent 30ba103 commit 8588c56b612d37aecd1fbaf77b2fa2f9c05b40d2
Showing with 27 additions and 7 deletions.
  1. +1 −1 app.js
  2. +23 −3 app/api/electrumApi.js
  3. +2 −2 package-lock.json
  4. +1 −1 package.json
View
2 app.js
@@ -131,7 +131,7 @@ app.runOnStartup = function() {
if (config.electrumXServers && config.electrumXServers.length > 0) {
electrumApi.connectToServers().then(function() {
console.log("Live with ElectrumX API");
console.log("Live with ElectrumX API.");
global.electrumApi = electrumApi;
View
@@ -27,6 +27,27 @@ function connectToServers() {
});
}
function reconnectToServers() {
return new Promise(function(resolve, reject) {
for (var i = 0; i < electrumClients.length; i++) {
electrumClients[i].close();
}
electrumClients = [];
console.log("Reconnecting ElectrumX sockets...");
connectToServers().catch(function(err) {
console.log("Error 317fh29y7fg3333: " + err);
}).finally(function() {
console.log("Done reconnecting ElectrumX sockets.");
resolve();
});
});
}
function connectToServer(host, port) {
return new Promise(function(resolve, reject) {
console.log("Connecting to ElectrumX Server: " + host + ":" + port);
@@ -54,11 +75,9 @@ function runOnServer(electrumClient, f) {
resolve({result:result, server:electrumClient.host});
}).catch(function(err) {
console.log("Error dif0e21qdh: " + JSON.stringify(err) + ", host=" + electrumClient.host + ", port=" + electrumClient.port);
console.log("Error dif0e21qdh: " + err + ", host=" + electrumClient.host + ", port=" + electrumClient.port);
reject(err);
electrumClient.reconnect();
});
});
}
@@ -148,6 +167,7 @@ function getAddressBalance(addrScripthash) {
module.exports = {
connectToServers: connectToServers,
reconnectToServers: reconnectToServers,
getAddressTxids: getAddressTxids,
getAddressBalance: getAddressBalance
};
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -27,7 +27,7 @@
"crypto-js": "3.1.9-1",
"debug": "~2.6.0",
"decimal.js": "7.2.3",
"electrum-client": "Monaize/node-electrum-client#7eaa018b63a9",
"electrum-client": "chaintools/node-electrum-client#90e533753",
"express": "~4.16.3",
"express-session": "1.15.6",
"jstransformer-markdown-it": "^2.0.0",

0 comments on commit 8588c56

Please sign in to comment.