Skip to content
This repository has been archived by the owner on Nov 25, 2023. It is now read-only.

Commit

Permalink
improve Electrum connection management
Browse files Browse the repository at this point in the history
  • Loading branch information
p0o committed May 13, 2021
1 parent 5510f92 commit 46a2cdb
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/wallet/src/utils/blockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ClusterOrder,
RequestResponse,
} from "electrum-cash";
import { toast } from "react-toastify";
import { electrumCashClusters } from "../config";
import { addressToElectrumScriptHash } from "./crypto";
import { getSlpUtxos, getSlpBalances, getSlpBatonUtxos } from "./slp";
Expand All @@ -21,17 +22,28 @@ const electrum = new ElectrumCluster(
);

// Connect to all the clusters defined in config
electrumCashClusters.forEach((c) => {
electrumCashClusters.forEach(async (c) => {
try {
electrum.addServer(c.host, c.port, ElectrumTransport.WSS.Scheme, true);
await electrum.addServer(
c.host,
c.port,
ElectrumTransport.WSS.Scheme,
true
);
} catch (e) {
console.log("Error connecting Electrum server ", e);
}
});

export async function getUtxos(bchAddr) {
await electrum.startup();
await electrum.ready();
const connectedServer = Object.keys(electrum.clients).filter(
(c) => electrum.clients[c].state == 1
)[0];

toast.success(`Connected to Electrum Server ${connectedServer} 🔒`, {
hideProgressBar: true,
});

const scripthash = addressToElectrumScriptHash(bchAddr);

Expand Down

0 comments on commit 46a2cdb

Please sign in to comment.