aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-06-15 13:01:41 -0700
committerAdam Soltys <[email protected]>2026-06-15 13:01:41 -0700
commit35df18174ab61c6d4a72bf8f1157584adb14bc4f (patch)
tree78b7763da96e29f590071707b51790b6e9aabf98 /lib
parent525556b45d042de6bf565a9bc153290243ac6404 (diff)
downloadcoinos-server-35df18174ab61c6d4a72bf8f1157584adb14bc4f.tar.gz
coinos-server-35df18174ab61c6d4a72bf8f1157584adb14bc4f.zip
Push broadcast txs directly to public explorers
After broadcasting an on-chain send via bitcoind, also POST the raw tx to mempool.space and blockstream (fire-and-forget, non-blocking) so those explorers see it immediately instead of waiting ~8s for p2p propagation. Skipped on regtest/testnet. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Diffstat (limited to 'lib')
-rw-r--r--lib/payments.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/payments.ts b/lib/payments.ts
index 30403b6c..489b78d3 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -49,6 +49,21 @@ import { PaymentType } from "$lib/types";
const bc = rpc(config.bitcoin);
const lq = rpc(config.liquid);
+// Fire-and-forget: push a freshly-broadcast tx straight to public explorers so
+// they see it immediately instead of waiting for it to propagate to their node
+// over the p2p network (measured ~8s otherwise). Never throws; never blocks.
+const broadcastToExplorers = (hex: string) => {
+ const net = config.bitcoin?.network;
+ if (net === "regtest" || net === "testnet") return; // public explorers are mainnet
+ for (const base of ["https://mempool.space/api", "https://blockstream.info/api"]) {
+ fetch(`${base}/tx`, {
+ method: "POST",
+ body: hex,
+ headers: { "Content-Type": "text/plain" },
+ }).catch(() => {});
+ }
+};
+
// Throttled warn — emit at most once per WARN_THROTTLE_MS per (key, message) pair
// so a downed external service (lq, bc, etc.) doesn't flood the log every loop tick.
const WARN_THROTTLE_MS = 5 * 60 * 1000;
@@ -591,6 +606,7 @@ export const sendOnchain = async (params) => {
await s(`payment:${p.id}`, p);
await node.sendRawTransaction(hex);
+ broadcastToExplorers(hex);
delete inflight[txid];
return p;