Switch supported_nips to strings
This commit is contained in:
@@ -155,14 +155,14 @@ func (rl *Relay) StartExpirationManager(
|
|||||||
}
|
}
|
||||||
|
|
||||||
go rl.expirationManager.start(rl.ctx)
|
go rl.expirationManager.start(rl.ctx)
|
||||||
rl.Info.AddSupportedNIP(40)
|
rl.Info.AddSupportedNIP("40")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rl *Relay) DisableExpirationManager() {
|
func (rl *Relay) DisableExpirationManager() {
|
||||||
rl.expirationManager.stop()
|
rl.expirationManager.stop()
|
||||||
rl.expirationManager = nil
|
rl.expirationManager = nil
|
||||||
|
|
||||||
idx := slices.Index(rl.Info.SupportedNIPs, 40)
|
idx := slices.Index(rl.Info.SupportedNIPs, "40")
|
||||||
if idx != -1 {
|
if idx != -1 {
|
||||||
rl.Info.SupportedNIPs[idx] = rl.Info.SupportedNIPs[len(rl.Info.SupportedNIPs)-1]
|
rl.Info.SupportedNIPs[idx] = rl.Info.SupportedNIPs[len(rl.Info.SupportedNIPs)-1]
|
||||||
rl.Info.SupportedNIPs = rl.Info.SupportedNIPs[0 : len(rl.Info.SupportedNIPs)-1]
|
rl.Info.SupportedNIPs = rl.Info.SupportedNIPs[0 : len(rl.Info.SupportedNIPs)-1]
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func New(rl *khatru.Relay, repositoryDir string) *GraspServer {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
rl.Info.AddSupportedNIP(34)
|
rl.Info.AddSupportedNIP("34")
|
||||||
rl.Info.SupportedGrasps = append(rl.Info.SupportedGrasps, "GRASP-01")
|
rl.Info.SupportedGrasps = append(rl.Info.SupportedGrasps, "GRASP-01")
|
||||||
|
|
||||||
base := rl.Router()
|
base := rl.Router()
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ func (rl *Relay) HandleNIP11(w http.ResponseWriter, r *http.Request) {
|
|||||||
info := *rl.Info
|
info := *rl.Info
|
||||||
|
|
||||||
if nil != rl.DeleteEvent {
|
if nil != rl.DeleteEvent {
|
||||||
info.AddSupportedNIP(9)
|
info.AddSupportedNIP("9")
|
||||||
}
|
}
|
||||||
if nil != rl.Count {
|
if nil != rl.Count {
|
||||||
info.AddSupportedNIP(45)
|
info.AddSupportedNIP("45")
|
||||||
}
|
}
|
||||||
if rl.Negentropy {
|
if rl.Negentropy {
|
||||||
info.AddSupportedNIP(77)
|
info.AddSupportedNIP("77")
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolve relative icon and banner URLs against base URL
|
// resolve relative icon and banner URLs against base URL
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func NewRelay() *Relay {
|
|||||||
Info: &nip11.RelayInformationDocument{
|
Info: &nip11.RelayInformationDocument{
|
||||||
Software: "https://pkg.go.dev/fiatjaf.com/nostr/khatru",
|
Software: "https://pkg.go.dev/fiatjaf.com/nostr/khatru",
|
||||||
Version: "n/a",
|
Version: "n/a",
|
||||||
SupportedNIPs: []any{1, 11, 42, 70, 86},
|
SupportedNIPs: []string{"1", "11", "42", "70", "86"},
|
||||||
},
|
},
|
||||||
|
|
||||||
upgrader: websocket.Upgrader{
|
upgrader: websocket.Upgrader{
|
||||||
|
|||||||
@@ -9,30 +9,30 @@ import (
|
|||||||
|
|
||||||
func TestAddSupportedNIP(t *testing.T) {
|
func TestAddSupportedNIP(t *testing.T) {
|
||||||
info := RelayInformationDocument{}
|
info := RelayInformationDocument{}
|
||||||
info.AddSupportedNIP(12)
|
info.AddSupportedNIP("12")
|
||||||
info.AddSupportedNIP(12)
|
info.AddSupportedNIP("12")
|
||||||
info.AddSupportedNIP(13)
|
info.AddSupportedNIP("13")
|
||||||
info.AddSupportedNIP(1)
|
info.AddSupportedNIP("1")
|
||||||
info.AddSupportedNIP(12)
|
info.AddSupportedNIP("12")
|
||||||
info.AddSupportedNIP(44)
|
info.AddSupportedNIP("44")
|
||||||
info.AddSupportedNIP(2)
|
info.AddSupportedNIP("2")
|
||||||
info.AddSupportedNIP(13)
|
info.AddSupportedNIP("13")
|
||||||
info.AddSupportedNIP(2)
|
info.AddSupportedNIP("2")
|
||||||
info.AddSupportedNIP(13)
|
info.AddSupportedNIP("13")
|
||||||
info.AddSupportedNIP(0)
|
info.AddSupportedNIP("0")
|
||||||
info.AddSupportedNIP(17)
|
info.AddSupportedNIP("17")
|
||||||
info.AddSupportedNIP(19)
|
info.AddSupportedNIP("19")
|
||||||
info.AddSupportedNIP(1)
|
info.AddSupportedNIP("1")
|
||||||
info.AddSupportedNIP(18)
|
info.AddSupportedNIP("18")
|
||||||
|
|
||||||
assert.Contains(t, info.SupportedNIPs, 0, 1, 2, 12, 13, 17, 18, 19, 44)
|
assert.Contains(t, info.SupportedNIPs, "0", "1", "2", "12", "13", "17", "18", "19", "44")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddSupportedNIPs(t *testing.T) {
|
func TestAddSupportedNIPs(t *testing.T) {
|
||||||
info := RelayInformationDocument{}
|
info := RelayInformationDocument{}
|
||||||
info.AddSupportedNIPs([]int{0, 1, 2, 12, 13, 17, 18, 19, 44})
|
info.AddSupportedNIPs([]int{"0", "1", "2", "12", "13", "17", "18", "19", "44"})
|
||||||
|
|
||||||
assert.Contains(t, info.SupportedNIPs, 0, 1, 2, 12, 13, 17, 18, 19, 44)
|
assert.Contains(t, info.SupportedNIPs, "0", "1", "2", "12", "13", "17", "18", "19", "44")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFetch(t *testing.T) {
|
func TestFetch(t *testing.T) {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ type RelayInformationDocument struct {
|
|||||||
PubKey *nostr.PubKey `json:"pubkey,omitempty"`
|
PubKey *nostr.PubKey `json:"pubkey,omitempty"`
|
||||||
Self *nostr.PubKey `json:"self,omitempty"`
|
Self *nostr.PubKey `json:"self,omitempty"`
|
||||||
Contact string `json:"contact,omitempty"`
|
Contact string `json:"contact,omitempty"`
|
||||||
SupportedNIPs []any `json:"supported_nips,omitempty"`
|
SupportedNIPs []string `json:"supported_nips,omitempty"`
|
||||||
Software string `json:"software,omitempty"`
|
Software string `json:"software,omitempty"`
|
||||||
Version string `json:"version,omitempty"`
|
Version string `json:"version,omitempty"`
|
||||||
|
|
||||||
@@ -33,16 +33,16 @@ type RelayInformationDocument struct {
|
|||||||
SupportedGrasps []string `json:"supported_grasps,omitempty"`
|
SupportedGrasps []string `json:"supported_grasps,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (info *RelayInformationDocument) AddSupportedNIP(number int) {
|
func (info *RelayInformationDocument) AddSupportedNIP(nip string) {
|
||||||
idx := slices.IndexFunc(info.SupportedNIPs, func(n any) bool { return n == number })
|
idx := slices.IndexFunc(info.SupportedNIPs, func(n string) bool { return n == nip })
|
||||||
if idx != -1 {
|
if idx != -1 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
info.SupportedNIPs = append(info.SupportedNIPs, number)
|
info.SupportedNIPs = append(info.SupportedNIPs, nip)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (info *RelayInformationDocument) AddSupportedNIPs(numbers []int) {
|
func (info *RelayInformationDocument) AddSupportedNIPs(numbers []string) {
|
||||||
for _, n := range numbers {
|
for _, n := range numbers {
|
||||||
info.AddSupportedNIP(n)
|
info.AddSupportedNIP(n)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user