use xhex everywhere.

This commit is contained in:
fiatjaf
2025-11-21 21:16:34 -03:00
parent 61b9717c5c
commit 55a43e46b7
46 changed files with 185 additions and 177 deletions

View File

@@ -4,7 +4,6 @@ import (
"bytes"
"crypto/md5"
"encoding/binary"
"encoding/hex"
"fmt"
"iter"
"slices"
@@ -13,6 +12,7 @@ import (
"fiatjaf.com/nostr"
"github.com/PowerDNS/lmdb-go/lmdb"
"github.com/templexxx/xhex"
)
type iterator struct {
@@ -244,7 +244,7 @@ func (b *LMDBBackend) getIndexKeysForEvent(evt nostr.Event) iter.Seq[key] {
// now the p-tag+kind+date
if dbi == b.indexTag32 && tag[0] == "p" {
k := make([]byte, 8+2+4)
hex.Decode(k[0:8], []byte(tag[1][0:8*2]))
xhex.Decode(k[0:8], []byte(tag[1][0:8*2]))
binary.BigEndian.PutUint16(k[8:8+2], uint16(evt.Kind))
binary.BigEndian.PutUint32(k[8+2:8+2+4], uint32(evt.CreatedAt))
dbi := b.indexPTagKind
@@ -276,7 +276,7 @@ func (b *LMDBBackend) getTagIndexPrefix(tagName string, tagValue string) (lmdb.D
if len(tagValue) == 64 {
// but we actually only use the first 8 bytes, with letter (tag name) prefix
k = make([]byte, 1+8+4)
if _, err := hex.Decode(k[1:1+8], []byte(tagValue[0:8*2])); err == nil {
if err := xhex.Decode(k[1:1+8], []byte(tagValue[0:8*2])); err == nil {
k[0] = letterPrefix
offset = 1 + 8
dbi = b.indexTag32
@@ -288,7 +288,7 @@ func (b *LMDBBackend) getTagIndexPrefix(tagName string, tagValue string) (lmdb.D
spl := strings.Split(tagValue, ":")
if len(spl) == 3 && len(spl[1]) == 64 {
k = make([]byte, 1+2+8+30+4)
if _, err := hex.Decode(k[1+2:1+2+8], []byte(spl[1][0:8*2])); err == nil {
if err := xhex.Decode(k[1+2:1+2+8], []byte(spl[1][0:8*2])); err == nil {
if kind, err := strconv.ParseUint(spl[0], 10, 16); err == nil {
k[0] = letterPrefix
k[1] = byte(kind >> 8)