-
Notifications
You must be signed in to change notification settings - Fork 0
/
typesupport.go
48 lines (43 loc) · 1.35 KB
/
typesupport.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
package group
import (
sdk "github.com/blockgenx/blockgen-sdk/types"
sdkerrors "github.com/blockgenx/blockgen-sdk/types/errors"
"github.com/blockgenx/blockgen-sdk/x/group/errors"
)
// MemberRequests defines a repeated slice of MemberRequest objects.
type MemberRequests struct {
Members []MemberRequest
}
// ValidateBasic performs stateless validation on an array of members. On top
// of validating each member individually, it also makes sure there are no
// duplicate addresses.
func (ms MemberRequests) ValidateBasic() error {
index := make(map[string]struct{}, len(ms.Members))
for i := range ms.Members {
member := ms.Members[i]
if err := member.ValidateBasic(); err != nil {
return err
}
addr := member.Address
if _, exists := index[addr]; exists {
return sdkerrors.Wrapf(errors.ErrDuplicate, "address: %s", addr)
}
index[addr] = struct{}{}
}
return nil
}
type accAddresses []sdk.AccAddress
// ValidateBasic verifies that there's no duplicate address.
// Individual account address validation has to be done separately.
func (a accAddresses) ValidateBasic() error {
index := make(map[string]struct{}, len(a))
for i := range a {
accAddr := a[i]
addr := string(accAddr)
if _, exists := index[addr]; exists {
return sdkerrors.Wrapf(errors.ErrDuplicate, "address: %s", accAddr.String())
}
index[addr] = struct{}{}
}
return nil
}