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
}
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,

View File

@ -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 {

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)
}
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)

View File

@ -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
}

View File

@ -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)

View File

@ -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)

View File

@ -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)