syntax = "proto3";

package ibc.core.connection.v1;

option go_package = "github.com/cosmos/ibc-go/v10/modules/core/03-connection/types";

import "gogoproto/gogo.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "ibc/core/client/v1/client.proto";
import "ibc/core/connection/v1/connection.proto";
import "google/api/annotations.proto";
import "google/protobuf/any.proto";

// Query provides defines the gRPC querier service
service Query {
  // Connection queries an IBC connection end.
  rpc Connection(QueryConnectionRequest) returns (QueryConnectionResponse) {
    option (google.api.http).get = "/ibc/core/connection/v1/connections/{connection_id}";
  }

  // Connections queries all the IBC connections of a chain.
  rpc Connections(QueryConnectionsRequest) returns (QueryConnectionsResponse) {
    option (google.api.http).get = "/ibc/core/connection/v1/connections";
  }

  // ClientConnections queries the connection paths associated with a client
  // state.
  rpc ClientConnections(QueryClientConnectionsRequest) returns (QueryClientConnectionsResponse) {
    option (google.api.http).get = "/ibc/core/connection/v1/client_connections/{client_id}";
  }

  // ConnectionClientState queries the client state associated with the
  // connection.
  rpc ConnectionClientState(QueryConnectionClientStateRequest) returns (QueryConnectionClientStateResponse) {
    option (google.api.http).get = "/ibc/core/connection/v1/connections/{connection_id}/client_state";
  }

  // ConnectionConsensusState queries the consensus state associated with the
  // connection.
  rpc ConnectionConsensusState(QueryConnectionConsensusStateRequest) returns (QueryConnectionConsensusStateResponse) {
    option (google.api.http).get = "/ibc/core/connection/v1/connections/{connection_id}/consensus_state/"
                                   "revision/{revision_number}/height/{revision_height}";
  }

  // ConnectionParams queries all parameters of the ibc connection submodule.
  rpc ConnectionParams(QueryConnectionParamsRequest) returns (QueryConnectionParamsResponse) {
    option (google.api.http).get = "/ibc/core/connection/v1/params";
  }
}

// QueryConnectionRequest is the request type for the Query/Connection RPC
// method
message QueryConnectionRequest {
  // connection unique identifier
  string connection_id = 1;
}

// QueryConnectionResponse is the response type for the Query/Connection RPC
// method. Besides the connection end, it includes a proof and the height from
// which the proof was retrieved.
message QueryConnectionResponse {
  // connection associated with the request identifier
  ibc.core.connection.v1.ConnectionEnd connection = 1;
  // merkle proof of existence
  bytes proof = 2;
  // height at which the proof was retrieved
  ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false];
}

// QueryConnectionsRequest is the request type for the Query/Connections RPC
// method
message QueryConnectionsRequest {
  cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

// QueryConnectionsResponse is the response type for the Query/Connections RPC
// method.
message QueryConnectionsResponse {
  // list of stored connections of the chain.
  repeated ibc.core.connection.v1.IdentifiedConnection connections = 1;
  // pagination response
  cosmos.base.query.v1beta1.PageResponse pagination = 2;
  // query block height
  ibc.core.client.v1.Height height = 3 [(gogoproto.nullable) = false];
}

// QueryClientConnectionsRequest is the request type for the
// Query/ClientConnections RPC method
message QueryClientConnectionsRequest {
  // client identifier associated with a connection
  string client_id = 1;
}

// QueryClientConnectionsResponse is the response type for the
// Query/ClientConnections RPC method
message QueryClientConnectionsResponse {
  // slice of all the connection paths associated with a client.
  repeated string connection_paths = 1;
  // merkle proof of existence
  bytes proof = 2;
  // height at which the proof was generated
  ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false];
}

// QueryConnectionClientStateRequest is the request type for the
// Query/ConnectionClientState RPC method
message QueryConnectionClientStateRequest {
  // connection identifier
  string connection_id = 1;
}

// QueryConnectionClientStateResponse is the response type for the
// Query/ConnectionClientState RPC method
message QueryConnectionClientStateResponse {
  // client state associated with the channel
  ibc.core.client.v1.IdentifiedClientState identified_client_state = 1;
  // merkle proof of existence
  bytes proof = 2;
  // height at which the proof was retrieved
  ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false];
}

// QueryConnectionConsensusStateRequest is the request type for the
// Query/ConnectionConsensusState RPC method
message QueryConnectionConsensusStateRequest {
  // connection identifier
  string connection_id   = 1;
  uint64 revision_number = 2;
  uint64 revision_height = 3;
}

// QueryConnectionConsensusStateResponse is the response type for the
// Query/ConnectionConsensusState RPC method
message QueryConnectionConsensusStateResponse {
  // consensus state associated with the channel
  google.protobuf.Any consensus_state = 1;
  // client ID associated with the consensus state
  string client_id = 2;
  // merkle proof of existence
  bytes proof = 3;
  // height at which the proof was retrieved
  ibc.core.client.v1.Height proof_height = 4 [(gogoproto.nullable) = false];
}

// QueryConnectionParamsRequest is the request type for the Query/ConnectionParams RPC method.
message QueryConnectionParamsRequest {}

// QueryConnectionParamsResponse is the response type for the Query/ConnectionParams RPC method.
message QueryConnectionParamsResponse {
  // params defines the parameters of the module.
  Params params = 1;
}
