nip11's info.AddSupportedNIP()

This commit is contained in:
fiatjaf
2023-11-18 10:32:15 -03:00
parent fe32ecd440
commit b33fe374c1
2 changed files with 43 additions and 0 deletions

View File

@ -1,5 +1,7 @@
package nip11
import "golang.org/x/exp/slices"
type RelayInformationDocument struct {
Name string `json:"name"`
Description string `json:"description"`
@ -19,6 +21,17 @@ type RelayInformationDocument struct {
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 {
MaxMessageLength int `json:"max_message_length,omitempty"`
MaxSubscriptions int `json:"max_subscriptions,omitempty"`