2018-10-19 11:36:00 -07:00
|
|
|
package mint
|
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
2019-03-28 16:27:47 -07:00
|
|
|
// GenesisState - minter state
|
2018-10-19 11:36:00 -07:00
|
|
|
type GenesisState struct {
|
2019-07-05 16:25:56 -07:00
|
|
|
Minter Minter `json:"minter" yaml:"minter"` // minter object
|
|
|
|
Params Params `json:"params" yaml:"params"` // inflation params
|
2018-10-19 11:36:00 -07:00
|
|
|
}
|
|
|
|
|
2019-03-28 16:27:47 -07:00
|
|
|
// NewGenesisState creates a new GenesisState object
|
2018-10-19 11:36:00 -07:00
|
|
|
func NewGenesisState(minter Minter, params Params) GenesisState {
|
|
|
|
return GenesisState{
|
|
|
|
Minter: minter,
|
|
|
|
Params: params,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-28 16:27:47 -07:00
|
|
|
// DefaultGenesisState creates a default GenesisState object
|
2018-10-19 11:36:00 -07:00
|
|
|
func DefaultGenesisState() GenesisState {
|
|
|
|
return GenesisState{
|
2018-11-26 04:13:47 -08:00
|
|
|
Minter: DefaultInitialMinter(),
|
2018-10-19 11:36:00 -07:00
|
|
|
Params: DefaultParams(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-28 13:11:27 -07:00
|
|
|
// InitGenesis new mint genesis
|
2018-10-19 11:36:00 -07:00
|
|
|
func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState) {
|
|
|
|
keeper.SetMinter(ctx, data.Minter)
|
2019-04-05 13:20:58 -07:00
|
|
|
keeper.SetParams(ctx, data.Params)
|
2018-10-19 11:36:00 -07:00
|
|
|
}
|
|
|
|
|
2019-04-05 13:20:58 -07:00
|
|
|
// ExportGenesis returns a GenesisState for a given context and keeper.
|
|
|
|
func ExportGenesis(ctx sdk.Context, keeper Keeper) GenesisState {
|
|
|
|
minter := keeper.GetMinter(ctx)
|
|
|
|
params := keeper.GetParams(ctx)
|
|
|
|
return NewGenesisState(minter, params)
|
2018-10-19 11:36:00 -07:00
|
|
|
}
|
|
|
|
|
2019-03-28 16:27:47 -07:00
|
|
|
// ValidateGenesis validates the provided genesis state to ensure the
|
|
|
|
// expected invariants holds.
|
2018-10-19 11:36:00 -07:00
|
|
|
func ValidateGenesis(data GenesisState) error {
|
2019-06-05 16:26:17 -07:00
|
|
|
err := ValidateParams(data.Params)
|
2018-10-19 11:36:00 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-06-08 09:17:21 -07:00
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
err = ValidateMinter(data.Minter)
|
2018-10-19 11:36:00 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-06-08 09:17:21 -07:00
|
|
|
|
2018-10-19 11:36:00 -07:00
|
|
|
return nil
|
|
|
|
}
|