replace deprecated functions in multiple places.

This commit is contained in:
fiatjaf 2025-03-10 02:54:34 -03:00
parent 8d869009b0
commit 459273216c
7 changed files with 19 additions and 27 deletions

View File

@ -153,12 +153,10 @@ func ListenForMessages(
return return
} }
for ie := range pool.SubMany(ctx, ourRelays, nostr.Filters{ for ie := range pool.SubscribeMany(ctx, ourRelays, nostr.Filter{
{ Kinds: []int{nostr.KindGiftWrap},
Kinds: []int{nostr.KindGiftWrap}, Tags: nostr.TagMap{"p": []string{pk}},
Tags: nostr.TagMap{"p": []string{pk}}, Since: &since,
Since: &since,
},
}) { }) {
rumor, err := nip59.GiftUnwrap( rumor, err := nip59.GiftUnwrap(
*ie.Event, *ie.Event,

View File

@ -113,13 +113,11 @@ func NewBunker(
go func() { go func() {
now := nostr.Now() now := nostr.Now()
events := pool.SubMany(ctx, relays, nostr.Filters{ events := pool.SubscribeMany(ctx, relays, nostr.Filter{
{ Tags: nostr.TagMap{"p": []string{clientPublicKey}},
Tags: nostr.TagMap{"p": []string{clientPublicKey}}, Kinds: []int{nostr.KindNostrConnect},
Kinds: []int{nostr.KindNostrConnect}, Since: &now,
Since: &now, LimitZero: true,
LimitZero: true,
},
}, nostr.WithLabel("bunker46client")) }, nostr.WithLabel("bunker46client"))
for ie := range events { for ie := range events {
if ie.Kind != nostr.KindNostrConnect { if ie.Kind != nostr.KindNostrConnect {

View File

@ -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) fmt.Errorf("event kind is %d, but we expected %d", event.Kind, nostr.KindNostrConnect)
} }
handler := event.Tags.GetFirst([]string{"p", ""}) handler := event.Tags.Find("p")
if handler == nil || !nostr.IsValid32ByteHex((*handler)[1]) { if handler == nil || !nostr.IsValid32ByteHex(handler[1]) {
return req, resp, eventResponse, fmt.Errorf("invalid \"p\" tag") return req, resp, eventResponse, fmt.Errorf("invalid \"p\" tag")
} }
handlerPubkey := (*handler)[1] handlerPubkey := handler[1]
handlerSecret, err := p.getHandlerSecretKey(handlerPubkey) handlerSecret, err := p.getHandlerSecretKey(handlerPubkey)
if err != nil { if err != nil {
return req, resp, eventResponse, fmt.Errorf("no private key for %s: %w", handlerPubkey, err) return req, resp, eventResponse, fmt.Errorf("no private key for %s: %w", handlerPubkey, err)

View File

@ -34,7 +34,7 @@ func (pool *SimplePool) PaginatorWithInterval(
time.Sleep(interval) time.Sleep(interval)
keepGoing := false 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) { if slices.Contains(repeatedCache, evt.ID) {
continue continue
} }

View File

@ -32,7 +32,7 @@ func TestMetadataAndEvents(t *testing.T) {
Limit: 5, Limit: 5,
} }
events := make([]*nostr.Event, 0, 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) events = append(events, ie.Event)
} }
require.NoError(t, err) require.NoError(t, err)

View File

@ -10,11 +10,9 @@ func (sys *System) SearchUsers(ctx context.Context, query string) []ProfileMetad
limit := 10 limit := 10
profiles := make([]ProfileMetadata, 0, limit*len(sys.UserSearchRelays.URLs)) profiles := make([]ProfileMetadata, 0, limit*len(sys.UserSearchRelays.URLs))
for ie := range sys.Pool.SubManyEose(ctx, sys.UserSearchRelays.URLs, nostr.Filters{ for ie := range sys.Pool.FetchMany(ctx, sys.UserSearchRelays.URLs, nostr.Filter{
{ Search: query,
Search: query, Limit: limit,
Limit: limit,
},
}, nostr.WithLabel("search")) { }, nostr.WithLabel("search")) {
m, _ := ParseMetadata(ie.Event) m, _ := ParseMetadata(ie.Event)
profiles = append(profiles, m) profiles = append(profiles, m)

View File

@ -15,10 +15,8 @@ func TestTagHelpers(t *testing.T) {
Tag{"e", "ffffff"}, Tag{"e", "ffffff"},
} }
assert.NotNil(t, tags.GetFirst([]string{"x"}), "failed to get existing prefix") assert.Nil(t, tags.Find("x"), "Find shouldn't have returned a tag with a single item")
assert.Nil(t, tags.GetFirst([]string{"x", ""}), "got with wrong prefix") assert.NotNil(t, tags.FindWithValue("p", "abcdef"), "failed to get with existing 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.Equal(t, "ffffff", tags.FindLast("e")[1], "failed to get last") 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") assert.Equal(t, 2, len(tags.GetAll([]string{"e", ""})), "failed to get all")
c := make(Tags, 0, 2) c := make(Tags, 0, 2)