use xhex everywhere.
This commit is contained in:
@@ -3,13 +3,13 @@ package boltdb
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"slices"
|
||||
|
||||
"fiatjaf.com/nostr"
|
||||
"fiatjaf.com/nostr/eventstore/codec/betterbinary"
|
||||
"fiatjaf.com/nostr/nip45"
|
||||
"fiatjaf.com/nostr/nip45/hyperloglog"
|
||||
"github.com/templexxx/xhex"
|
||||
"go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
@@ -174,11 +174,11 @@ func (b *BoltBackend) countEventsHLLCached(filter nostr.Filter) (uint32, *hyperl
|
||||
binary.BigEndian.PutUint16(cacheKey[0:2], uint16(filter.Kinds[0]))
|
||||
switch filter.Kinds[0] {
|
||||
case 3:
|
||||
hex.Decode(cacheKey[2:2+8], []byte(filter.Tags["p"][0][0:8*2]))
|
||||
xhex.Decode(cacheKey[2:2+8], []byte(filter.Tags["p"][0][0:8*2]))
|
||||
case 7:
|
||||
hex.Decode(cacheKey[2:2+8], []byte(filter.Tags["e"][0][0:8*2]))
|
||||
xhex.Decode(cacheKey[2:2+8], []byte(filter.Tags["e"][0][0:8*2]))
|
||||
case 1111:
|
||||
hex.Decode(cacheKey[2:2+8], []byte(filter.Tags["E"][0][0:8*2]))
|
||||
xhex.Decode(cacheKey[2:2+8], []byte(filter.Tags["E"][0][0:8*2]))
|
||||
}
|
||||
|
||||
var count uint32
|
||||
@@ -204,7 +204,7 @@ func (b *BoltBackend) updateHyperLogLogCachedValues(txn *bbolt.Tx, evt nostr.Eve
|
||||
|
||||
for ref, offset := range nip45.HyperLogLogEventPubkeyOffsetsAndReferencesForEvent(evt) {
|
||||
// setup cache key (reusing buffer)
|
||||
hex.Decode(cacheKey[2:2+8], []byte(ref[0:8*2]))
|
||||
xhex.Decode(cacheKey[2:2+8], []byte(ref[0:8*2]))
|
||||
|
||||
// fetch hll value from cache db
|
||||
hll := hyperloglog.New(offset)
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"iter"
|
||||
"slices"
|
||||
@@ -12,6 +11,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"fiatjaf.com/nostr"
|
||||
"github.com/templexxx/xhex"
|
||||
"go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
@@ -284,7 +284,7 @@ func (b *BoltBackend) getTagIndexPrefix(tagName string, tagValue string) (bucket
|
||||
if len(tagValue) == 64 {
|
||||
// but we actually only use the first 8 bytes, with letter (tag name) prefix
|
||||
k = make([]byte, 1+8+4+8)
|
||||
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
|
||||
return indexTag32, k
|
||||
}
|
||||
@@ -294,7 +294,7 @@ func (b *BoltBackend) getTagIndexPrefix(tagName string, tagValue string) (bucket
|
||||
spl := strings.Split(tagValue, ":")
|
||||
if len(spl) == 3 && len(spl[1]) == 64 {
|
||||
k = make([]byte, 1+2+8+30+4+8)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user