syntax = "proto3";
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";
import "tendermint/types/block.proto";
import "tendermint/types/types.proto";

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

// Service defines a gRPC service for interacting with transactions.
service Service {
  // Simulate simulates executing a transaction for estimating gas usage.
  rpc Simulate(SimulateRequest) returns (SimulateResponse) {
    option (google.api.http) = {
      post: "/cosmos/tx/v1beta1/simulate"
      body: "*"
    };
  }
  // GetTx fetches a tx by hash.
  rpc GetTx(GetTxRequest) returns (GetTxResponse) {
    option (google.api.http).get = "/cosmos/tx/v1beta1/txs/{hash}";
  }
  // BroadcastTx broadcast transaction.
  rpc BroadcastTx(BroadcastTxRequest) returns (BroadcastTxResponse) {
    option (google.api.http) = {
      post: "/cosmos/tx/v1beta1/txs"
      body: "*"
    };
  }
  // GetTxsEvent fetches txs by event.
  rpc GetTxsEvent(GetTxsEventRequest) returns (GetTxsEventResponse) {
    option (google.api.http).get = "/cosmos/tx/v1beta1/txs";
  }
  // GetBlockWithTxs fetches a block with decoded txs.
  //
  // Since: cosmos-sdk 0.45.2
  rpc GetBlockWithTxs(GetBlockWithTxsRequest) returns (GetBlockWithTxsResponse) {
    option (google.api.http).get = "/cosmos/tx/v1beta1/txs/block/{height}";
  }
  // TxDecode decodes the transaction.
  //
  // Since: cosmos-sdk 0.47
  rpc TxDecode(TxDecodeRequest) returns (TxDecodeResponse) {
    option (google.api.http) = {
      post: "/cosmos/tx/v1beta1/decode"
      body: "*"
    };
  }
  // TxEncode encodes the transaction.
  //
  // Since: cosmos-sdk 0.47
  rpc TxEncode(TxEncodeRequest) returns (TxEncodeResponse) {
    option (google.api.http) = {
      post: "/cosmos/tx/v1beta1/encode"
      body: "*"
    };
  }
  // TxEncodeAmino encodes an Amino transaction from JSON to encoded bytes.
  //
  // Since: cosmos-sdk 0.47
  rpc TxEncodeAmino(TxEncodeAminoRequest) returns (TxEncodeAminoResponse) {
    option (google.api.http) = {
      post: "/cosmos/tx/v1beta1/encode/amino"
      body: "*"
    };
  }
  // TxDecodeAmino decodes an Amino transaction from encoded bytes to JSON.
  //
  // Since: cosmos-sdk 0.47
  rpc TxDecodeAmino(TxDecodeAminoRequest) returns (TxDecodeAminoResponse) {
    option (google.api.http) = {
      post: "/cosmos/tx/v1beta1/decode/amino"
      body: "*"
    };
  }
}

// GetTxsEventRequest is the request type for the Service.TxsByEvents
// RPC method.
message GetTxsEventRequest {
  // events is the list of transaction event type.
  repeated string events = 1;
  // pagination defines a pagination for the request.
  // Deprecated post v0.46.x: use page and limit instead.
  cosmos.base.query.v1beta1.PageRequest pagination = 2 [deprecated = true];

  OrderBy order_by = 3;
  // page is the page number to query, starts at 1. If not provided, will default to first page.
  uint64 page = 4;
  // limit is the total number of results to be returned in the result page.
  // If left empty it will default to a value to be set by each app.
  uint64 limit = 5;
}

// 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
// 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 a pagination for the response.
  // Deprecated post v0.46.x: use total instead.
  cosmos.base.query.v1beta1.PageResponse pagination = 3 [deprecated = true];
  // total is total number of results available
  uint64 total = 4;
}

// BroadcastTxRequest is the request type for the Service.BroadcastTxRequest
// RPC method.
message BroadcastTxRequest {
  // tx_bytes is the raw transaction.
  bytes         tx_bytes = 1;
  BroadcastMode mode     = 2;
}

