Add registry module commands to set and get records #5

Merged
ashwin merged 4 commits from pm-registry-commands into main 2024-02-16 06:40:44 +00:00
3 changed files with 28 additions and 6 deletions
Showing only changes of commit 28c4dc81fd - Show all commits

View File

@ -76,9 +76,14 @@ func NewKeeper(
) Keeper {
sb := collections.NewSchemaBuilder(storeService)
k := Keeper{
cdc: cdc,
Params: collections.NewItem(sb, registrytypes.ParamsPrefix, "params", codec.CollValue[registrytypes.Params](cdc)),
Records: collections.NewIndexedMap(sb, registrytypes.RecordsPrefix, "records", collections.StringKey, codec.CollValue[registrytypes.Record](cdc), newRecordIndexes(sb)),
cdc: cdc,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
recordKeeper: recordKeeper,
bondKeeper: bondKeeper,
auctionKeeper: auctionKeeper,
Params: collections.NewItem(sb, registrytypes.ParamsPrefix, "params", codec.CollValue[registrytypes.Params](cdc)),
Records: collections.NewIndexedMap(sb, registrytypes.RecordsPrefix, "records", collections.StringKey, codec.CollValue[registrytypes.Record](cdc), newRecordIndexes(sb)),
}
schema, err := sb.Build()
@ -102,8 +107,13 @@ func (k Keeper) HasRecord(ctx sdk.Context, id string) (bool, error) {
}
// GetRecord - gets a record from the store.
func (k Keeper) GetRecord(ctx sdk.Context, id string) (record registrytypes.Record) {
panic("unimplemented")
func (k Keeper) GetRecord(ctx sdk.Context, id string) (registrytypes.Record, error) {
record, err := k.Records.Get(ctx, id)
if err != nil {
return registrytypes.Record{}, err
}
return record, nil
}
// ListRecords - get all records.

View File

@ -67,7 +67,11 @@ func (qs queryServer) GetRecord(c context.Context, req *registrytypes.QueryRecor
return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "Record not found.")
}
record := qs.k.GetRecord(ctx, id)
record, err := qs.k.GetRecord(ctx, id)
if err != nil {
return nil, err
}
return &registrytypes.QueryRecordByIdResponse{Record: record}, nil
}

View File

@ -27,6 +27,14 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
Short: "List records",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{},
},
{
RpcMethod: "GetRecord",
Use: "get [record-id]",
Short: "Get record info by record id",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "id"},
},
},
},
},
Tx: &autocliv1.ServiceCommandDescriptor{