Add a command to get records by bond id
This commit is contained in:
parent
5e68c7d9b3
commit
91a8b56183
@ -106,16 +106,6 @@ func (k Keeper) HasRecord(ctx sdk.Context, id string) (bool, error) {
|
|||||||
return has, nil
|
return has, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRecord - gets a record from the store.
|
|
||||||
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.
|
// ListRecords - get all records.
|
||||||
func (k Keeper) ListRecords(ctx sdk.Context) ([]registrytypes.Record, error) {
|
func (k Keeper) ListRecords(ctx sdk.Context) ([]registrytypes.Record, error) {
|
||||||
iter, err := k.Records.Iterate(ctx, nil)
|
iter, err := k.Records.Iterate(ctx, nil)
|
||||||
@ -129,6 +119,26 @@ func (k Keeper) ListRecords(ctx sdk.Context) ([]registrytypes.Record, error) {
|
|||||||
return iter.Values()
|
return iter.Values()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRecordById - gets a record from the store.
|
||||||
|
func (k Keeper) GetRecordById(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
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRecordsByBondId - gets a record from the store.
|
||||||
|
func (k Keeper) GetRecordsByBondId(ctx sdk.Context, bondId string) ([]registrytypes.Record, error) {
|
||||||
|
iter, err := k.Records.Indexes.BondId.MatchExact(ctx, bondId)
|
||||||
|
if err != nil {
|
||||||
|
return []registrytypes.Record{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return indexes.CollectValues(ctx, k.Records, iter)
|
||||||
|
}
|
||||||
|
|
||||||
// RecordsFromAttributes gets a list of records whose attributes match all provided values
|
// RecordsFromAttributes gets a list of records whose attributes match all provided values
|
||||||
func (k Keeper) RecordsFromAttributes(ctx sdk.Context, attributes []*registrytypes.QueryRecordsRequest_KeyValueInput, all bool) ([]registrytypes.Record, error) {
|
func (k Keeper) RecordsFromAttributes(ctx sdk.Context, attributes []*registrytypes.QueryRecordsRequest_KeyValueInput, all bool) ([]registrytypes.Record, error) {
|
||||||
panic("unimplemented")
|
panic("unimplemented")
|
||||||
|
@ -67,7 +67,7 @@ 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, err := qs.k.GetRecord(ctx, id)
|
record, err := qs.k.GetRecordById(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -77,7 +77,12 @@ func (qs queryServer) GetRecord(c context.Context, req *registrytypes.QueryRecor
|
|||||||
|
|
||||||
func (qs queryServer) GetRecordsByBondId(c context.Context, req *registrytypes.QueryRecordsByBondIdRequest) (*registrytypes.QueryRecordsByBondIdResponse, error) {
|
func (qs queryServer) GetRecordsByBondId(c context.Context, req *registrytypes.QueryRecordsByBondIdRequest) (*registrytypes.QueryRecordsByBondIdResponse, error) {
|
||||||
ctx := sdk.UnwrapSDKContext(c)
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
records := qs.k.recordKeeper.QueryRecordsByBond(ctx, req.GetId())
|
|
||||||
|
records, err := qs.k.GetRecordsByBondId(ctx, req.GetId())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return ®istrytypes.QueryRecordsByBondIdResponse{Records: records}, nil
|
return ®istrytypes.QueryRecordsByBondIdResponse{Records: records}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,11 +17,6 @@ type RecordKeeper struct {
|
|||||||
// storeKey storetypes.StoreKey // Unexposed key to access store from sdk.Context
|
// storeKey storetypes.StoreKey // Unexposed key to access store from sdk.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryRecordsByBond - get all records for the given bond.
|
|
||||||
func (k RecordKeeper) QueryRecordsByBond(ctx sdk.Context, bondID string) []registrytypes.Record {
|
|
||||||
panic("unimplemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
// ProcessRenewRecord renews a record.
|
// ProcessRenewRecord renews a record.
|
||||||
func (k Keeper) ProcessRenewRecord(ctx sdk.Context, msg registrytypes.MsgRenewRecord) error {
|
func (k Keeper) ProcessRenewRecord(ctx sdk.Context, msg registrytypes.MsgRenewRecord) error {
|
||||||
panic("unimplemented")
|
panic("unimplemented")
|
||||||
|
@ -35,6 +35,14 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
|
|||||||
{ProtoField: "id"},
|
{ProtoField: "id"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
RpcMethod: "GetRecordsByBondId",
|
||||||
|
Use: "get-records-by-bond-id [bond-id]",
|
||||||
|
Short: "Get records by bond id",
|
||||||
|
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||||
|
{ProtoField: "id"},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Tx: &autocliv1.ServiceCommandDescriptor{
|
Tx: &autocliv1.ServiceCommandDescriptor{
|
||||||
|
Loading…
Reference in New Issue
Block a user