move nostr-sdk repository into here because why not?

This commit is contained in:
fiatjaf
2024-09-10 22:37:48 -03:00
parent c6ea51653b
commit 072da132f4
29 changed files with 1970 additions and 33 deletions

41
sdk/relays.go Normal file
View File

@@ -0,0 +1,41 @@
package sdk
import (
"github.com/nbd-wtf/go-nostr"
)
type RelayList = GenericList[Relay]
type Relay struct {
URL string
Inbox bool
Outbox bool
}
func (r Relay) Value() string { return r.URL }
func parseRelayFromKind10002(tag nostr.Tag) (rl Relay, ok bool) {
if u := tag.Value(); u != "" && tag[0] == "r" {
if !nostr.IsValidRelayURL(u) {
return rl, false
}
u := nostr.NormalizeURL(u)
relay := Relay{
URL: u,
}
if len(tag) == 2 {
relay.Inbox = true
relay.Outbox = true
} else if tag[2] == "write" {
relay.Outbox = true
} else if tag[2] == "read" {
relay.Inbox = true
}
return relay, true
}
return rl, false
}