Skip to content

Commit

Permalink
Merge branch 'master' of github.com:janoside/btc-rpc-explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
janoside committed Nov 16, 2018
2 parents 5ef702b + bc04463 commit dd9e40e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions app/api/electrumApi.js
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion app/config.js
Expand Up @@ -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: {
Expand Down

0 comments on commit dd9e40e

Please sign in to comment.