Skip to content

Commit

Permalink
add orderBy parameter to TxsByEvents (bp #8815) (#8883)
Browse files Browse the repository at this point in the history
Closes: #8686

(cherry picked from commit 553aac5)

Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
Co-authored-by: MD Aleem <72057206+aleem1314@users.noreply.github.com>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Jonathan Gimeno <jgimeno@gmail.com>
Co-authored-by: aleem1314 <aleem@vitwit.com>
  • Loading branch information
6 people committed Mar 17, 2021
1 parent 51b163e commit 177672f
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 49 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ Ref: https://keepachangelog.com/en/1.0.0/

# Changelog

## [Unreleased]

### Improvements
* (grpc) [\#8815](https://github.com/cosmos/cosmos-sdk/pull/8815) Add orderBy parameter to `TxsByEvents` endpoint.

## [v0.42.1](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.42.1) - 2021-03-10

This release fixes security vulnerability identified in the simapp.
Expand Down
20 changes: 20 additions & 0 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@
- [SimulateResponse](#cosmos.tx.v1beta1.SimulateResponse)

- [BroadcastMode](#cosmos.tx.v1beta1.BroadcastMode)
- [OrderBy](#cosmos.tx.v1beta1.OrderBy)

- [Service](#cosmos.tx.v1beta1.Service)

Expand Down Expand Up @@ -9490,6 +9491,11 @@ GenesisState defines the ibc module's genesis state.

<!-- end services -->

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `events` | [string](#string) | repeated | events is the list of transaction event type. |
| `pagination` | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | pagination defines an pagination for the request. |
| `order_by` | [OrderBy](#cosmos.tx.v1beta1.OrderBy) | | |


<a name="ibc/lightclients/localhost/v1/localhost.proto"></a>
Expand Down Expand Up @@ -9565,6 +9571,20 @@ state and if the client is frozen.



<a name="cosmos.tx.v1beta1.OrderBy"></a>

### OrderBy
OrderBy defines the sorting order

| Name | Number | Description |
| ---- | ------ | ----------- |
| ORDER_BY_UNSPECIFIED | 0 | ORDER_BY_UNSPECIFIED specifies an unknown sorting order. OrderBy defaults to ASC in this case. |
| ORDER_BY_ASC | 1 | ORDER_BY_ASC defines ascending order |
| ORDER_BY_DESC | 2 | ORDER_BY_DESC defines descending order |


<!-- end enums -->




Expand Down
12 changes: 12 additions & 0 deletions proto/cosmos/tx/v1beta1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "cosmos/tx/v1beta1/tx.proto";
import "gogoproto/gogo.proto";
import "cosmos/base/query/v1beta1/pagination.proto";

option (gogoproto.goproto_registration) = true;
option go_package = "github.com/cosmos/cosmos-sdk/types/tx";

// Service defines a gRPC service for interacting with transactions.
Expand Down Expand Up @@ -42,6 +43,17 @@ message GetTxsEventRequest {
repeated string events = 1;
// pagination defines an pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
OrderBy order_by = 3;
}

// OrderBy defines the sorting order
enum OrderBy {
// ORDER_BY_UNSPECIFIED specifies an unknown sorting order. OrderBy defaults to ASC in this case.
ORDER_BY_UNSPECIFIED = 0;
// ORDER_BY_ASC defines ascending order
ORDER_BY_ASC = 1;
// ORDER_BY_DESC defines descending order
ORDER_BY_DESC = 2;
}

// GetTxsEventResponse is the response type for the Service.TxsByEvents
Expand Down
184 changes: 136 additions & 48 deletions types/tx/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion x/auth/tx/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (s txServer) GetTxsEvent(ctx context.Context, req *txtypes.GetTxsEventReque
if err != nil {
return nil, err
}
orderBy := parseOrderBy(req.OrderBy)

if len(req.Events) == 0 {
return nil, status.Error(codes.InvalidArgument, "must declare at least one event to search")
Expand All @@ -63,7 +64,7 @@ func (s txServer) GetTxsEvent(ctx context.Context, req *txtypes.GetTxsEventReque
}
}

result, err := queryTxsByEvents(ctx, s.clientCtx, req.Events, page, limit, "")
result, err := queryTxsByEvents(ctx, s.clientCtx, req.Events, page, limit, orderBy)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -161,3 +162,14 @@ func RegisterTxService(
func RegisterGRPCGatewayRoutes(clientConn gogogrpc.ClientConn, mux *runtime.ServeMux) {
txtypes.RegisterServiceHandlerClient(context.Background(), mux, txtypes.NewServiceClient(clientConn))
}

func parseOrderBy(orderBy txtypes.OrderBy) string {
switch orderBy {
case txtypes.OrderBy_ORDER_BY_ASC:
return "asc"
case txtypes.OrderBy_ORDER_BY_DESC:
return "desc"
default:
return "" // Defaults to Tendermint's default, which is `asc` now.
}
}
Loading

0 comments on commit 177672f

Please sign in to comment.