diff --git a/x/auction/keeper/genesis.go b/x/auction/keeper/genesis.go new file mode 100644 index 00000000..fd1374ac --- /dev/null +++ b/x/auction/keeper/genesis.go @@ -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 +} diff --git a/x/auction/keeper/keeper.go b/x/auction/keeper/keeper.go new file mode 100644 index 00000000..6f993faf --- /dev/null +++ b/x/auction/keeper/keeper.go @@ -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 +// } diff --git a/x/auction/keeper/msg_server.go b/x/auction/keeper/msg_server.go new file mode 100644 index 00000000..c823d585 --- /dev/null +++ b/x/auction/keeper/msg_server.go @@ -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} +// } diff --git a/x/auction/keeper/query_server.go b/x/auction/keeper/query_server.go new file mode 100644 index 00000000..5c52f590 --- /dev/null +++ b/x/auction/keeper/query_server.go @@ -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} +// }