Setup registry module keeper files

This commit is contained in:
Prathamesh Musale 2024-02-14 17:38:29 +05:30
parent 475abc1a4c
commit cf93a3558d
6 changed files with 183 additions and 1 deletions

View File

@ -1,8 +1,9 @@
package keeper package keeper
import ( import (
"git.vdb.to/cerc-io/laconic2d/x/auction"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"git.vdb.to/cerc-io/laconic2d/x/auction"
) )
// InitGenesis initializes the module state from a genesis state. // InitGenesis initializes the module state from a genesis state.

View File

@ -0,0 +1,80 @@
package keeper
import (
"context"
"git.vdb.to/cerc-io/laconic2d/x/registry"
)
// InitGenesis initializes the module state from a genesis state.
func (k *Keeper) InitGenesis(ctx context.Context, data *registry.GenesisState) error {
if err := k.Params.Set(ctx, data.Params); err != nil {
return err
}
// for _, record := range data.Records {
// keeper.PutRecord(ctx, record)
// // Add to record expiry queue if expiry time is in the future.
// expiryTime, err := time.Parse(time.RFC3339, record.ExpiryTime)
// if err != nil {
// panic(err)
// }
// if expiryTime.After(ctx.BlockTime()) {
// keeper.InsertRecordExpiryQueue(ctx, record)
// }
// // Note: Bond genesis runs first, so bonds will already be present.
// if record.BondId != "" {
// keeper.AddBondToRecordIndexEntry(ctx, record.BondId, record.Id)
// }
// }
// for _, authority := range data.Authorities {
// // Only import authorities that are marked active.
// if authority.Entry.Status == types.AuthorityActive {
// keeper.SetNameAuthority(ctx, authority.Name, authority.Entry)
// // Add authority name to expiry queue.
// keeper.InsertAuthorityExpiryQueue(ctx, authority.Name, authority.Entry.ExpiryTime)
// // Note: Bond genesis runs first, so bonds will already be present.
// if authority.Entry.BondId != "" {
// keeper.AddBondToAuthorityIndexEntry(ctx, authority.Entry.BondId, authority.Name)
// }
// }
// }
// for _, nameEntry := range data.Names {
// keeper.SetNameRecord(ctx, nameEntry.Name, nameEntry.Entry.Latest.Id)
// }
return nil
}
// ExportGenesis exports the module state to a genesis state.
func (k *Keeper) ExportGenesis(ctx context.Context) (*registry.GenesisState, error) {
params, err := k.Params.Get(ctx)
if err != nil {
return nil, err
}
// records := keeper.ListRecords(ctx)
// authorities := keeper.ListNameAuthorityRecords(ctx)
// authorityEntries := []types.AuthorityEntry{}
// // #nosec G705
// for name, record := range authorities {
// authorityEntries = append(authorityEntries, types.AuthorityEntry{
// Name: name,
// Entry: &record, //nolint: all
// }) // #nosec G601
// }
// names := keeper.ListNameRecords(ctx)
return &registry.GenesisState{
Params: params,
}, nil
}

View File

@ -0,0 +1,55 @@
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"
auctionkeeper "git.vdb.to/cerc-io/laconic2d/x/auction/keeper"
bondkeeper "git.vdb.to/cerc-io/laconic2d/x/bond/keeper"
registrytypes "git.vdb.to/cerc-io/laconic2d/x/registry"
)
// TODO: Add required methods
type Keeper struct {
cdc codec.BinaryCodec
accountKeeper auth.AccountKeeper
bankKeeper bank.Keeper
recordKeeper RecordKeeper
bondKeeper bondkeeper.Keeper
auctionKeeper auctionkeeper.Keeper
// state management
Schema collections.Schema
Params collections.Item[registrytypes.Params]
}
// NewKeeper creates a new Keeper instance
func NewKeeper(
cdc codec.BinaryCodec,
storeService storetypes.KVStoreService,
accountKeeper auth.AccountKeeper,
bankKeeper bank.Keeper,
recordKeeper RecordKeeper,
bondKeeper bondkeeper.Keeper,
auctionKeeper auctionkeeper.Keeper,
) Keeper {
sb := collections.NewSchemaBuilder(storeService)
k := Keeper{
cdc: cdc,
Params: collections.NewItem(sb, registrytypes.ParamsPrefix, "params", codec.CollValue[registrytypes.Params](cdc)),
}
schema, err := sb.Build()
if err != nil {
panic(err)
}
k.Schema = schema
return k
}

View File

@ -0,0 +1,14 @@
package keeper
// import "git.vdb.to/cerc-io/laconic2d/x/registry"
// var _ registry.MsgServer = msgServer{}
type msgServer struct {
k Keeper
}
// // NewMsgServerImpl returns an implementation of the module MsgServer interface.
// func NewMsgServerImpl(keeper Keeper) registry.MsgServer {
// return &msgServer{k: keeper}
// }

View File

@ -0,0 +1,16 @@
package keeper
// import (
// registrytypes "git.vdb.to/cerc-io/laconic2d/x/registry"
// )
// var _ registrytypes.QueryServer = queryServer{}
type queryServer struct {
k Keeper
}
// // NewQueryServerImpl returns an implementation of the module QueryServer.
// func NewQueryServerImpl(k Keeper) registrytypes.QueryServer {
// return queryServer{k}
// }

View File

@ -0,0 +1,16 @@
package keeper
import (
"github.com/cosmos/cosmos-sdk/codec"
auctionkeeper "git.vdb.to/cerc-io/laconic2d/x/auction/keeper"
)
// TODO: Add methods
// RecordKeeper exposes the bare minimal read-only API for other modules.
type RecordKeeper struct {
cdc codec.BinaryCodec // The wire codec for binary encoding/decoding.
auctionKeeper auctionkeeper.Keeper
// storeKey storetypes.StoreKey // Unexposed key to access store from sdk.Context
}