// BroadcastMode specifies the broadcast mode for the TxService.Broadcast RPC method.
enum BroadcastMode {
  // zero-value for mode ordering
  BROADCAST_MODE_UNSPECIFIED = 0;
  // DEPRECATED: use BROADCAST_MODE_SYNC instead,
  // BROADCAST_MODE_BLOCK is not supported by the SDK from v0.47.x onwards.
  BROADCAST_MODE_BLOCK = 1 [deprecated = true];
  // BROADCAST_MODE_SYNC defines a tx broadcasting mode where the client waits for
  // a CheckTx execution response only.
  BROADCAST_MODE_SYNC = 2;
  // BROADCAST_MODE_ASYNC defines a tx broadcasting mode where the client returns
  // immediately.
  BROADCAST_MODE_ASYNC = 3;
}

// BroadcastTxResponse is the response type for the
// Service.BroadcastTx method.
message BroadcastTxResponse {
  // tx_response is the queried TxResponses.
  cosmos.base.abci.v1beta1.TxResponse tx_response = 1;
}

// SimulateRequest is the request type for the Service.Simulate
// RPC method.
message SimulateRequest {
  // tx is the transaction to simulate.
  // Deprecated. Send raw tx bytes instead.
  cosmos.tx.v1beta1.Tx tx = 1 [deprecated = true];
  // tx_bytes is the raw transaction.
  //
  // Since: cosmos-sdk 0.43
  bytes tx_bytes = 2;
}

// SimulateResponse is the response type for the
// Service.SimulateRPC method.
message SimulateResponse {
  // gas_info is the information about gas used in the simulation.
  cosmos.base.abci.v1beta1.GasInfo gas_info = 1;
  // result is the result of the simulation.
  cosmos.base.abci.v1beta1.Result result = 2;
}

// 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;
}

// GetBlockWithTxsRequest is the request type for the Service.GetBlockWithTxs
// RPC method.
//
// Since: cosmos-sdk 0.45.2
message GetBlockWithTxsRequest {
  // height is the height of the block to query.
  int64 height = 1;
  // pagination defines a pagination for the request.
  cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

// GetBlockWithTxsResponse is the response type for the Service.GetBlockWithTxs method.
//
// Since: cosmos-sdk 0.45.2
message GetBlockWithTxsResponse {
  // txs are the transactions in the block.
  repeated cosmos.tx.v1beta1.Tx txs      = 1;
  .tendermint.types.BlockID     block_id = 2;
  .tendermint.types.Block       block    = 3;
  // pagination defines a pagination for the response.
  cosmos.base.query.v1beta1.PageResponse pagination = 4;
}

// TxDecodeRequest is the request type for the Service.TxDecode
// RPC method.
//
// Since: cosmos-sdk 0.47
message TxDecodeRequest {
  // tx_bytes is the raw transaction.
  bytes tx_bytes = 1;
}

// TxDecodeResponse is the response type for the
// Service.TxDecode method.
//
// Since: cosmos-sdk 0.47
message TxDecodeResponse {
  // tx is the decoded transaction.
  cosmos.tx.v1beta1.Tx tx = 1;
}

// TxEncodeRequest is the request type for the Service.TxEncode
// RPC method.
//
// Since: cosmos-sdk 0.47
message TxEncodeRequest {
  // tx is the transaction to encode.
  cosmos.tx.v1beta1.Tx tx = 1;
}

// TxEncodeResponse is the response type for the
// Service.TxEncode method.
//
// Since: cosmos-sdk 0.47
message TxEncodeResponse {
  // tx_bytes is the encoded transaction bytes.
  bytes tx_bytes = 1;
}

// TxEncodeAminoRequest is the request type for the Service.TxEncodeAmino
// RPC method.
//
// Since: cosmos-sdk 0.47
message TxEncodeAminoRequest {
  string amino_json = 1;
}

// TxEncodeAminoResponse is the response type for the Service.TxEncodeAmino
// RPC method.
//
// Since: cosmos-sdk 0.47
message TxEncodeAminoResponse {
  bytes amino_binary = 1;
}

// TxDecodeAminoRequest is the request type for the Service.TxDecodeAmino
// RPC method.
//
// Since: cosmos-sdk 0.47
message TxDecodeAminoRequest {
  bytes amino_binary = 1;
}

// TxDecodeAminoResponse is the response type for the Service.TxDecodeAmino
// RPC method.
//
// Since: cosmos-sdk 0.47
message TxDecodeAminoResponse {
  string amino_json = 1;
}