From 74b13e9d6f26638507becd1a5da80aed98db5ceb Mon Sep 17 00:00:00 2001 From: binarybaron <86064887+binarybaron@users.noreply.github.com> Date: Thu, 26 Sep 2024 19:09:49 +0600 Subject: [PATCH] feat: Allow user to override electrum rpc and modify default one (#222) * feat: Allow user to override electrum rpc and modify default one * bump: release version to 0.6.4 --- release/app/package-lock.json | 4 ++-- release/app/package.json | 2 +- src/main/cli/cli.ts | 3 ++- src/store/config.ts | 17 +++++++++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/release/app/package-lock.json b/release/app/package-lock.json index e2b6bbc..aee0e8e 100644 --- a/release/app/package-lock.json +++ b/release/app/package-lock.json @@ -1,12 +1,12 @@ { "name": "unstoppableswap-gui", - "version": "0.6.3", + "version": "0.6.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "unstoppableswap-gui", - "version": "0.6.3", + "version": "0.6.4", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/release/app/package.json b/release/app/package.json index a4fa8fb..cc339bb 100644 --- a/release/app/package.json +++ b/release/app/package.json @@ -1,6 +1,6 @@ { "name": "unstoppableswap-gui", - "version": "0.6.3", + "version": "0.6.4", "description": "Graphical User Interface for XMR<>BTC Atomic Swaps", "main": "./dist/main/main.js", "scripts": { diff --git a/src/main/cli/cli.ts b/src/main/cli/cli.ts index 0d4893e..8111f0d 100644 --- a/src/main/cli/cli.ts +++ b/src/main/cli/cli.ts @@ -6,7 +6,7 @@ import { import PQueue from 'p-queue'; import pidtree from 'pidtree'; import util from 'util'; -import { getPlatform, isTestnet } from 'store/config'; +import { getElectrumRpcUrl, getPlatform, isTestnet } from 'store/config'; import { CliLog, isCliLog } from 'models/cliModel'; import { getLogsAndStringsFromRawFileString } from 'utils/parseUtils'; import { store } from 'main/store/mainStore'; @@ -284,6 +284,7 @@ export async function startRPC() { 'start-daemon', { 'server-address': `${RPC_BIND_HOST}:${RPC_BIND_PORT}`, + 'electrum-rpc': getElectrumRpcUrl(), }, async (logs) => { RPC_LOG_EVENT_EMITTER.emit(logs.filter(isCliLog)); diff --git a/src/store/config.ts b/src/store/config.ts index 1cf150e..30f05fd 100644 --- a/src/store/config.ts +++ b/src/store/config.ts @@ -1,5 +1,8 @@ import { ExtendedProviderStatus } from 'models/apiModel'; +const DEFAULT_MAINNET_ELECTRUM_RPC_URL = 'tcp://blockstream.info:110'; +const DEFAULT_TESTNET_ELECTRUM_RPC_URL = 'ssl://testnet.foundation.xyz:50002'; + export const isTestnet = () => process.env.TESTNET?.toString().toLowerCase() === 'true'; @@ -49,3 +52,17 @@ export const getPlatform = () => { return 'linux'; } }; + +export function getElectrumRpcUrl(): string { + if (isTestnet()) { + // If running on testnet, return the testnet Electrum RPC URL from environment variable or use the default + return ( + process.env.OVERRIDE_TESTNET_ELECTRUM_RPC_URL ?? + DEFAULT_TESTNET_ELECTRUM_RPC_URL + ); + } + // If running on mainnet, return the mainnet Electrum RPC URL from environment variable or use the default + return ( + process.env.OVERRIDE_ELECTRUM_RPC_URL ?? DEFAULT_MAINNET_ELECTRUM_RPC_URL + ); +}