-
Notifications
You must be signed in to change notification settings - Fork 246
/
community_token_permission.go
65 lines (54 loc) · 1.54 KB
/
community_token_permission.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 communities
import (
"reflect"
"github.com/status-im/status-go/protocol/protobuf"
)
type TokenPermissionState uint8
const (
TokenPermissionApproved TokenPermissionState = iota
TokenPermissionAdditionPending
TokenPermissionUpdatePending
TokenPermissionRemovalPending
)
type CommunityTokenPermission struct {
*protobuf.CommunityTokenPermission
State TokenPermissionState `json:"state,omitempty"`
}
func NewCommunityTokenPermission(base *protobuf.CommunityTokenPermission) *CommunityTokenPermission {
return &CommunityTokenPermission{
CommunityTokenPermission: base,
State: TokenPermissionApproved,
}
}
func (p *CommunityTokenPermission) Equals(other *CommunityTokenPermission) bool {
if p.Id != other.Id ||
p.Type != other.Type ||
len(p.TokenCriteria) != len(other.TokenCriteria) ||
len(p.ChatIds) != len(other.ChatIds) ||
p.IsPrivate != other.IsPrivate ||
p.State != other.State {
return false
}
for i := range p.TokenCriteria {
if !compareTokenCriteria(p.TokenCriteria[i], other.TokenCriteria[i]) {
return false
}
}
return reflect.DeepEqual(p.ChatIds, other.ChatIds)
}
func compareTokenCriteria(a, b *protobuf.TokenCriteria) bool {
if a == nil && b == nil {
return true
}
if a == nil || b == nil {
return false
}
return a.Type == b.Type &&
a.Symbol == b.Symbol &&
a.Name == b.Name &&
a.Amount == b.Amount &&
a.EnsPattern == b.EnsPattern &&
a.Decimals == b.Decimals &&
reflect.DeepEqual(a.ContractAddresses, b.ContractAddresses) &&
reflect.DeepEqual(a.TokenIds, b.TokenIds)
}