-
Notifications
You must be signed in to change notification settings - Fork 246
/
request_to_join_community.go
65 lines (52 loc) · 2.33 KB
/
request_to_join_community.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package requests
import (
"errors"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
)
var ErrRequestToJoinCommunityInvalidCommunityID = errors.New("request-to-join-community: invalid community id")
var ErrRequestToJoinCommunityNoAddressesToReveal = errors.New("request-to-join-community: no addresses to reveal")
var ErrRequestToJoinCommunityMissingPassword = errors.New("request-to-join-community: password is necessary when sending a list of addresses")
var ErrRequestToJoinNoAirdropAddress = errors.New("request-to-join-community: airdropAddress is necessary when sending a list of addresses")
var ErrRequestToJoinNoAirdropAddressAmongAddressesToReveal = errors.New("request-to-join-community: airdropAddress must be in the set of addresses to reveal")
var ErrRequestToJoinCommunityInvalidSignature = errors.New("request-to-join-community: invalid signature")
type RequestToJoinCommunity struct {
CommunityID types.HexBytes `json:"communityId"`
ENSName string `json:"ensName"`
AddressesToReveal []string `json:"addressesToReveal"`
Signatures []types.HexBytes `json:"signatures"` // the order of signatures should match the order of addresses
AirdropAddress string `json:"airdropAddress"`
}
func (j *RequestToJoinCommunity) Validate(full bool) error {
// TODO: A parital validation, in case `full` is set to `false` should check `AddressesToReveal` as well. But because of changes
// that need to be done in tests we cannot do that now.
// Also in the line 61, we should remove `len(signature) > 0` from the condition, but from the same reason we cannot do that now.
if len(j.CommunityID) == 0 {
return ErrRequestToJoinCommunityInvalidCommunityID
}
if !full {
return nil
}
if len(j.AddressesToReveal) == 0 {
return ErrRequestToJoinCommunityNoAddressesToReveal
}
if j.AirdropAddress == "" {
return ErrRequestToJoinNoAirdropAddress
}
found := false
for _, address := range j.AddressesToReveal {
if address == j.AirdropAddress {
found = true
break
}
}
if !found {
return ErrRequestToJoinNoAirdropAddressAmongAddressesToReveal
}
for _, signature := range j.Signatures {
if len(signature) > 0 && len(signature) != crypto.SignatureLength {
return ErrRequestToJoinCommunityInvalidSignature
}
}
return nil
}