From 459273216c1bb1d14a192a381f23d2638495fd59 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Mon, 10 Mar 2025 02:54:34 -0300 Subject: [PATCH] replace deprecated functions in multiple places. --- nip17/nip17.go | 10 ++++------ nip46/client.go | 12 +++++------- nip46/dynamic-signer.go | 6 +++--- paginator.go | 2 +- sdk/sdk_test.go | 2 +- sdk/search.go | 8 +++----- tag_test.go | 6 ++---- 7 files changed, 19 insertions(+), 27 deletions(-) diff --git a/nip17/nip17.go b/nip17/nip17.go index fe04b18..1647e7a 100644 --- a/nip17/nip17.go +++ b/nip17/nip17.go @@ -153,12 +153,10 @@ func ListenForMessages( return } - for ie := range pool.SubMany(ctx, ourRelays, nostr.Filters{ - { - Kinds: []int{nostr.KindGiftWrap}, - Tags: nostr.TagMap{"p": []string{pk}}, - Since: &since, - }, + for ie := range pool.SubscribeMany(ctx, ourRelays, nostr.Filter{ + Kinds: []int{nostr.KindGiftWrap}, + Tags: nostr.TagMap{"p": []string{pk}}, + Since: &since, }) { rumor, err := nip59.GiftUnwrap( *ie.Event, diff --git a/nip46/client.go b/nip46/client.go index 4a84b25..f8f3c28 100644 --- a/nip46/client.go +++ b/nip46/client.go @@ -113,13 +113,11 @@ func NewBunker( go func() { now := nostr.Now() - events := pool.SubMany(ctx, relays, nostr.Filters{ - { - Tags: nostr.TagMap{"p": []string{clientPublicKey}}, - Kinds: []int{nostr.KindNostrConnect}, - Since: &now, - LimitZero: true, - }, + events := pool.SubscribeMany(ctx, relays, nostr.Filter{ + Tags: nostr.TagMap{"p": []string{clientPublicKey}}, + Kinds: []int{nostr.KindNostrConnect}, + Since: &now, + LimitZero: true, }, nostr.WithLabel("bunker46client")) for ie := range events { if ie.Kind != nostr.KindNostrConnect { diff --git a/nip46/dynamic-signer.go b/nip46/dynamic-signer.go index 5cc29a8..eaf7ca4 100644 --- a/nip46/dynamic-signer.go +++ b/nip46/dynamic-signer.go @@ -94,12 +94,12 @@ func (p *DynamicSigner) HandleRequest(ctx context.Context, event *nostr.Event) ( fmt.Errorf("event kind is %d, but we expected %d", event.Kind, nostr.KindNostrConnect) } - handler := event.Tags.GetFirst([]string{"p", ""}) - if handler == nil || !nostr.IsValid32ByteHex((*handler)[1]) { + handler := event.Tags.Find("p") + if handler == nil || !nostr.IsValid32ByteHex(handler[1]) { return req, resp, eventResponse, fmt.Errorf("invalid \"p\" tag") } - handlerPubkey := (*handler)[1] + handlerPubkey := handler[1] handlerSecret, err := p.getHandlerSecretKey(handlerPubkey) if err != nil { return req, resp, eventResponse, fmt.Errorf("no private key for %s: %w", handlerPubkey, err) diff --git a/paginator.go b/paginator.go index ea5e57d..044a8c5 100644 --- a/paginator.go +++ b/paginator.go @@ -34,7 +34,7 @@ func (pool *SimplePool) PaginatorWithInterval( time.Sleep(interval) keepGoing := false - for evt := range pool.SubManyEose(ctx, urls, Filters{filter}, opts...) { + for evt := range pool.FetchMany(ctx, urls, filter, opts...) { if slices.Contains(repeatedCache, evt.ID) { continue } diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index 2ce58ec..e38794c 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -32,7 +32,7 @@ func TestMetadataAndEvents(t *testing.T) { Limit: 5, } events := make([]*nostr.Event, 0, 5) - for ie := range sys.Pool.SubManyEose(ctx, relays, nostr.Filters{filter}) { + for ie := range sys.Pool.FetchMany(ctx, relays, filter) { events = append(events, ie.Event) } require.NoError(t, err) diff --git a/sdk/search.go b/sdk/search.go index 48550ca..2482964 100644 --- a/sdk/search.go +++ b/sdk/search.go @@ -10,11 +10,9 @@ func (sys *System) SearchUsers(ctx context.Context, query string) []ProfileMetad limit := 10 profiles := make([]ProfileMetadata, 0, limit*len(sys.UserSearchRelays.URLs)) - for ie := range sys.Pool.SubManyEose(ctx, sys.UserSearchRelays.URLs, nostr.Filters{ - { - Search: query, - Limit: limit, - }, + for ie := range sys.Pool.FetchMany(ctx, sys.UserSearchRelays.URLs, nostr.Filter{ + Search: query, + Limit: limit, }, nostr.WithLabel("search")) { m, _ := ParseMetadata(ie.Event) profiles = append(profiles, m) diff --git a/tag_test.go b/tag_test.go index 846e58f..2f91cbd 100644 --- a/tag_test.go +++ b/tag_test.go @@ -15,10 +15,8 @@ func TestTagHelpers(t *testing.T) { Tag{"e", "ffffff"}, } - assert.NotNil(t, tags.GetFirst([]string{"x"}), "failed to get existing prefix") - assert.Nil(t, tags.GetFirst([]string{"x", ""}), "got with wrong prefix") - assert.NotNil(t, tags.GetFirst([]string{"p", "abcdef", "wss://"}), "failed to get with existing prefix") - assert.NotNil(t, tags.GetFirst([]string{"p", "abcdef", ""}), "failed to get with existing prefix (blank last string)") + assert.Nil(t, tags.Find("x"), "Find shouldn't have returned a tag with a single item") + assert.NotNil(t, tags.FindWithValue("p", "abcdef"), "failed to get with existing prefix") assert.Equal(t, "ffffff", tags.FindLast("e")[1], "failed to get last") assert.Equal(t, 2, len(tags.GetAll([]string{"e", ""})), "failed to get all") c := make(Tags, 0, 2)