Add registry module commands to set and get records #5
@ -77,6 +77,11 @@ func NewKeeper(
|
|||||||
sb := collections.NewSchemaBuilder(storeService)
|
sb := collections.NewSchemaBuilder(storeService)
|
||||||
k := Keeper{
|
k := Keeper{
|
||||||
cdc: cdc,
|
cdc: cdc,
|
||||||
|
accountKeeper: accountKeeper,
|
||||||
|
bankKeeper: bankKeeper,
|
||||||
|
recordKeeper: recordKeeper,
|
||||||
|
bondKeeper: bondKeeper,
|
||||||
|
auctionKeeper: auctionKeeper,
|
||||||
Params: collections.NewItem(sb, registrytypes.ParamsPrefix, "params", codec.CollValue[registrytypes.Params](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)),
|
Records: collections.NewIndexedMap(sb, registrytypes.RecordsPrefix, "records", collections.StringKey, codec.CollValue[registrytypes.Record](cdc), newRecordIndexes(sb)),
|
||||||
}
|
}
|
||||||
@ -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.
|
||||||
|
@ -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 ®istrytypes.QueryRecordByIdResponse{Record: record}, nil
|
return ®istrytypes.QueryRecordByIdResponse{Record: record}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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{
|
||||||
|
Loading…
Reference in New Issue
Block a user