corvidd/x/bond/keeper/genesis.go
prathamesh0 4da8dd8d7b
Additional bond commands (#4)
* Add commands to get bonds by id and owner

* Add commands to get bond module params and balances

* Add commands to refill, withdraw and cancel bond

* Add implementations for bond tx commands

* Use indexed map to implement command for getting bond by owner

* Use collections for bond module params

* Clean up
2024-02-08 18:53:20 +05:30

38 lines
831 B
Go

package keeper
import (
"git.vdb.to/cerc-io/laconic2d/x/bond"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// InitGenesis initializes the module state from a genesis state.
func (k *Keeper) InitGenesis(ctx sdk.Context, data *bond.GenesisState) error {
if err := k.Params.Set(ctx, data.Params); err != nil {
return err
}
// Save bonds in store.
for _, bond := range data.Bonds {
if err := k.Bonds.Set(ctx, bond.Id, *bond); err != nil {
return err
}
}
return nil
}
// ExportGenesis exports the module state to a genesis state.
func (k *Keeper) ExportGenesis(ctx sdk.Context) (*bond.GenesisState, error) {
params, err := k.Params.Get(ctx)
if err != nil {
return nil, err
}
bonds, err := k.ListBonds(ctx)
if err != nil {
return nil, err
}
return &bond.GenesisState{Params: params, Bonds: bonds}, nil
}