From adf5f625c1bc5fb1c763d5345c48c4d607be3405 Mon Sep 17 00:00:00 2001 From: MD Aleem <72057206+aleem1314@users.noreply.github.com> Date: Sat, 13 Mar 2021 00:17:10 +0530 Subject: [PATCH] add orderBy parameter to TxsByEvents (#8815) Co-authored-by: Alessio Treglia Co-authored-by: Jonathan Gimeno --- CHANGELOG.md | 1 + docs/core/proto-docs.md | 15 +++ proto/cosmos/tx/v1beta1/service.proto | 12 ++ types/tx/service.pb.go | 184 +++++++++++++++++++------- x/auth/tx/service.go | 14 +- x/auth/tx/service_test.go | 26 ++++ 6 files changed, 203 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f878eabadf4..24048f26493 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/auth) [\#8522](https://github.com/cosmos/cosmos-sdk/pull/8522) Allow to query all stored accounts * (x/ibc) [\#7949](https://github.com/cosmos/cosmos-sdk/issues/7949) Standardized channel `Acknowledgement` moved to its own file. Codec registration redundancy removed. * (crypto/types) [\#8600](https://github.com/cosmos/cosmos-sdk/pull/8600) `CompactBitArray`: optimize the `NumTrueBitsBefore` method and add an `Equal` method. +* (grpc) [\#8815](https://github.com/cosmos/cosmos-sdk/pull/8815) Add orderBy parameter to `TxsByEvents` endpoint. ### Bug Fixes diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 9e985a6a6a1..4d493b27c4a 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -515,6 +515,7 @@ - [SimulateResponse](#cosmos.tx.v1beta1.SimulateResponse) - [BroadcastMode](#cosmos.tx.v1beta1.BroadcastMode) + - [OrderBy](#cosmos.tx.v1beta1.OrderBy) - [Service](#cosmos.tx.v1beta1.Service) @@ -7221,6 +7222,7 @@ RPC method. | ----- | ---- | ----- | ----------- | | `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) | | | @@ -7293,6 +7295,19 @@ BroadcastMode specifies the broadcast mode for the TxService.Broadcast RPC metho | BROADCAST_MODE_ASYNC | 3 | BROADCAST_MODE_ASYNC defines a tx broadcasting mode where the client returns immediately. | + + + +### 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 | + + diff --git a/proto/cosmos/tx/v1beta1/service.proto b/proto/cosmos/tx/v1beta1/service.proto index 59df75bab12..25214c4374e 100644 --- a/proto/cosmos/tx/v1beta1/service.proto +++ b/proto/cosmos/tx/v1beta1/service.proto @@ -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. @@ -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 diff --git a/types/tx/service.pb.go b/types/tx/service.pb.go index f01a60fe52a..f0eabcaca9a 100644 --- a/types/tx/service.pb.go +++ b/types/tx/service.pb.go @@ -11,6 +11,7 @@ import ( _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" + golang_proto "github.com/golang/protobuf/proto" _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" @@ -22,6 +23,7 @@ import ( // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal +var _ = golang_proto.Marshal var _ = fmt.Errorf var _ = math.Inf @@ -31,6 +33,38 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// OrderBy defines the sorting order +type OrderBy int32 + +const ( + // ORDER_BY_UNSPECIFIED specifies an unknown sorting order. OrderBy defaults to ASC in this case. + OrderBy_ORDER_BY_UNSPECIFIED OrderBy = 0 + // ORDER_BY_ASC defines ascending order + OrderBy_ORDER_BY_ASC OrderBy = 1 + // ORDER_BY_DESC defines descending order + OrderBy_ORDER_BY_DESC OrderBy = 2 +) + +var OrderBy_name = map[int32]string{ + 0: "ORDER_BY_UNSPECIFIED", + 1: "ORDER_BY_ASC", + 2: "ORDER_BY_DESC", +} + +var OrderBy_value = map[string]int32{ + "ORDER_BY_UNSPECIFIED": 0, + "ORDER_BY_ASC": 1, + "ORDER_BY_DESC": 2, +} + +func (x OrderBy) String() string { + return proto.EnumName(OrderBy_name, int32(x)) +} + +func (OrderBy) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_e0b00a618705eca7, []int{0} +} + // BroadcastMode specifies the broadcast mode for the TxService.Broadcast RPC method. type BroadcastMode int32 @@ -67,7 +101,7 @@ func (x BroadcastMode) String() string { } func (BroadcastMode) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_e0b00a618705eca7, []int{0} + return fileDescriptor_e0b00a618705eca7, []int{1} } // GetTxsEventRequest is the request type for the Service.TxsByEvents @@ -77,6 +111,7 @@ type GetTxsEventRequest struct { Events []string `protobuf:"bytes,1,rep,name=events,proto3" json:"events,omitempty"` // pagination defines an pagination for the request. Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` + OrderBy OrderBy `protobuf:"varint,3,opt,name=order_by,json=orderBy,proto3,enum=cosmos.tx.v1beta1.OrderBy" json:"order_by,omitempty"` } func (m *GetTxsEventRequest) Reset() { *m = GetTxsEventRequest{} } @@ -126,6 +161,13 @@ func (m *GetTxsEventRequest) GetPagination() *query.PageRequest { return nil } +func (m *GetTxsEventRequest) GetOrderBy() OrderBy { + if m != nil { + return m.OrderBy + } + return OrderBy_ORDER_BY_UNSPECIFIED +} + // GetTxsEventResponse is the response type for the Service.TxsByEvents // RPC method. type GetTxsEventResponse struct { @@ -499,67 +541,86 @@ func (m *GetTxResponse) GetTxResponse() *types.TxResponse { } func init() { + proto.RegisterEnum("cosmos.tx.v1beta1.OrderBy", OrderBy_name, OrderBy_value) + golang_proto.RegisterEnum("cosmos.tx.v1beta1.OrderBy", OrderBy_name, OrderBy_value) proto.RegisterEnum("cosmos.tx.v1beta1.BroadcastMode", BroadcastMode_name, BroadcastMode_value) + golang_proto.RegisterEnum("cosmos.tx.v1beta1.BroadcastMode", BroadcastMode_name, BroadcastMode_value) proto.RegisterType((*GetTxsEventRequest)(nil), "cosmos.tx.v1beta1.GetTxsEventRequest") + golang_proto.RegisterType((*GetTxsEventRequest)(nil), "cosmos.tx.v1beta1.GetTxsEventRequest") proto.RegisterType((*GetTxsEventResponse)(nil), "cosmos.tx.v1beta1.GetTxsEventResponse") + golang_proto.RegisterType((*GetTxsEventResponse)(nil), "cosmos.tx.v1beta1.GetTxsEventResponse") proto.RegisterType((*BroadcastTxRequest)(nil), "cosmos.tx.v1beta1.BroadcastTxRequest") + golang_proto.RegisterType((*BroadcastTxRequest)(nil), "cosmos.tx.v1beta1.BroadcastTxRequest") proto.RegisterType((*BroadcastTxResponse)(nil), "cosmos.tx.v1beta1.BroadcastTxResponse") + golang_proto.RegisterType((*BroadcastTxResponse)(nil), "cosmos.tx.v1beta1.BroadcastTxResponse") proto.RegisterType((*SimulateRequest)(nil), "cosmos.tx.v1beta1.SimulateRequest") + golang_proto.RegisterType((*SimulateRequest)(nil), "cosmos.tx.v1beta1.SimulateRequest") proto.RegisterType((*SimulateResponse)(nil), "cosmos.tx.v1beta1.SimulateResponse") + golang_proto.RegisterType((*SimulateResponse)(nil), "cosmos.tx.v1beta1.SimulateResponse") proto.RegisterType((*GetTxRequest)(nil), "cosmos.tx.v1beta1.GetTxRequest") + golang_proto.RegisterType((*GetTxRequest)(nil), "cosmos.tx.v1beta1.GetTxRequest") proto.RegisterType((*GetTxResponse)(nil), "cosmos.tx.v1beta1.GetTxResponse") + golang_proto.RegisterType((*GetTxResponse)(nil), "cosmos.tx.v1beta1.GetTxResponse") } func init() { proto.RegisterFile("cosmos/tx/v1beta1/service.proto", fileDescriptor_e0b00a618705eca7) } +func init() { + golang_proto.RegisterFile("cosmos/tx/v1beta1/service.proto", fileDescriptor_e0b00a618705eca7) +} var fileDescriptor_e0b00a618705eca7 = []byte{ - // 737 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xcd, 0x4f, 0x13, 0x41, - 0x14, 0xef, 0xb6, 0xc8, 0xc7, 0x2b, 0x68, 0x1d, 0x10, 0x6b, 0xd1, 0xa5, 0x2c, 0x16, 0x08, 0x89, - 0xbb, 0xa1, 0x7a, 0x20, 0xc6, 0xc4, 0xd0, 0x52, 0x08, 0x51, 0x3e, 0xb2, 0xc5, 0x83, 0xc6, 0xa4, - 0x99, 0xb6, 0xc3, 0xb2, 0x91, 0xee, 0x94, 0xce, 0x94, 0x2c, 0x01, 0x62, 0xe2, 0xd1, 0x93, 0x89, - 0xff, 0x94, 0x47, 0x12, 0x2f, 0x1e, 0x0d, 0xf8, 0x47, 0x78, 0x34, 0x3b, 0x3b, 0x6d, 0xb7, 0x65, - 0x0b, 0xc4, 0x13, 0x33, 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, 0xe8, 0x57, 0xfa, 0xa9, 0xef, - 0xba, 0xa6, 0x87, 0x40, 0xeb, 0x30, 0xca, 0xdd, 0x52, 0x43, 0xd6, 0xb1, 0x64, 0x54, 0x54, 0x3c, - 0xed, 0xb2, 0x22, 0x7a, 0x18, 0x28, 0x94, 0x60, 0x33, 0xce, 0xdb, 0x6b, 0x8f, 0x28, 0x98, 0x28, - 0x26, 0x12, 0xcd, 0xdf, 0x98, 0x48, 0x32, 0x05, 0x23, 0x11, 0x40, 0xb9, 0x06, 0xc5, 0xd5, 0x0a, - 0x66, 0xdc, 0x13, 0xf3, 0x1b, 0xf9, 0x08, 0x86, 0xb9, 0x5b, 0x2a, 0x1f, 0x73, 0xe2, 0xa5, 0x52, - 0x16, 0x46, 0xcd, 0x21, 0xee, 0xe6, 0xbc, 0x2d, 0x7a, 0x01, 0x03, 0x35, 0x5a, 0x25, 0xa2, 0x8b, - 0x77, 0xb3, 0xe9, 0x90, 0xb0, 0x6d, 0xbe, 0x4d, 0x5a, 0x25, 0xa6, 0x40, 0x6b, 0x1f, 0x61, 0xbc, - 0x4b, 0x46, 0x36, 0xae, 0x00, 0xf1, 0x40, 0x3f, 0x84, 0xd4, 0x6d, 0xdb, 0x01, 0x9d, 0x76, 0x68, - 0xcb, 0x70, 0xaf, 0x68, 0xd7, 0x9a, 0x07, 0x98, 0xb7, 0xc6, 0x86, 0x32, 0x10, 0xe5, 0xae, 0x24, - 0xec, 0x33, 0x91, 0x28, 0x77, 0xb5, 0xaf, 0x0a, 0x24, 0x3a, 0xa5, 0xd2, 0xd5, 0x2b, 0x18, 0xb6, - 0x30, 0x2b, 0xd9, 0xce, 0x1e, 0x95, 0x0c, 0x33, 0xfd, 0x2d, 0xad, 0x63, 0xb6, 0xe1, 0xec, 0x51, - 0x73, 0xc8, 0xf2, 0x17, 0x68, 0x19, 0x06, 0x1b, 0x84, 0x35, 0x0f, 0xb8, 0xbc, 0x68, 0xe9, 0xfe, - 0xb5, 0xa6, 0xc0,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x23, 0x3f, 0x77, 0x13, 0x4c, 0x9a, 0x98, - 0x11, 0x26, 0xa6, 0xb4, 0xc9, 0x70, 0x13, 0x5e, 0xe6, 0x53, 0x88, 0x07, 0xde, 0xbe, 0x50, 0x03, - 0x57, 0x9f, 0xe4, 0x50, 0x03, 0x21, 0x4f, 0xa8, 0xa6, 0x0a, 0x03, 0x49, 0xd4, 0xc7, 0x40, 0xee, - 0xf5, 0x8f, 0x0b, 0x55, 0x39, 0xbf, 0x50, 0x95, 0xdf, 0x17, 0xaa, 0xf2, 0xed, 0x52, 0x8d, 0x9c, - 0x5f, 0xaa, 0x91, 0x5f, 0x97, 0x6a, 0xe4, 0x43, 0xc6, 0xb2, 0xf9, 0x7e, 0xb3, 0xac, 0x57, 0x68, - 0xad, 0x55, 0xeb, 0xff, 0x79, 0xc6, 0xaa, 0x9f, 0x0c, 0x7e, 0x5c, 0x27, 0x1e, 0x59, 0x79, 0x50, - 0xfc, 0x70, 0x3c, 0xff, 0x17, 0x00, 0x00, 0xff, 0xff, 0x96, 0xba, 0xfb, 0xcb, 0x0f, 0x07, 0x00, + // 817 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xcf, 0x6f, 0xe3, 0x44, + 0x14, 0x8e, 0x9d, 0xa5, 0xc9, 0xbe, 0xa4, 0x4b, 0x76, 0x5a, 0x96, 0x90, 0x05, 0x37, 0xeb, 0x25, + 0x6d, 0x14, 0x09, 0x5b, 0x0d, 0x20, 0x55, 0x88, 0x4b, 0x7e, 0xb5, 0x54, 0xd0, 0xa6, 0x72, 0xca, + 0xa1, 0x08, 0x29, 0x72, 0x92, 0xa9, 0x6b, 0xd1, 0x78, 0x52, 0xcf, 0xa4, 0x72, 0xd4, 0x56, 0x48, + 0x1c, 0x39, 0x21, 0xf1, 0x67, 0xf0, 0x4f, 0x70, 0xe4, 0x58, 0x89, 0x0b, 0x47, 0xd4, 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 0xff, 0x7b, 0x64, 0xf5, 0xff, 0x95, 0x07, 0x00, 0x00, } @@ -779,6 +840,11 @@ func (m *GetTxsEventRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.OrderBy != 0 { + i = encodeVarintService(dAtA, i, uint64(m.OrderBy)) + i-- + dAtA[i] = 0x18 + } if m.Pagination != nil { { size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) @@ -1122,6 +1188,9 @@ func (m *GetTxsEventRequest) Size() (n int) { l = m.Pagination.Size() n += 1 + l + sovService(uint64(l)) } + if m.OrderBy != 0 { + n += 1 + sovService(uint64(m.OrderBy)) + } return n } @@ -1342,6 +1411,25 @@ func (m *GetTxsEventRequest) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field OrderBy", wireType) + } + m.OrderBy = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.OrderBy |= OrderBy(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipService(dAtA[iNdEx:]) diff --git a/x/auth/tx/service.go b/x/auth/tx/service.go index d33bcac9132..2d73a110b70 100644 --- a/x/auth/tx/service.go +++ b/x/auth/tx/service.go @@ -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") @@ -63,7 +64,7 @@ func (s txServer) GetTxsEvent(ctx context.Context, req *txtypes.GetTxsEventReque } } - result, err := QueryTxsByEvents(s.clientCtx, req.Events, page, limit, "") + result, err := QueryTxsByEvents(s.clientCtx, req.Events, page, limit, orderBy) if err != nil { return nil, err } @@ -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 "asc" + } +} diff --git a/x/auth/tx/service_test.go b/x/auth/tx/service_test.go index b460867b4b2..03944d6c41e 100644 --- a/x/auth/tx/service_test.go +++ b/x/auth/tx/service_test.go @@ -173,6 +173,14 @@ func (s IntegrationTestSuite) TestGetTxEvents_GRPC() { &tx.GetTxsEventRequest{Events: []string{"foobar"}}, true, "event foobar should be of the format: {eventType}.{eventAttribute}={value}", }, + { + "request with order-by", + &tx.GetTxsEventRequest{ + Events: []string{"message.action='/cosmos.bank.v1beta1.Msg/Send'"}, + OrderBy: tx.OrderBy_ORDER_BY_ASC, + }, + false, "", + }, { "without pagination", &tx.GetTxsEventRequest{ @@ -248,6 +256,24 @@ func (s IntegrationTestSuite) TestGetTxEvents_GRPCGateway() { false, "", }, + { + "valid request: order by asc", + fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s&events=%s&order_by=ORDER_BY_ASC", val.APIAddress, "message.action='/cosmos.bank.v1beta1.Msg/Send'", "message.module='bank'"), + false, + "", + }, + { + "valid request: order by desc", + fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s&events=%s&order_by=ORDER_BY_DESC", val.APIAddress, "message.action='/cosmos.bank.v1beta1.Msg/Send'", "message.module='bank'"), + false, + "", + }, + { + "invalid request: invalid order by", + fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s&events=%s&order_by=invalid_order", val.APIAddress, "message.action='/cosmos.bank.v1beta1.Msg/Send'", "message.module='bank'"), + true, + "is not a valid tx.OrderBy", + }, { "expect pass with multiple-events", fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s&events=%s", val.APIAddress, "message.action='/cosmos.bank.v1beta1.Msg/Send'", "message.module='bank'"),