-
Notifications
You must be signed in to change notification settings - Fork 31
/
genesis.go
49 lines (40 loc) · 1.22 KB
/
genesis.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 types
import (
"fmt"
"strings"
)
// DefaultIndex is the default capability global index
const DefaultIndex uint64 = 1
// DefaultGenesis returns the default Capability genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
Index: DefaultIndex,
Owners: []GenesisOwners{},
}
}
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
// NOTE: index must be greater than 0
if gs.Index == 0 {
return fmt.Errorf("capability index must be non-zero")
}
for _, genOwner := range gs.Owners {
if len(genOwner.IndexOwners.Owners) == 0 {
return fmt.Errorf("empty owners in genesis")
}
// all exported existing indices must be between [1, gs.Index)
if genOwner.Index == 0 || genOwner.Index >= gs.Index {
return fmt.Errorf("owners exist for index %d outside of valid range: %d-%d", genOwner.Index, 1, gs.Index-1)
}
for _, owner := range genOwner.IndexOwners.Owners {
if strings.TrimSpace(owner.Module) == "" {
return fmt.Errorf("owner's module cannot be blank: %s", owner)
}
if strings.TrimSpace(owner.Name) == "" {
return fmt.Errorf("owner's name cannot be blank: %s", owner)
}
}
}
return nil
}