From 542142a719d608a58a3a70b02f25cf778ab22b5f Mon Sep 17 00:00:00 2001 From: Daniel McNally Date: Thu, 15 Nov 2018 00:10:06 -0500 Subject: [PATCH] configurable electrumx server protocol This makes the protocol (either `tcp` or `tls`) for the electrum server configurable, to allow communicating with an electrum server without tls encryption. --- app/api/electrumApi.js | 9 ++++++--- app/config.js | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/api/electrumApi.js b/app/api/electrumApi.js index 61d667a17..a9576f056 100644 --- a/app/api/electrumApi.js +++ b/app/api/electrumApi.js @@ -13,7 +13,8 @@ function connectToServers() { var promises = []; for (var i = 0; i < config.electrumXServers.length; i++) { - promises.push(connectToServer(config.electrumXServers[i].host, config.electrumXServers[i].port)); + var { host, port, protocol } = config.electrumXServers[i]; + promises.push(connectToServer(host, port, protocol)); } Promise.all(promises).then(function() { @@ -48,11 +49,13 @@ function reconnectToServers() { }); } -function connectToServer(host, port) { +function connectToServer(host, port, protocol) { return new Promise(function(resolve, reject) { console.log("Connecting to ElectrumX Server: " + host + ":" + port); - var electrumClient = new ElectrumClient(port, host, 'tls'); + // default protocol is 'tcp' if port is 50001, which is the default unencrypted port for electrumx + var defaultProtocol = port === 50001 ? 'tcp' : 'tls'; + var electrumClient = new ElectrumClient(port, host, protocol || defaultProtocol); electrumClient.initElectrum({client:"btc-rpc-explorer-v1.1", version:"1.2"}).then(function(res) { console.log("Connected to ElectrumX Server: " + host + ":" + port + ", versions: " + res); diff --git a/app/config.js b/app/config.js index 0a03beefc..6ca46b007 100644 --- a/app/config.js +++ b/app/config.js @@ -74,7 +74,9 @@ module.exports = { // https://uasf.saltylemon.org/electrum electrumXServers:[ - // {host: "electrum.example.com", port:50002}, ... + // set host & port of electrum servers to connect to + // protocol can be "tls" or "tcp", it defaults to "tcp" if port is 50001 and "tls" otherwise + // {host: "electrum.example.com", port:50002, protocol: "tls"}, ... ], site: {