0g-chain/app/genesis.go

35 lines
1.1 KiB
Go
Raw Normal View History

2019-06-20 13:37:57 +00:00
package app
import (
"encoding/json"
2019-09-13 20:52:10 +00:00
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/exported"
2019-06-20 13:37:57 +00:00
)
2019-07-19 14:06:33 +00:00
// GenesisState represents the genesis state of the blockchain. It is a map from module names to module genesis states.
2019-07-18 17:36:31 +00:00
type GenesisState map[string]json.RawMessage
2019-06-20 13:37:57 +00:00
2019-07-18 17:36:31 +00:00
// NewDefaultGenesisState generates the default state for the application.
2019-06-20 13:37:57 +00:00
func NewDefaultGenesisState() GenesisState {
2019-07-18 17:36:31 +00:00
return ModuleBasics.DefaultGenesis()
2019-06-20 13:37:57 +00:00
}
2019-09-13 20:52:10 +00:00
// TODO remove iterator once merged into sdk master
type GenesisAccountIterator struct{}
// IterateGenesisAccounts iterates over all the genesis accounts found in
// appGenesis and invokes a callback on each genesis account. If any call
// returns true, iteration stops.
func (GenesisAccountIterator) IterateGenesisAccounts(
cdc *codec.Codec, appGenesis map[string]json.RawMessage, cb func(exported.Account) (stop bool),
) {
var authGenState auth.GenesisState
cdc.MustUnmarshalJSON(appGenesis[auth.ModuleName], &authGenState)
for _, genAcc := range authGenState.Accounts {
if cb(genAcc) {
break
}
}
}