github.com/status-im/status-go@v1.1.0/protocol/requests/set_community_storenodes.go (about) 1 package requests 2 3 import ( 4 "bytes" 5 "errors" 6 7 "github.com/status-im/status-go/eth-node/types" 8 "github.com/status-im/status-go/protocol/storenodes" 9 ) 10 11 var ( 12 ErrSetCommunityStorenodesEmpty = errors.New("set-community-storenodes: empty payload") 13 ErrSetCommunityStorenodesTooMany = errors.New("set-community-storenodes: too many") 14 ErrSetCommunityStorenodesMismatch = errors.New("set-community-storenodes: communityId mismatch") 15 ErrSetCommunityStorenodesMissingCommunity = errors.New("set-community-storenodes: missing community") 16 ErrSetCommunityStorenodesBadVersion = errors.New("set-community-storenodes: bad version") 17 ) 18 19 type SetCommunityStorenodes struct { 20 CommunityID types.HexBytes `json:"communityId"` 21 Storenodes []storenodes.Storenode `json:"storenodes"` 22 } 23 24 func (s *SetCommunityStorenodes) Validate() error { 25 if s == nil || len(s.Storenodes) == 0 { 26 return ErrSetCommunityStorenodesEmpty 27 } 28 if len(s.Storenodes) > 1 { 29 // TODO for now only allow one 30 return ErrSetCommunityStorenodesTooMany 31 } 32 if len(s.CommunityID) == 0 { 33 return ErrSetCommunityStorenodesMissingCommunity 34 } 35 for _, sn := range s.Storenodes { 36 if !bytes.Equal(sn.CommunityID, s.CommunityID) { 37 return ErrSetCommunityStorenodesMismatch 38 } 39 if sn.Version == 0 { 40 return ErrSetCommunityStorenodesBadVersion 41 } 42 // TODO validate address and other fields 43 } 44 return nil 45 }