From 6a0ed46413de1835f8f9d48ed351a5b7c3cea3ce Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Fri, 20 Nov 2020 20:52:22 -0800 Subject: [PATCH] fix(electrumx): Automatically reconnecting when Electrumx disconnects --- src/routes/v3/electrumx.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/routes/v3/electrumx.js b/src/routes/v3/electrumx.js index 43f2bb7..59a5687 100644 --- a/src/routes/v3/electrumx.js +++ b/src/routes/v3/electrumx.js @@ -79,6 +79,21 @@ class Electrum { // Set the connection flag. _this.isReady = true + // Periodically check the connection. If it's not connected, attempt to + // reconnect. + setInterval(async function () { + const status = _this.electrumx.connection.status + // console.log(`Electrumx status: ${status}`) + + // 1 = connected. If we're not connected, attemp to reconnect. + if (status !== 1) { + wlogger.info(`Electrumx not connectes. Status: ${status}`) + wlogger.info(`Attempting to reconnect...`) + await _this.electrumx.connect() + wlogger.info(`...reconnected.`) + } + }, 30000) + console.log('...Successfully connected to ElectrumX server.') // console.log(`_this.isReady: ${_this.isReady}`)