-
Notifications
You must be signed in to change notification settings - Fork 5
/
sender_groups.go
49 lines (42 loc) · 1.04 KB
/
sender_groups.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
package contracts
import (
"fmt"
)
type SenderGroup struct {
Name string
Allow ContractAddresses
}
func (s SenderGroup) String() string {
str := fmt.Sprintf("- sender group '%s'\n", s.Name)
for _, a := range s.Allow {
str += fmt.Sprintf("- allow chain %d address %s\n", a.ChainId, a.Address)
}
return str
}
type SenderGroups []*SenderGroup
// Validate senderGroups does not contain duplicated name.
func (s SenderGroups) Validate() error {
groupAllows := make(map[string]ContractAddresses)
for _, group := range s {
if groupAllows[group.Name] != nil {
return fmt.Errorf("duplicated sender group in executor.toml [service.contract_sender_groups]: %s", group.Name)
}
groupAllows[group.Name] = group.Allow
}
return nil
}
func (s SenderGroups) AllowedSenders(senderGroupName string) ContractAddresses {
for _, group := range s {
if group.Name == senderGroupName {
return group.Allow
}
}
return []*ContractAddress{}
}
func (s SenderGroups) String() string {
str := ""
for _, sg := range s {
str += sg.String()
}
return str
}