mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-05-12 03:29:57 +02:00
sdk: track event relays on kvstore.
This commit is contained in:
parent
795f9516ae
commit
ba38c28b99
@ -112,6 +112,8 @@ func NewSystem(mods ...SystemModifier) *System {
|
||||
sys.Pool = nostr.NewSimplePool(context.Background(),
|
||||
nostr.WithAuthorKindQueryMiddleware(sys.TrackQueryAttempts),
|
||||
nostr.WithEventMiddleware(sys.TrackEventHints),
|
||||
nostr.WithEventMiddleware(sys.TrackEventRelays),
|
||||
nostr.WithDuplicateMiddleware(sys.TrackEventRelaysD),
|
||||
nostr.WithPenaltyBox(),
|
||||
)
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"net/url"
|
||||
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
@ -108,3 +109,31 @@ func (sys *System) TrackEventHints(ie nostr.RelayEvent) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (sys *System) TrackEventRelays(ie nostr.RelayEvent) {
|
||||
// decode the event ID hex into bytes
|
||||
idBytes, err := hex.DecodeString(ie.ID)
|
||||
if err != nil || len(idBytes) < 8 {
|
||||
return
|
||||
}
|
||||
|
||||
// store only first 8 bytes of event ID as key
|
||||
key := idBytes[:8]
|
||||
|
||||
// store the relay URL as value
|
||||
sys.KVStore.Set(key, []byte(ie.Relay.URL))
|
||||
}
|
||||
|
||||
func (sys *System) TrackEventRelaysD(relay, id string) {
|
||||
// decode the event ID hex into bytes
|
||||
idBytes, err := hex.DecodeString(id)
|
||||
if err != nil || len(idBytes) < 8 {
|
||||
return
|
||||
}
|
||||
|
||||
// store only first 8 bytes of event ID as key
|
||||
key := idBytes[:8]
|
||||
|
||||
// store the relay URL as value
|
||||
sys.KVStore.Set(key, []byte(relay))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user