mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-06-12 18:00:52 +02:00
nip11's info.AddSupportedNIP()
This commit is contained in:
parent
fe32ecd440
commit
b33fe374c1
30
nip11/nip11_test.go
Normal file
30
nip11/nip11_test.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package nip11
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestAddSupportedNIP(t *testing.T) {
|
||||||
|
info := RelayInformationDocument{}
|
||||||
|
info.AddSupportedNIP(12)
|
||||||
|
info.AddSupportedNIP(12)
|
||||||
|
info.AddSupportedNIP(13)
|
||||||
|
info.AddSupportedNIP(1)
|
||||||
|
info.AddSupportedNIP(12)
|
||||||
|
info.AddSupportedNIP(44)
|
||||||
|
info.AddSupportedNIP(2)
|
||||||
|
info.AddSupportedNIP(13)
|
||||||
|
info.AddSupportedNIP(2)
|
||||||
|
info.AddSupportedNIP(13)
|
||||||
|
info.AddSupportedNIP(0)
|
||||||
|
info.AddSupportedNIP(17)
|
||||||
|
info.AddSupportedNIP(19)
|
||||||
|
info.AddSupportedNIP(1)
|
||||||
|
info.AddSupportedNIP(18)
|
||||||
|
|
||||||
|
for i, v := range []int{0, 1, 2, 12, 13, 17, 18, 19, 44} {
|
||||||
|
if info.SupportedNIPs[i] != v {
|
||||||
|
t.Errorf("expected info.SupportedNIPs[%d] to equal %v, got %v",
|
||||||
|
i, v, info.SupportedNIPs)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package nip11
|
package nip11
|
||||||
|
|
||||||
|
import "golang.org/x/exp/slices"
|
||||||
|
|
||||||
type RelayInformationDocument struct {
|
type RelayInformationDocument struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
@ -19,6 +21,17 @@ type RelayInformationDocument struct {
|
|||||||
Icon string `json:"icon"`
|
Icon string `json:"icon"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (info *RelayInformationDocument) AddSupportedNIP(number int) {
|
||||||
|
idx, exists := slices.BinarySearch(info.SupportedNIPs, number)
|
||||||
|
if exists {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
info.SupportedNIPs = append(info.SupportedNIPs, -1)
|
||||||
|
copy(info.SupportedNIPs[idx+1:], info.SupportedNIPs[idx:])
|
||||||
|
info.SupportedNIPs[idx] = number
|
||||||
|
}
|
||||||
|
|
||||||
type RelayLimitationDocument struct {
|
type RelayLimitationDocument struct {
|
||||||
MaxMessageLength int `json:"max_message_length,omitempty"`
|
MaxMessageLength int `json:"max_message_length,omitempty"`
|
||||||
MaxSubscriptions int `json:"max_subscriptions,omitempty"`
|
MaxSubscriptions int `json:"max_subscriptions,omitempty"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user