mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-07-09 23:59:54 +02:00
nip11: support hex nip numbers as strings.
This commit is contained in:
@ -25,10 +25,7 @@ func TestAddSupportedNIP(t *testing.T) {
|
|||||||
info.AddSupportedNIP(1)
|
info.AddSupportedNIP(1)
|
||||||
info.AddSupportedNIP(18)
|
info.AddSupportedNIP(18)
|
||||||
|
|
||||||
for i, v := range []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.Equal(t, v, info.SupportedNIPs[i], "expected info.SupportedNIPs[%d] to equal %v, got %v",
|
|
||||||
i, v, info.SupportedNIPs)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFetch(t *testing.T) {
|
func TestFetch(t *testing.T) {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package nip11
|
package nip11
|
||||||
|
|
||||||
import "slices"
|
import (
|
||||||
|
"slices"
|
||||||
|
)
|
||||||
|
|
||||||
type RelayInformationDocument struct {
|
type RelayInformationDocument struct {
|
||||||
URL string `json:"-"`
|
URL string `json:"-"`
|
||||||
@ -9,7 +11,7 @@ type RelayInformationDocument struct {
|
|||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
PubKey string `json:"pubkey"`
|
PubKey string `json:"pubkey"`
|
||||||
Contact string `json:"contact"`
|
Contact string `json:"contact"`
|
||||||
SupportedNIPs []int `json:"supported_nips"`
|
SupportedNIPs []any `json:"supported_nips"`
|
||||||
Software string `json:"software"`
|
Software string `json:"software"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
|
|
||||||
@ -24,14 +26,12 @@ type RelayInformationDocument struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (info *RelayInformationDocument) AddSupportedNIP(number int) {
|
func (info *RelayInformationDocument) AddSupportedNIP(number int) {
|
||||||
idx, exists := slices.BinarySearch(info.SupportedNIPs, number)
|
idx := slices.IndexFunc(info.SupportedNIPs, func(n any) bool { return n == number })
|
||||||
if exists {
|
if idx != -1 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
info.SupportedNIPs = append(info.SupportedNIPs, -1)
|
info.SupportedNIPs = append(info.SupportedNIPs, number)
|
||||||
copy(info.SupportedNIPs[idx+1:], info.SupportedNIPs[idx:])
|
|
||||||
info.SupportedNIPs[idx] = number
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type RelayLimitationDocument struct {
|
type RelayLimitationDocument struct {
|
||||||
|
Reference in New Issue
Block a user