Skip to content

Commit

Permalink
added support for zapping replaceable events
Browse files Browse the repository at this point in the history
  • Loading branch information
bitcoinpirate committed Aug 4, 2024
1 parent 6f334f3 commit 6b35f06
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions nip57.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function makeZapRequest({
comment = '',
}: {
profile: string
event: string | null
event: string | Event | null
amount: number
comment: string
relays: string[]
Expand All @@ -68,9 +68,23 @@ export function makeZapRequest({
],
}

if (event) {
if (event && typeof event === 'string') {
zr.tags.push(['e', event])
}
if (event && typeof event === 'object') {
zr.tags.push(['e', event.id])
// replacable event
if ((10000 <= event.kind && event.kind < 20000) || event.kind == 0 || event.kind == 3){
const a = ["a", `${event.kind}:${event.pubkey}`]
zr.tags.push(a)
// parameterized replacable event
}else if (30000 <= event.kind && event.kind < 40000){
let d = event.tags.find(([t, v]) => t === 'd' && v)
if (!d) throw new Error('d tag not found or is empty')
const a = ["a", `${event.kind}:${event.pubkey}:${d[1]}`]
zr.tags.push(a)
}
}

return zr
}
Expand Down

0 comments on commit 6b35f06

Please sign in to comment.