/
genesis.go
72 lines (64 loc) · 2.42 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package types
import (
"fmt"
undtypes "github.com/unification-com/mainchain/types"
)
const (
// WRKChain fees, in nano FUND
RegFee = 1000000000000 // 1000 FUND - used in init genesis
RecordFee = 1000000000 // 1 FUND - used in init genesis
PurchaseStorageFee = 5000000000 // 5 FUND - used in init genesis
FeeDenom = undtypes.DefaultDenomination // used in init genesis
DefaultStartingWrkChainID uint64 = 1 // used in init genesis
DefaultStorageLimit uint64 = 50000 // used in init genesis
DefaultMaxStorageLimit uint64 = 600000 // used in init genesis
)
// NewGenesisState creates a new GenesisState object
func NewGenesisState(params Params, startingWrkChainID uint64, wrkChains WrkChainExports) *GenesisState {
return &GenesisState{
Params: params,
StartingWrkchainId: startingWrkChainID,
RegisteredWrkchains: wrkChains,
}
}
// DefaultGenesisState creates a default GenesisState object
func DefaultGenesisState() *GenesisState {
return &GenesisState{
Params: DefaultParams(),
StartingWrkchainId: DefaultStartingWrkChainID,
RegisteredWrkchains: nil,
}
}
// ValidateGenesis validates the provided genesis state to ensure the
// expected invariants holds.
func ValidateGenesis(data GenesisState) error {
if err := data.Params.Validate(); err != nil {
return err
}
for _, record := range data.RegisteredWrkchains {
if record.Wrkchain.WrkchainId == 0 {
return fmt.Errorf("invalid WrkChain: ID: %d. Error: Missing ID", record.Wrkchain.WrkchainId)
}
if record.Wrkchain.Owner == "" {
return fmt.Errorf("invalid WrkChain: Owner: %s. Error: Missing Owner", record.Wrkchain.Owner)
}
if record.Wrkchain.Moniker == "" {
return fmt.Errorf("invalid WrkChain: Moniker: %s. Error: Missing Moniker", record.Wrkchain.Moniker)
}
if record.Wrkchain.Type == "" {
return fmt.Errorf("invalid WrkChain: BaseType: %s. Error: Missing BaseType", record.Wrkchain.Type)
}
if record.InStateLimit == 0 {
return fmt.Errorf("invalid WrkChain: InStateLimit: %d. Error: Missing InStateLimit", record.InStateLimit)
}
for _, block := range record.Blocks {
if block.Bh == "" {
return fmt.Errorf("invalid WrkChain block: BlockHash: %s. Error: Missing BlockHash", block.Bh)
}
if block.He == 0 {
return fmt.Errorf("invalid WrkChain block: Height: %d. Error: Missing Height", block.He)
}
}
}
return nil
}