0g-chain/x/validator-vesting/genesis.go
Kevin Davis e21a04ca57
fix: set previous block time correctly on block one (#868)
* fix: set previous block time correctly on block one

* fix failing tests
2021-03-10 10:56:23 -07:00

31 lines
1021 B
Go

package validatorvesting
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/kava-labs/kava/x/validator-vesting/types"
)
// InitGenesis stores the account address of each ValidatorVestingAccount in the validator vesting keeper, for faster lookup.
// CONTRACT: Accounts must have already been initialized/created by AccountKeeper
func InitGenesis(ctx sdk.Context, keeper Keeper, accountKeeper types.AccountKeeper, data GenesisState) {
accounts := accountKeeper.GetAllAccounts(ctx)
for _, a := range accounts {
vv, ok := a.(*ValidatorVestingAccount)
if ok {
keeper.SetValidatorVestingAccountKey(ctx, vv.Address)
}
}
keeper.SetPreviousBlockTime(ctx, data.PreviousBlockTime)
}
// ExportGenesis returns empty genesis state because auth exports all the genesis state we need.
func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState {
prevBlockTime, found := keeper.GetPreviousBlockTime(ctx)
if !found {
prevBlockTime = ctx.BlockTime()
}
return NewGenesisState(prevBlockTime)
}