status-go/protocol/requests/set_community_storenodes.go
Pablo Lopez 3f19972c8e
enable custom community storenodes (#4532)
* enable custom community store nodes

* fix

* fix

* fix

* fix

* cleanup

* fix

* migration

* fix

* cleanup

* fix

* cleanup

* fix

* fix

* cleanup

* message to update the community storenodes

* rename

* fix test

* wait for availability only if global storenode

* fix test

* fix typo

* sync community storenodes

* remove unused

* add tests

* fix imports

* fix todo

* unused

* pr comments

* pr feedback

* revert merge deleted

* fix lint

* fix db and perform ms request

* typo

* fix log

* fix go imports

* refactor handle message

* cleanup public message

* add tests

* fix test

* cleanup test

* fix test

* avoid making one file to big to keep codeclimate from complaining

* fix lint

* revert

* Update protocol/storenodes/database.go

Co-authored-by: richΛrd <info@richardramos.me>

* Update protocol/messenger_mailserver_cycle.go

Co-authored-by: richΛrd <info@richardramos.me>

* PR comment

* fix tx

* proto files

* pr comment

---------

Co-authored-by: richΛrd <info@richardramos.me>
2024-02-20 17:49:39 +02:00

46 lines
1.4 KiB
Go

package requests
import (
"bytes"
"errors"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/protocol/storenodes"
)
var (
ErrSetCommunityStorenodesEmpty = errors.New("set-community-storenodes: empty payload")
ErrSetCommunityStorenodesTooMany = errors.New("set-community-storenodes: too many")
ErrSetCommunityStorenodesMismatch = errors.New("set-community-storenodes: communityId mismatch")
ErrSetCommunityStorenodesMissingCommunity = errors.New("set-community-storenodes: missing community")
ErrSetCommunityStorenodesBadVersion = errors.New("set-community-storenodes: bad version")
)
type SetCommunityStorenodes struct {
CommunityID types.HexBytes `json:"communityId"`
Storenodes []storenodes.Storenode `json:"storenodes"`
}
func (s *SetCommunityStorenodes) Validate() error {
if s == nil || len(s.Storenodes) == 0 {
return ErrSetCommunityStorenodesEmpty
}
if len(s.Storenodes) > 1 {
// TODO for now only allow one
return ErrSetCommunityStorenodesTooMany
}
if len(s.CommunityID) == 0 {
return ErrSetCommunityStorenodesMissingCommunity
}
for _, sn := range s.Storenodes {
if !bytes.Equal(sn.CommunityID, s.CommunityID) {
return ErrSetCommunityStorenodesMismatch
}
if sn.Version == 0 {
return ErrSetCommunityStorenodesBadVersion
}
// TODO validate address and other fields
}
return nil
}