aboutsummaryrefslogtreecommitdiffstats
path: root/src/api.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-06-27 08:49:09 -0700
committerAdam Soltys <[email protected]>2026-06-27 08:49:09 -0700
commit1d0c1c9bfb9ccfb8a28e0cf147af12c37655cdcc (patch)
tree443c23a9320f4e1d494e51e2a13e6f3acaf4f426 /src/api.js
parenta9a903e7a1f80ed4a6f4163419b25d4e6de5db01 (diff)
downloadcoinosv3-1d0c1c9bfb9ccfb8a28e0cf147af12c37655cdcc.tar.gz
coinosv3-1d0c1c9bfb9ccfb8a28e0cf147af12c37655cdcc.zip
Regtest realtime via a local Electrum-over-WebSocket bridge
On regtest there's no realtime push (coinos watcher is mainnet-only), so the UI only updated on the 5–10s poll — a funded tx took a while to appear and a just-mined block stayed "pending" until the next reconcile. electrs speaks the Electrum protocol the watcher already understands, but only over TCP; route it through a small WS<->TCP bridge (see coinos-server/electrum-ws) so the wallet subscribes scripthashes and reconciles instantly on each notification. Data still comes from esplora; this only adds the push channel. Configurable in Settings (default ws://localhost:50003); falls back to polling if unreachable. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Diffstat (limited to 'src/api.js')
-rw-r--r--src/api.js14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/api.js b/src/api.js
index d135218..98b7528 100644
--- a/src/api.js
+++ b/src/api.js
@@ -166,8 +166,20 @@ export function resolveElectrumUrl() {
return electrumCandidates()[0] || null;
}
+// Regtest realtime push: a local electrs reached over a WS<->TCP bridge (electrs
+// is TCP-only). Same Electrum protocol the watcher already speaks, so the wallet
+// subscribes scripthashes and reconciles via esplora on each notification.
+const REGTEST_ELECTRUM_KEY = 'btc-wallet-regtest-electrum';
+export function getRegtestElectrumWs() {
+ try { return (localStorage.getItem(REGTEST_ELECTRUM_KEY) || '').trim() || 'ws://localhost:50003'; }
+ catch { return 'ws://localhost:50003'; }
+}
+export function setRegtestElectrumWs(url) { try { localStorage.setItem(REGTEST_ELECTRUM_KEY, (url || '').trim()); } catch {} }
+
export function wsUrl(net) {
- if (net !== 'mainnet') return null; // coinos watcher is mainnet-only
+ // Regtest gets realtime via the local electrs WS bridge (data still via esplora).
+ if (net === 'regtest') return getRealtimeEnabled() ? getRegtestElectrumWs() : null;
+ if (net !== 'mainnet') return null; // testnet: poll-only
// Electrum backend selects/rotates candidates in the wallet; here we only
// resolve the coinos watcher (esplora 'coinos' mode) or null (esplora 'explorer').
if (getBackend() === 'electrum') return null;