aboutsummaryrefslogtreecommitdiffstats
path: root/tools/zmq-watcher.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-06-25 15:47:50 -0700
committerAdam Soltys <[email protected]>2026-06-25 15:47:50 -0700
commitc1581a783b02af40567666e03b4f28e404e8ec34 (patch)
tree6e7261a58cd996bf533847b0eeb20f48a15e87ed /tools/zmq-watcher.js
parent44dc3197ae74e63505245c53a146a11cbccc6e55 (diff)
downloadcoinosv3-c1581a783b02af40567666e03b4f28e404e8ec34.tar.gz
coinosv3-c1581a783b02af40567666e03b4f28e404e8ec34.zip
Confirm transactions via the WebSocket push, not REST
The watcher's block (rawblock) push now carries confirmed=true + the block time, and _applyTxNotification flips the matching history row and coins from pending to confirmed directly — for incoming and outgoing txs (flag-only, so no overcount). Confirmations no longer wait on a mempool.space reconcile; the 30s backstop poll just fills in block height / fee afterward. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Diffstat (limited to 'tools/zmq-watcher.js')
-rw-r--r--tools/zmq-watcher.js10
1 files changed, 6 insertions, 4 deletions
diff --git a/tools/zmq-watcher.js b/tools/zmq-watcher.js
index 80d8f88..43a81cf 100644
--- a/tools/zmq-watcher.js
+++ b/tools/zmq-watcher.js
@@ -126,7 +126,7 @@ const TX_OPTS = { allowUnknownOutputs: true, allowUnknownInputs: true, disableSc
// confirmed flag, so the client can credit the payment WITHOUT a REST round-trip
// — keeping the rate-limited explorer off the critical path. `confirmed` is true
// when the tx came from a block (rawblock), false from the mempool (rawtx).
-const notifyForTx = (raw, confirmed) => {
+const notifyForTx = (raw, confirmed, blockTime) => {
let tx;
try { tx = Transaction.fromRaw(raw, TX_OPTS); } catch { return; }
const txid = tx.id;
@@ -147,7 +147,7 @@ const notifyForTx = (raw, confirmed) => {
jsonrpc: '2.0',
method: 'blockchain.scripthash.subscribe',
params: [sh, txid],
- data: { txid, confirmed: !!confirmed, outputs },
+ data: { txid, confirmed: !!confirmed, blockTime: blockTime || 0, outputs },
}) + '\n';
let sent = 0;
for (const ws of set) { try { ws.send(note); sent++; } catch {} }
@@ -184,7 +184,9 @@ const rawTxSize = (buf, start) => {
return o - start;
};
const handleRawBlock = (raw) => {
- // A new block confirms watched txs: walk its txs and notify matching scripthashes.
+ // A new block confirms watched txs: walk its txs and notify matching
+ // scripthashes with confirmed=true + the block time (header bytes 68..71, LE).
+ const blockTime = new DataView(raw.buffer, raw.byteOffset, raw.byteLength).getUint32(68, true);
let offset = 80; // skip header
const txCount = readVarInt(raw, offset);
offset += txCount.size;
@@ -192,7 +194,7 @@ const handleRawBlock = (raw) => {
const size = rawTxSize(raw, offset);
const txRaw = raw.subarray(offset, offset + size);
offset += size;
- try { notifyForTx(txRaw, true); } catch {}
+ try { notifyForTx(txRaw, true, blockTime); } catch {}
}
};