a bunch of [32]byte conversions. still more needed.

This commit is contained in:
fiatjaf
2025-04-14 17:31:23 -03:00
parent 40535e6b19
commit b4268d649c
132 changed files with 857 additions and 879 deletions

View File

@@ -2,11 +2,9 @@ package sdk
import (
"context"
"strconv"
"strings"
"github.com/nbd-wtf/go-nostr"
cache_memory "github.com/nbd-wtf/go-nostr/sdk/cache/memory"
"fiatjaf.com/nostr"
cache_memory "fiatjaf.com/nostr/sdk/cache/memory"
)
type EventRef struct{ nostr.Pointer }
@@ -15,7 +13,7 @@ func (e EventRef) Value() string { return e.Pointer.AsTagReference() }
func (sys *System) FetchBookmarkList(ctx context.Context, pubkey string) GenericList[EventRef] {
if sys.BookmarkListCache == nil {
sys.BookmarkListCache = cache_memory.New32[GenericList[EventRef]](1000)
sys.BookmarkListCache = cache_memory.New[GenericList[EventRef]](1000)
}
ml, _ := fetchGenericList(sys, ctx, pubkey, 10003, kind_10003, parseEventRef, sys.BookmarkListCache)
@@ -24,7 +22,7 @@ func (sys *System) FetchBookmarkList(ctx context.Context, pubkey string) Generic
func (sys *System) FetchPinList(ctx context.Context, pubkey string) GenericList[EventRef] {
if sys.PinListCache == nil {
sys.PinListCache = cache_memory.New32[GenericList[EventRef]](1000)
sys.PinListCache = cache_memory.New[GenericList[EventRef]](1000)
}
ml, _ := fetchGenericList(sys, ctx, pubkey, 10001, kind_10001, parseEventRef, sys.PinListCache)
@@ -37,36 +35,16 @@ func parseEventRef(tag nostr.Tag) (evr EventRef, ok bool) {
}
switch tag[0] {
case "e":
if !nostr.IsValid32ByteHex(tag[1]) {
pointer, err := nostr.EventPointerFromTag(tag)
if err != nil {
return evr, false
}
pointer := nostr.EventPointer{
ID: tag[1],
}
if len(tag) >= 3 {
pointer.Relays = []string{nostr.NormalizeURL(tag[2])}
if len(tag) >= 4 {
pointer.Author = tag[3]
}
}
evr.Pointer = pointer
case "a":
spl := strings.SplitN(tag[1], ":", 3)
if len(spl) != 3 || !nostr.IsValidPublicKey(spl[1]) {
pointer, err := nostr.EntityPointerFromTag(tag)
if err != nil {
return evr, false
}
pointer := nostr.EntityPointer{
PublicKey: spl[1],
Identifier: spl[2],
}
if kind, err := strconv.Atoi(spl[0]); err != nil {
return evr, false
} else {
pointer.Kind = kind
}
if len(tag) >= 3 {
pointer.Relays = []string{nostr.NormalizeURL(tag[2])}
}
evr.Pointer = pointer
default:
return evr, false