/
genesis.go
56 lines (47 loc) · 1.67 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
50
51
52
53
54
55
56
package types
import "fmt"
// DefaultGenesis returns the default genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
ClaimList: []Claim{},
ProofList: []Proof{},
// this line is used by starport scaffolding # genesis/types/default
Params: DefaultParams(),
}
}
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
// Check for duplicated index in claim
claimPrimaryKeyMap := make(map[string]struct{})
// Ensure claims are unique with respect to a given session ID and supplier address.
for _, claim := range gs.ClaimList {
// TODO_BLOCKER: ensure the corresponding supplier exists and is staked.
if claim.GetRootHash() == nil {
return fmt.Errorf("root hash cannot be nil")
}
if len(claim.GetRootHash()) == 0 {
return fmt.Errorf("root hash cannot be empty")
}
sessionId := claim.GetSessionHeader().GetSessionId()
primaryKey := string(ClaimPrimaryKey(sessionId, claim.SupplierAddress))
if _, ok := claimPrimaryKeyMap[primaryKey]; ok {
return fmt.Errorf("duplicated supplierAddr for claim")
}
claimPrimaryKeyMap[primaryKey] = struct{}{}
}
// Check for duplicated index in proof
proofPrimaryKeyMap := make(map[string]struct{})
for _, proof := range gs.ProofList {
proofPrimaryKey := string(ProofPrimaryKey(
proof.GetSessionHeader().GetSessionId(),
proof.GetSupplierAddress(),
))
if _, ok := proofPrimaryKeyMap[proofPrimaryKey]; ok {
return fmt.Errorf("duplicated primaryKey for proof")
}
proofPrimaryKeyMap[proofPrimaryKey] = struct{}{}
}
// this line is used by starport scaffolding # genesis/types/validate
return gs.Params.Validate()
}