fix: replace subscribeMany with querySync for nostr-tools v2 compatibility

The server was using the nostr-tools v1 API (subscribeMany with onevent/oneose
callbacks) but the installed version is v2.23.5 which changed the internal
subscription handling. querySync() is the correct v2 API for one-shot queries
and handles EOSE cleanly without needing manual timeout management.

Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
This commit is contained in:
shakespeare.diy 2026-06-17 11:43:51 +07:00
parent 84aa009b33
commit 4c263e729a

View file

@ -45,23 +45,27 @@ const CVM_RELAY = process.env.CVM_RELAY || "wss://relay.contextvm.net";
const dataPool = new SimplePool(); const dataPool = new SimplePool();
async function queryNostr(filters: Filter[], timeoutMs = 6000): Promise<any[]> { async function queryNostr(filters: Filter[], timeoutMs = 8000): Promise<any[]> {
return new Promise((resolve) => { // nostr-tools v2: use querySync which handles eose cleanly
const events: any[] = []; // Run each filter separately and merge results (querySync takes a single filter)
const sub = dataPool.subscribeMany(NOSTR_RELAYS, filters, { const allEvents: any[] = [];
onevent(e: any) { await Promise.all(
events.push(e); filters.map(async (filter) => {
}, try {
oneose() { const abort = new AbortController();
sub.close(); const timer = setTimeout(() => abort.abort(), timeoutMs);
resolve(events); const events = await dataPool.querySync(NOSTR_RELAYS, filter, {
}, maxWait: timeoutMs,
}); abort: abort.signal,
setTimeout(() => {
sub.close();
resolve(events);
}, timeoutMs);
}); });
clearTimeout(timer);
allEvents.push(...events);
} catch {
// ignore per-filter errors
}
})
);
return allEvents;
} }
// ─── Helpers ───────────────────────────────────────────────────────────────── // ─── Helpers ─────────────────────────────────────────────────────────────────