Add a command to get a record by id

This commit is contained in:
Prathamesh Musale 2024-02-16 11:16:51 +05:30
parent 3d478568ac
commit 28c4dc81fd
3 changed files with 28 additions and 6 deletions

View File

@ -76,9 +76,14 @@ func NewKeeper(
) Keeper { ) Keeper {
sb := collections.NewSchemaBuilder(storeService) sb := collections.NewSchemaBuilder(storeService)
k := Keeper{ k := Keeper{
cdc: cdc, cdc: cdc,
Params: collections.NewItem(sb, registrytypes.ParamsPrefix, "params", codec.CollValue[registrytypes.Params](cdc)), accountKeeper: accountKeeper,
Records: collections.NewIndexedMap(sb, registrytypes.RecordsPrefix, "records", collections.StringKey, codec.CollValue[registrytypes.Record](cdc), newRecordIndexes(sb)), 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() 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. // GetRecord - gets a record from the store.
func (k Keeper) GetRecord(ctx sdk.Context, id string) (record registrytypes.Record) { func (k Keeper) GetRecord(ctx sdk.Context, id string) (registrytypes.Record, error) {
panic("unimplemented") record, err := k.Records.Get(ctx, id)
if err != nil {
return registrytypes.Record{}, err
}
return record, nil
} }
// ListRecords - get all records. // 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.") 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 return &registrytypes.QueryRecordByIdResponse{Record: record}, nil
} }

View File

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