Browse Source

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.
fix-133-memory-crash
Daniel McNally 6 years ago
parent
commit
542142a719
No known key found for this signature in database GPG Key ID: 2D510757156F5E75
  1. 9
      app/api/electrumApi.js
  2. 4
      app/config.js

9
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);

4
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: {

Loading…
Cancel
Save