Skip to content

Commit

Permalink
Working on #188
Browse files Browse the repository at this point in the history
Switching to BlueWallet-based ElectrumX connector which is a maintained fork of old ElectrumX connection code. Seems that some extra effort has been put into reconnecting and this also drops some manual error handling that my old code incorporated.
  • Loading branch information
janoside committed Jun 25, 2020
1 parent 01bdb83 commit abd03a7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
15 changes: 7 additions & 8 deletions app/api/electrumAddressApi.js
Expand Up @@ -9,7 +9,10 @@ var hexEnc = require("crypto-js/enc-hex");

var coinConfig = coins[config.coin];

const ElectrumClient = require('electrum-client');
global.net = require('net');
global.tls = require('tls');

const ElectrumClient = require('rn-electrum-client');

var electrumClients = [];

Expand Down Expand Up @@ -41,7 +44,7 @@ function connectToServer(host, port, protocol) {
var defaultProtocol = port === 50001 ? 'tcp' : 'tls';

var electrumClient = new ElectrumClient(port, host, protocol || defaultProtocol);
electrumClient.initElectrum({client:"btc-rpc-explorer-v1.1", version:"1.4"}).then(function(res) {
electrumClient.initElectrum({client:"btc-rpc-explorer-v2", version:"1.4"}).then(function(res) {
debugLog("Connected to ElectrumX Server: " + host + ":" + port + ", versions: " + JSON.stringify(res));

electrumClients.push(electrumClient);
Expand All @@ -60,12 +63,8 @@ function connectToServer(host, port, protocol) {
function runOnServer(electrumClient, f) {
return new Promise(function(resolve, reject) {
f(electrumClient).then(function(result) {
if (result.success) {
resolve({result:result.response, server:electrumClient.host});

} else {
reject({error:result.error, server:electrumClient.host});
}
resolve({result:result, server:electrumClient.host});

}).catch(function(err) {
utils.logError("dif0e21qdh", err, {host:electrumClient.host, port:electrumClient.port});

Expand Down
11 changes: 7 additions & 4 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -32,7 +32,6 @@
"debug": "~4.1.1",
"decimal.js": "^10.2.0",
"dotenv": "^8.2.0",
"electrum-client": "github:chaintools/node-electrum-client#43a999036f9c5",
"express": "^4.17.1",
"express-session": "^1.17.1",
"jstransformer-markdown-it": "^2.1.0",
Expand All @@ -47,6 +46,7 @@
"qrcode": "^1.4.4",
"redis": "^2.8.0",
"request": "^2.88.2",
"rn-electrum-client": "github:janoside/rn-electrum-client",
"semver": "^7.3.2",
"serve-favicon": "^2.5.0",
"simple-git": "^1.132.0"
Expand Down
9 changes: 7 additions & 2 deletions views/address.pug
Expand Up @@ -294,8 +294,8 @@ block content

else if (addressDetailsErrors && addressDetailsErrors.length > 0)
each err in addressDetailsErrors
if (err.e && err.e.error && err.e.error.message == "history too large")
span Failed to retrieve transaction history from ElectrumX. See
if (err.e && err.e && err.e.message == "history too large")
span Failed to retrieve transaction history from ElectrumX because this address is involved in too many transactions (more than ElectrumX currently supports retrieving). See
a(href="https://github.com/janoside/btc-rpc-explorer/issues/67") Issue #67
span for more information.

Expand All @@ -304,6 +304,11 @@ block content
a(href="https://github.com/janoside/btc-rpc-explorer/blob/master/.env-sample") the example configuration file
span for help setting up an address API if desired.

else
span.text-danger Error retrieving transaction history
pre
code.json #{JSON.stringify(err, null, 4)}

else if (transactions.length == 0)
span No transactions found

Expand Down

0 comments on commit abd03a7

Please sign in to comment.