Setup keeper files

This commit is contained in:
Prathamesh Musale 2024-02-09 12:04:44 +05:30
parent 6a2c489cd3
commit 19e3cec976
4 changed files with 129 additions and 0 deletions

View File

@ -0,0 +1,41 @@
package keeper
import (
"context"
"git.vdb.to/cerc-io/laconic2d/x/auction"
)
// InitGenesis initializes the module state from a genesis state.
func (k *Keeper) InitGenesis(ctx context.Context, data *auction.GenesisState) error {
if err := k.Params.Set(ctx, data.Params); err != nil {
return err
}
// Save auctions in store.
// for _, auction := range data.Auctions {
// if err := k.Auctions.Set(ctx, auction.Id, *auction); err != nil {
// return err
// }
// }
return nil
}
// ExportGenesis exports the module state to a genesis state.
func (k *Keeper) ExportGenesis(ctx context.Context) (*auction.GenesisState, error) {
params, err := k.Params.Get(ctx)
if err != nil {
return nil, err
}
// auctions, err := k.ListAuctions(ctx)
// if err != nil {
// return nil, err
// }
return &auction.GenesisState{
Params: params,
// Auctions: auctions,
}, nil
}

View File

@ -0,0 +1,60 @@
package keeper
import (
"cosmossdk.io/collections"
storetypes "cosmossdk.io/core/store"
"github.com/cosmos/cosmos-sdk/codec"
auth "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bank "github.com/cosmos/cosmos-sdk/x/bank/keeper"
auctiontypes "git.vdb.to/cerc-io/laconic2d/x/auction"
)
type Keeper struct {
// Codecs
cdc codec.BinaryCodec
// External keepers
accountKeeper auth.AccountKeeper
bankKeeper bank.Keeper
// Track auction usage in other cosmos-sdk modules (more like a usage tracker).
// usageKeepers []types.AuctionUsageKeeper
// state management
Schema collections.Schema
Params collections.Item[auctiontypes.Params]
// TODO
// Auctions ...
}
// NewKeeper creates a new Keeper instance
func NewKeeper(
cdc codec.BinaryCodec,
storeService storetypes.KVStoreService,
accountKeeper auth.AccountKeeper,
bankKeeper bank.Keeper,
) Keeper {
sb := collections.NewSchemaBuilder(storeService)
k := Keeper{
cdc: cdc,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
Params: collections.NewItem(sb, auctiontypes.ParamsKeyPrefix, "params", codec.CollValue[auctiontypes.Params](cdc)),
// Auctions: ...
}
schema, err := sb.Build()
if err != nil {
panic(err)
}
k.Schema = schema
return k
}
// func (k *Keeper) SetUsageKeepers(usageKeepers []types.AuctionUsageKeeper) {
// k.usageKeepers = usageKeepers
// }

View File

@ -0,0 +1,14 @@
package keeper
// TODO: Add required read methods
// var _ auctiontypes.MsgServer = msgServer{}
type msgServer struct {
k Keeper
}
// NewMsgServerImpl returns an implementation of the module MsgServer interface.
// func NewMsgServerImpl(keeper Keeper) auctiontypes.MsgServer {
// return &msgServer{k: keeper}
// }

View File

@ -0,0 +1,14 @@
package keeper
// TODO: Add required read methods
// var _ auctiontypes.QueryServer = queryServer{}
type queryServer struct {
k Keeper
}
// NewQueryServerImpl returns an implementation of the module QueryServer.
// func NewQueryServerImpl(k Keeper) auctiontypes.QueryServer {
// return queryServer{k}
// }