From 80e9e10a34f11cfc0d3c4a92ebd88edbfa7d1bb4 Mon Sep 17 00:00:00 2001 From: Kanishka Date: Wed, 8 Apr 2026 22:13:45 +0530 Subject: [PATCH] fix: set event_deduplication in seed script --- seeds/0000-events.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/seeds/0000-events.js b/seeds/0000-events.js index e38ab99c..4544dbed 100644 --- a/seeds/0000-events.js +++ b/seeds/0000-events.js @@ -1,6 +1,32 @@ /* eslint-disable @typescript-eslint/no-var-requires */ const NAMESPACE = 'c646b451-db73-47fb-9a70-ea24ce8a225a' + +function isReplaceableEvent(kind) { + return kind === 0 + || kind === 3 + || kind === 41 + || (kind >= 10000 && kind < 20000) +} + +function isParameterizedReplaceableEvent(kind) { + return kind >= 30000 && kind < 40000 +} + +function getEventDeduplication(event) { + if (isReplaceableEvent(event.kind)) { + return JSON.stringify([event.pubkey, event.kind]) + } + + if (isParameterizedReplaceableEvent(event.kind)) { + const dTag = event.tags.find((tag) => tag.length >= 2 && tag[0] === 'd') + const [, ...deduplication] = dTag ?? [null, ''] + return JSON.stringify(deduplication) + } + + return null +} + exports.seed = async function (knex) { await knex('events').del() @@ -16,6 +42,7 @@ exports.seed = async function (knex) { event_content: event.content, event_tags: JSON.stringify(event.tags), event_signature: Buffer.from(event.sig, 'hex'), + event_deduplication: getEventDeduplication(event), }) return result