github.com/Finschia/finschia-sdk@v0.48.1/x/capability/genesis.go (about) 1 package capability 2 3 import ( 4 sdk "github.com/Finschia/finschia-sdk/types" 5 "github.com/Finschia/finschia-sdk/x/capability/keeper" 6 "github.com/Finschia/finschia-sdk/x/capability/types" 7 ) 8 9 // InitGenesis initializes the capability module's state from a provided genesis 10 // state. 11 func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { 12 if err := k.InitializeIndex(ctx, genState.Index); err != nil { 13 panic(err) 14 } 15 16 // set owners for each index 17 for _, genOwner := range genState.Owners { 18 k.SetOwners(ctx, genOwner.Index, genOwner.IndexOwners) 19 } 20 // initialize in-memory capabilities 21 k.InitMemStore(ctx) 22 } 23 24 // ExportGenesis returns the capability module's exported genesis. 25 func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { 26 index := k.GetLatestIndex(ctx) 27 owners := []types.GenesisOwners{} 28 29 for i := uint64(1); i < index; i++ { 30 capabilityOwners, ok := k.GetOwners(ctx, i) 31 if !ok || len(capabilityOwners.Owners) == 0 { 32 continue 33 } 34 35 genOwner := types.GenesisOwners{ 36 Index: i, 37 IndexOwners: capabilityOwners, 38 } 39 owners = append(owners, genOwner) 40 } 41 42 return &types.GenesisState{ 43 Index: index, 44 Owners: owners, 45 } 46 }