Add registry module commands to set and get records #5
@ -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.
|
||||
|
@ -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 ®istrytypes.QueryRecordByIdResponse{Record: record}, nil
|
||||
}
|
||||
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user