mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-09-17 19:13:56 +02:00
nip45: hyperlolog small fixes and improvements. support deterministic offset for hardcoded set of queries.
This commit is contained in:
42
nip45/hll_event.go
Normal file
42
nip45/hll_event.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package nip45
|
||||
|
||||
import (
|
||||
"iter"
|
||||
"strconv"
|
||||
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
)
|
||||
|
||||
func HyperLogLogEventPubkeyOffsetsAndReferencesForEvent(evt *nostr.Event) iter.Seq2[string, int] {
|
||||
return func(yield func(string, int) bool) {
|
||||
switch evt.Kind {
|
||||
case 3:
|
||||
//
|
||||
// follower counts
|
||||
for _, tag := range evt.Tags {
|
||||
if len(tag) >= 2 && tag[0] == "p" && nostr.IsValid32ByteHex(tag[1]) {
|
||||
// 32th nibble of each "p" tag
|
||||
p, _ := strconv.ParseInt(tag[1][32:33], 16, 64)
|
||||
if !yield(tag[1], int(p+8)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
case 7:
|
||||
//
|
||||
// reaction counts:
|
||||
// (only the last "e" tag counts)
|
||||
lastE := evt.Tags.GetLast([]string{"e", ""})
|
||||
if lastE != nil {
|
||||
v := (*lastE)[1]
|
||||
if nostr.IsValid32ByteHex(v) {
|
||||
// 32th nibble of "e" tag
|
||||
p, _ := strconv.ParseInt(v[32:33], 16, 64)
|
||||
if !yield(v, int(p+8)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user