-
Notifications
You must be signed in to change notification settings - Fork 368
/
genesis.go
55 lines (46 loc) · 1.18 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
package types
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// NewGenesisState returns a new genesis state object for the module.
func NewGenesisState(accounts []Account) *GenesisState {
return &GenesisState{
Accounts: accounts,
}
}
// DefaultGenesisState returns the default genesis state for the module.
func DefaultGenesisState() *GenesisState {
return NewGenesisState(
[]Account{},
)
}
// Validate performs basic validation of genesis data.
func (gs GenesisState) Validate() error {
seenAccounts := make(map[string]bool)
for _, account := range gs.Accounts {
if seenAccounts[account.Address.String()] {
return fmt.Errorf("duplicate account for address %s", account.Address)
}
if err := account.Validate(); err != nil {
return err
}
seenAccounts[account.Address.String()] = true
}
return nil
}
func NewAccount(addr sdk.AccAddress, balance sdk.Int) *Account {
return &Account{
Address: addr,
Balance: balance,
}
}
func (b Account) Validate() error {
if b.Address.Empty() {
return fmt.Errorf("address cannot be empty")
}
if b.Balance.IsNegative() {
return fmt.Errorf("balance amount cannot be negative; amount: %d", b.Balance)
}
return nil
}