-
Notifications
You must be signed in to change notification settings - Fork 242
/
set_community_storenodes.go
45 lines (40 loc) · 1.38 KB
/
set_community_storenodes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
}