feat: improve relay selection for zap requests with e+a tags

When both eventPointer and addressPointer are provided:
- Collect outbox relays from both semantic authors
- Include relay hints from both pointers
- Deduplicate and use combined relay set

Priority order:
1. Explicit params.relays (respects CLI -r flags)
2. Semantic author outbox relays + pointer relay hints
3. Sender read relays (fallback)
4. Aggregator relays (final fallback)
This commit is contained in:
Claude
2026-01-19 10:49:11 +00:00
parent 3777d1c3b9
commit 8b02a8dde3

View File

@@ -57,12 +57,50 @@ export async function createZapRequest(
}
// Get relays for zap receipt publication
// Priority: explicit params.relays > semantic author relays > sender read relays > aggregators
let relays = params.relays;
if (!relays || relays.length === 0) {
// Use sender's read relays (where they want to receive zap receipts)
const senderReadRelays =
(await relayListCache.getInboxRelays(account.pubkey)) || [];
relays = senderReadRelays.length > 0 ? senderReadRelays : AGGREGATOR_RELAYS;
const collectedRelays: string[] = [];
// Collect outbox relays from semantic authors (event author and/or addressable event pubkey)
const authorsToQuery: string[] = [];
if (params.eventPointer?.author) {
authorsToQuery.push(params.eventPointer.author);
}
if (params.addressPointer?.pubkey) {
authorsToQuery.push(params.addressPointer.pubkey);
}
// Deduplicate authors
const uniqueAuthors = [...new Set(authorsToQuery)];
// Fetch outbox relays for each author
for (const authorPubkey of uniqueAuthors) {
const authorOutboxes =
(await relayListCache.getOutboxRelays(authorPubkey)) || [];
collectedRelays.push(...authorOutboxes);
}
// Include relay hints from pointers
if (params.eventPointer?.relays) {
collectedRelays.push(...params.eventPointer.relays);
}
if (params.addressPointer?.relays) {
collectedRelays.push(...params.addressPointer.relays);
}
// Deduplicate collected relays
const uniqueRelays = [...new Set(collectedRelays)];
if (uniqueRelays.length > 0) {
relays = uniqueRelays;
} else {
// Fallback to sender's read relays (where they want to receive zap receipts)
const senderReadRelays =
(await relayListCache.getInboxRelays(account.pubkey)) || [];
relays =
senderReadRelays.length > 0 ? senderReadRelays : AGGREGATOR_RELAYS;
}
}
// Build tags