/
types.go
47 lines (41 loc) · 1.23 KB
/
types.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
package v039
import (
"fmt"
"strings"
)
// GenesisState is the head state of all scopes with history.
type GenesisState struct {
ScopeRecords []Scope `json:"scope_records,omitempty"`
// NOTE: this comes from the v39 spec module that was merged in. The migrate step should copy this over
Specifications []ContractSpec `json:"specifications,omitempty"`
}
// SpecGenesisState is a sequence of contract specs (from the deprecated spec module)
type SpecGenesisState struct {
ContractSpecRecords []ContractSpec `json:"contract_spec_records"`
}
// Validate ensures the genesis state is valid.
func (state GenesisState) Validate() error {
for _, s := range state.ScopeRecords {
if err := ValidateScope(s); err != nil {
return err
}
}
return nil
}
// ValidateScope ensures required scope fields are valid.
func ValidateScope(s Scope) error {
if s.Uuid == nil {
return fmt.Errorf("scope UUID cannot be nil")
}
if strings.TrimSpace(s.Uuid.Value) == "" {
return fmt.Errorf("scope UUID value cannot be empty")
}
if len(s.Parties) == 0 {
return fmt.Errorf("scope must have at least one party")
}
return nil
}
// DefaultGenesisState returns a zero-value genesis state.
func DefaultGenesisState() GenesisState {
return GenesisState{}
}