define a nostr.Kind type for event kinds, make adjustments everywhere and fix some horrible bugs with mmm, lmdb and badger querying and deleting.

This commit is contained in:
fiatjaf
2025-04-20 11:14:39 -03:00
parent 27f40c2cf2
commit 15c6093c9b
74 changed files with 689 additions and 404 deletions

View File

@@ -0,0 +1,23 @@
package betterbinary
import (
"encoding/binary"
"fiatjaf.com/nostr"
)
func GetKind(evtb []byte) nostr.Kind {
return nostr.Kind(binary.LittleEndian.Uint16(evtb[1:3]))
}
func GetID(evtb []byte) nostr.ID {
return nostr.ID(evtb[7:39])
}
func GetPubKey(evtb []byte) nostr.PubKey {
return nostr.PubKey(evtb[39:71])
}
func GetCreatedAt(evtb []byte) nostr.Timestamp {
return nostr.Timestamp(binary.LittleEndian.Uint32(evtb[3:7]))
}

View File

@@ -107,7 +107,7 @@ func Unmarshal(data []byte, evt *nostr.Event) (err error) {
}
}()
evt.Kind = uint16(binary.LittleEndian.Uint16(data[1:3]))
evt.Kind = nostr.Kind(binary.LittleEndian.Uint16(data[1:3]))
evt.CreatedAt = nostr.Timestamp(binary.LittleEndian.Uint32(data[3:7]))
evt.ID = nostr.ID(data[7:39])
evt.PubKey = nostr.PubKey(data[39:71])

View File

@@ -27,7 +27,3 @@ func TagMatches(evtb []byte, key string, vals []string) bool {
}
return false
}
func KindMatches(evtb []byte, kind uint16) bool {
return binary.LittleEndian.Uint16(evtb[1:3]) == kind
}