From ddd8976d3f6dedf3ab97041cc1b22cf7cbada01f Mon Sep 17 00:00:00 2001 From: ZigBalthazar Date: Tue, 14 Jan 2025 15:59:35 +0330 Subject: [PATCH] fix: add retention to nip-11 --- nip11/nip11_test.go | 10 ++++++++++ nip11/types.go | 29 +++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/nip11/nip11_test.go b/nip11/nip11_test.go index f2d8ced..c56bb99 100644 --- a/nip11/nip11_test.go +++ b/nip11/nip11_test.go @@ -28,6 +28,13 @@ func TestAddSupportedNIP(t *testing.T) { assert.Contains(t, info.SupportedNIPs, 0, 1, 2, 12, 13, 17, 18, 19, 44) } +func TestAddSupportedNIPs(t *testing.T) { + info := RelayInformationDocument{} + 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) +} + func TestFetch(t *testing.T) { tests := []struct { inputURL string @@ -38,6 +45,9 @@ func TestFetch(t *testing.T) { {"wss://nostr.wine", false, "", "wss://nostr.wine"}, {"https://nostr.wine", false, "", "wss://nostr.wine"}, {"nostr.wine", false, "", "wss://nostr.wine"}, + {"jellyfish.land", false, "", "wss://jellyfish.land"}, + {"https://jellyfish.land", false, "", "wss://jellyfish.land"}, + {"wss://jellyfish.land", false, "", "wss://jellyfish.land"}, {"wlenwqkeqwe.asjdaskd", true, "", "wss://wlenwqkeqwe.asjdaskd"}, } diff --git a/nip11/types.go b/nip11/types.go index d687668..e6ae1de 100644 --- a/nip11/types.go +++ b/nip11/types.go @@ -15,14 +15,15 @@ type RelayInformationDocument struct { Software string `json:"software"` Version string `json:"version"` - Limitation *RelayLimitationDocument `json:"limitation,omitempty"` - RelayCountries []string `json:"relay_countries,omitempty"` - LanguageTags []string `json:"language_tags,omitempty"` - Tags []string `json:"tags,omitempty"` - PostingPolicy string `json:"posting_policy,omitempty"` - PaymentsURL string `json:"payments_url,omitempty"` - Fees *RelayFeesDocument `json:"fees,omitempty"` - Icon string `json:"icon"` + Limitation *RelayLimitationDocument `json:"limitation,omitempty"` + RelayCountries []string `json:"relay_countries,omitempty"` + LanguageTags []string `json:"language_tags,omitempty"` + Tags []string `json:"tags,omitempty"` + PostingPolicy string `json:"posting_policy,omitempty"` + PaymentsURL string `json:"payments_url,omitempty"` + Fees *RelayFeesDocument `json:"fees,omitempty"` + Retention []*RelayRetentionDocument `json:"retention,omitempty"` + Icon string `json:"icon"` } func (info *RelayInformationDocument) AddSupportedNIP(number int) { @@ -34,6 +35,12 @@ func (info *RelayInformationDocument) AddSupportedNIP(number int) { info.SupportedNIPs = append(info.SupportedNIPs, number) } +func (info *RelayInformationDocument) AddSupportedNIPs(numbers []int) { + for _, n := range numbers { + info.AddSupportedNIP(n) + } +} + type RelayLimitationDocument struct { MaxMessageLength int `json:"max_message_length,omitempty"` MaxSubscriptions int `json:"max_subscriptions,omitempty"` @@ -64,3 +71,9 @@ type RelayFeesDocument struct { Unit string `json:"unit"` } `json:"publication,omitempty"` } + +type RelayRetentionDocument struct { + Time int64 `json:"time,omitempty"` + Count int `json:"count,omitempty"` + Kinds [][]int `json:"kinds,omitempty"` +}