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 {
|
2018-10-19 14:01:23 -07:00
|
|
|
Minter Minter `json:"minter"` // minter object
|
2018-10-19 11:36:00 -07:00
|
|
|
Params Params `json:"params"` // inflation params
|
|
|
|
}
|
|
|
|
|
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(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// new mint genesis
|
|
|
|
func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState) {
|
|
|
|
keeper.SetMinter(ctx, data.Minter)
|
2019-04-04 00:10:56 -07:00
|
|
|
if err := keeper.SetParams(ctx, data.Params); err != nil {
|
|
|
|
// TODO: return error - needs rewrite interfaces
|
|
|
|
// and handle error on the caller side
|
|
|
|
// check PR #3782
|
|
|
|
}
|
2018-10-19 11:36:00 -07:00
|
|
|
}
|
|
|
|
|
2019-04-04 00:10:56 -07:00
|
|
|
// ExportGenesis returns a GenesisState for a given context and keeper. The
|
|
|
|
// GenesisState will contain the pool, and validator/delegator distribution info's
|
|
|
|
func ExportGenesis(ctx sdk.Context, keeper Keeper) (GenesisState, error) {
|
|
|
|
minter, err := keeper.GetMinter(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return GenesisState{}, err
|
|
|
|
}
|
|
|
|
params, err := keeper.GetParams(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return GenesisState{}, err
|
|
|
|
}
|
|
|
|
return NewGenesisState(minter, params), nil
|
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 {
|
|
|
|
err := validateParams(data.Params)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = validateMinter(data.Minter)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|