-
Notifications
You must be signed in to change notification settings - Fork 41
/
genesis.go
33 lines (27 loc) · 900 Bytes
/
genesis.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package resource
import (
"fmt"
"github.com/cheqd/cheqd-node/x/resource/keeper"
"github.com/cheqd/cheqd-node/x/resource/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// InitGenesis initializes the resource module's state from a provided genesis
// state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
for _, resource := range genState.ResourceList {
if err := k.SetResource(&ctx, resource); err != nil {
panic(fmt.Sprintf("Cannot set resource case: %s", err.Error()))
}
}
}
// ExportGenesis returns the cheqd module's exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
genesis := types.GenesisState{}
// Get all resource
resourceList := k.GetAllResources(&ctx)
for _, elem := range resourceList {
elem := elem
genesis.ResourceList = append(genesis.ResourceList, &elem)
}
return &genesis
}