* x/capability: simulations * update logs * validate genesis state * InitGenesis and ExportGenesis functions * update validation func * fix import-export sim * remove nondeterminism from capability genesis * Update x/capability/types/genesis.go * Update x/capability/types/genesis.go * fix tests * fix merge * consistency updates * try fix nondeterminism * fix conditional * Fix random index logic * lint * lint Co-authored-by: Aditya Sripal <adityasripal@gmail.com> Co-authored-by: Aleksandr Bezobchuk <aleks.bezobchuk@gmail.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
42 lines
1006 B
Go
42 lines
1006 B
Go
package capability
|
|
|
|
import (
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
// InitGenesis initializes the capability module's state from a provided genesis
|
|
// state.
|
|
func InitGenesis(ctx sdk.Context, k Keeper, genState GenesisState) {
|
|
k.SetIndex(ctx, genState.Index)
|
|
|
|
// set owners for each index and initialize capability
|
|
for _, genOwner := range genState.Owners {
|
|
k.SetOwners(ctx, genOwner.Index, genOwner.Owners)
|
|
k.InitializeCapability(ctx, genOwner.Index, genOwner.Owners)
|
|
}
|
|
}
|
|
|
|
// ExportGenesis returns the capability module's exported genesis.
|
|
func ExportGenesis(ctx sdk.Context, k Keeper) GenesisState {
|
|
index := k.GetLatestIndex(ctx)
|
|
owners := []GenesisOwners{}
|
|
|
|
for i := uint64(1); i < index; i++ {
|
|
capabilityOwners, ok := k.GetOwners(ctx, i)
|
|
if !ok || len(capabilityOwners.Owners) == 0 {
|
|
continue
|
|
}
|
|
|
|
genOwner := GenesisOwners{
|
|
Index: i,
|
|
Owners: capabilityOwners,
|
|
}
|
|
owners = append(owners, genOwner)
|
|
}
|
|
|
|
return GenesisState{
|
|
Index: index,
|
|
Owners: owners,
|
|
}
|
|
}
|