Skip to content

Commit

Permalink
Add TxsByEvent gRPC endpoint (#7842)
Browse files Browse the repository at this point in the history
* add service definition for TxsByEvents

* add TxsByEvent gRPC endpoint

* fix lint

* fix test

* review changes

* review changes

* fix proto descriptions

* review changes

* fix lint

* review changes

* Update proto/cosmos/tx/v1beta1/service.proto

* review changes

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Nov 12, 2020
1 parent c8afb2c commit f3e4964
Show file tree
Hide file tree
Showing 7 changed files with 967 additions and 43 deletions.
34 changes: 31 additions & 3 deletions proto/cosmos/tx/v1beta1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package cosmos.tx.v1beta1;
import "google/api/annotations.proto";
import "cosmos/base/abci/v1beta1/abci.proto";
import "cosmos/tx/v1beta1/tx.proto";
import "cosmos/base/query/v1beta1/pagination.proto";

option go_package = "github.com/cosmos/cosmos-sdk/types/tx";

Expand All @@ -17,6 +18,31 @@ service Service {
rpc GetTx(GetTxRequest) returns (GetTxResponse) {
option (google.api.http).get = "/cosmos/tx/v1beta1/tx/{hash}";
}

// GetTxsEvent fetches txs by event.
rpc GetTxsEvent(GetTxsEventRequest) returns (GetTxsEventResponse) {
option (google.api.http).get = "/cosmos/tx/v1beta1/txs";
}
}

// GetTxsEventRequest is the request type for the Service.TxsByEvents
// RPC method.
message GetTxsEventRequest {
// event is the transaction event type.
string event = 1;
// pagination defines an pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

// GetTxsEventResponse is the response type for the Service.TxsByEvents
// RPC method.
message GetTxsEventResponse {
// txs is the list of queried transactions.
repeated cosmos.tx.v1beta1.Tx txs = 1;
// tx_responses is the list of queried TxResponses.
repeated cosmos.base.abci.v1beta1.TxResponse tx_responses = 2;
// pagination defines an pagination for the response.
cosmos.base.query.v1beta1.PageResponse pagination = 3;
}

// SimulateRequest is the request type for the Service.Simulate
Expand All @@ -35,15 +61,17 @@ message SimulateResponse {
cosmos.base.abci.v1beta1.Result result = 2;
}

// GetTx is the request type for the Service.GetTx
// GetTxRequest is the request type for the Service.GetTx
// RPC method.
message GetTxRequest {
// hash is the tx hash to query, encoded as a hex string.
string hash = 1;
}

// GetTxResponse is the response type for the Service.GetTx method.
message GetTxResponse {
// tx is the queried transaction.
cosmos.tx.v1beta1.Tx tx = 1;
}
// tx_response is the queried TxResponses.
cosmos.base.abci.v1beta1.TxResponse tx_response = 2;
}
2 changes: 1 addition & 1 deletion types/query/filtered_pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func FilteredPaginate(
}

if limit == 0 {
limit = defaultLimit
limit = DefaultLimit

// count total results when the limit is zero/not supplied
countTotal = true
Expand Down
8 changes: 4 additions & 4 deletions types/query/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"github.com/cosmos/cosmos-sdk/store/types"
)

// defaultLimit is the default `limit` for queries
// if the `limit` is not supplied, paginate will use `defaultLimit`
const defaultLimit = 100
// DefaultLimit is the default `limit` for queries
// if the `limit` is not supplied, paginate will use `DefaultLimit`
const DefaultLimit = 100

// Paginate does pagination of all the results in the PrefixStore based on the
// provided PageRequest. onResult should be used to do actual unmarshaling.
Expand All @@ -33,7 +33,7 @@ func Paginate(
}

if limit == 0 {
limit = defaultLimit
limit = DefaultLimit

// count total results when the limit is zero/not supplied
countTotal = true
Expand Down
Loading

0 comments on commit f3e4964

Please sign in to comment.