Browse Source

More improvements to ElectrumX connection management

master
Dan Janosik 5 years ago
parent
commit
f419303162
No known key found for this signature in database GPG Key ID: C6F8CE9FFDB2CED2
  1. 24
      app/api/electrumAddressApi.js
  2. 6043
      npm-shrinkwrap.json
  3. 2
      package.json

24
app/api/electrumAddressApi.js

@ -12,7 +12,7 @@ var coinConfig = coins[config.coin];
global.net = require('net');
global.tls = require('tls');
const ElectrumClient = require('rn-electrum-client');
const ElectrumClient = require('electrum-client');
var electrumClients = [];
@ -49,11 +49,7 @@ function connectToServer(host, port, protocol) {
var electrumConfig = { client:"btc-rpc-explorer-v2", version:"1.4" };
var electrumClient = new ElectrumClient(port, host, protocol || defaultProtocol);
electrumClient.persistencePolicy = { retryPeriod: 5000, maxRetry: 1000, callback: null };
electrumClient.electrumConfig = electrumConfig;
electrumClient.afterConnect = function(client) {
var electrumAfterConnect = function(client) {
client.server_version(electrumConfig.client, electrumConfig.version).then(function(versionResult) {
debugLog(`Connected to ElectrumX @ ${host}:${port} (${JSON.stringify(versionResult)})`);
@ -70,7 +66,7 @@ function connectToServer(host, port, protocol) {
});
};
electrumClient.afterClose = function(client) {
var electrumAfterClose = function(client) {
debugLog(`Lost connection to ElectrumX @ ${host}:${port}`);
var index = electrumClients.indexOf(client);
@ -80,6 +76,20 @@ function connectToServer(host, port, protocol) {
}
};
var electrumOnLog = function(str) {
debugLog(str);
};
var electrumCallbacks = {
afterConnect: electrumAfterConnect,
afterClose: electrumAfterClose,
onLog: electrumOnLog
};
var electrumClient = new ElectrumClient(port, host, protocol || defaultProtocol, null, electrumCallbacks);
electrumClient.persistencePolicy = { retryPeriod: 10000, maxRetry: 1000, callback: null };
electrumClient.electrumConfig = electrumConfig;
// connect().then() is excluded here because "afterConnect" above handles that flow
electrumClient.connect().catch(function(err) {
debugLog(`Error connecting to ElectrumX @ ${host}:${port}`);

6043
npm-shrinkwrap.json

File diff suppressed because it is too large

2
package.json

@ -32,6 +32,7 @@
"debug": "~4.1.1",
"decimal.js": "^10.2.0",
"dotenv": "^8.2.0",
"electrum-client": "github:janoside/electrum-client",
"express": "^4.17.1",
"express-session": "^1.17.1",
"jstransformer-markdown-it": "^2.1.0",
@ -46,7 +47,6 @@
"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"

Loading…
Cancel
Save