2020-04-30 08:07:43 -07:00
|
|
|
package capability
|
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-06-14 10:05:45 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/capability/keeper"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/capability/types"
|
2020-04-30 08:07:43 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// InitGenesis initializes the capability module's state from a provided genesis
|
|
|
|
// state.
|
2020-06-14 10:05:45 -07:00
|
|
|
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
|
2020-04-30 08:07:43 -07:00
|
|
|
k.SetIndex(ctx, genState.Index)
|
|
|
|
|
|
|
|
// set owners for each index and initialize capability
|
|
|
|
for _, genOwner := range genState.Owners {
|
2020-08-12 08:48:22 -07:00
|
|
|
k.SetOwners(ctx, genOwner.Index, genOwner.IndexOwners)
|
|
|
|
k.InitializeCapability(ctx, genOwner.Index, genOwner.IndexOwners)
|
2020-04-30 08:07:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExportGenesis returns the capability module's exported genesis.
|
2020-08-11 07:22:30 -07:00
|
|
|
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
|
2020-04-30 08:07:43 -07:00
|
|
|
index := k.GetLatestIndex(ctx)
|
2020-06-14 10:05:45 -07:00
|
|
|
owners := []types.GenesisOwners{}
|
2020-04-30 08:07:43 -07:00
|
|
|
|
|
|
|
for i := uint64(1); i < index; i++ {
|
|
|
|
capabilityOwners, ok := k.GetOwners(ctx, i)
|
|
|
|
if !ok || len(capabilityOwners.Owners) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-06-14 10:05:45 -07:00
|
|
|
genOwner := types.GenesisOwners{
|
2020-08-12 08:48:22 -07:00
|
|
|
Index: i,
|
|
|
|
IndexOwners: capabilityOwners,
|
2020-04-30 08:07:43 -07:00
|
|
|
}
|
|
|
|
owners = append(owners, genOwner)
|
|
|
|
}
|
|
|
|
|
2020-08-11 07:22:30 -07:00
|
|
|
return &types.GenesisState{
|
2020-04-30 08:07:43 -07:00
|
|
|
Index: index,
|
|
|
|
Owners: owners,
|
|
|
|
}
|
|
|
|
}
|