From 1e76aec88417c310c9c30b652555d402ba3087f4 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 28 Jan 2025 23:47:35 -0300 Subject: [PATCH] nip60: fix receive proof saving, send nil to Processed, do a dedicated kind:5 filter, hack for initial processing race condition. --- nip60/receive.go | 2 +- nip60/send.go | 2 +- nip60/stash.go | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/nip60/receive.go b/nip60/receive.go index 425dd29..4c2a59b 100644 --- a/nip60/receive.go +++ b/nip60/receive.go @@ -48,7 +48,7 @@ func (w *Wallet) ReceiveToken(ctx context.Context, serializedToken string) error } // get new proofs - _, newProofs, err := w.SwapProofs(ctx, source, proofs, proofs.Amount(), swapOpts...) + newProofs, _, err := w.SwapProofs(ctx, source, proofs, proofs.Amount(), swapOpts...) if err != nil { return err } diff --git a/nip60/send.go b/nip60/send.go index b6c71cf..f8d778f 100644 --- a/nip60/send.go +++ b/nip60/send.go @@ -148,7 +148,7 @@ found: deleteEvent := nostr.Event{ CreatedAt: nostr.Now(), Kind: 5, - Tags: nostr.Tags{{"e", token.event.ID}}, + Tags: nostr.Tags{{"e", token.event.ID}, {"k", "7375"}}, } w.wl.kr.SignEvent(ctx, &deleteEvent) w.wl.Changes <- deleteEvent diff --git a/nip60/stash.go b/nip60/stash.go index d809a4b..8d35490 100644 --- a/nip60/stash.go +++ b/nip60/stash.go @@ -6,6 +6,7 @@ import ( "iter" "strings" "sync" + "time" "github.com/btcsuite/btcd/btcec/v2" "github.com/nbd-wtf/go-nostr" @@ -46,7 +47,10 @@ func LoadStash( events := pool.SubManyNotifyEOSE( ctx, relays, - nostr.Filters{{Kinds: []int{5, 37375, 7375, 7376}, Authors: []string{pk}}}, + nostr.Filters{ + {Kinds: []int{37375, 7375, 7376}, Authors: []string{pk}}, + {Kinds: []int{5}, Tags: nostr.TagMap{"k": []string{"7375"}}, Authors: []string{pk}}, + }, eoseChan, ) @@ -81,6 +85,7 @@ func loadStash( } wl.pendingDeletions = nil + time.Sleep(100 * time.Millisecond) // race condition hack close(wl.Stable) }() @@ -204,6 +209,7 @@ func loadStash( } } + wl.Processed <- nil wl.Unlock() } }()