syntax = "proto3";
package cosmwasm.wasm.v1beta1;

import "gogoproto/gogo.proto";
import "cosmwasm/wasm/v1beta1/types.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";

option go_package = "github.com/CosmWasm/wasmd/x/wasm/types";
option (gogoproto.goproto_getters_all) = false;
option (gogoproto.equal_all) = false;

// Query provides defines the gRPC querier service
service Query {
  // ContractInfo gets the contract meta data
  rpc ContractInfo(QueryContractInfoRequest)
      returns (QueryContractInfoResponse) {
    option (google.api.http).get = "/wasm/v1beta1/contract/{address}";
  }
  // ContractHistory gets the contract code history
  rpc ContractHistory(QueryContractHistoryRequest)
      returns (QueryContractHistoryResponse) {
    option (google.api.http).get = "/wasm/v1beta1/contract/{address}/history";
  }
  // ContractsByCode lists all smart contracts for a code id
  rpc ContractsByCode(QueryContractsByCodeRequest)
      returns (QueryContractsByCodeResponse) {
    option (google.api.http).get = "/wasm/v1beta1/code/{code_id}/contracts";
  }
  // AllContractState gets all raw store data for a single contract
  rpc AllContractState(QueryAllContractStateRequest)
      returns (QueryAllContractStateResponse) {
    option (google.api.http).get = "/wasm/v1beta1/contract/{address}/state";
  }
  // RawContractState gets single key from the raw store data of a contract
  rpc RawContractState(QueryRawContractStateRequest)
      returns (QueryRawContractStateResponse) {
    option (google.api.http).get =
        "/wasm/v1beta1/contract/{address}/raw/{query_data}";
  }
  // SmartContractState get smart query result from the contract
  rpc SmartContractState(QuerySmartContractStateRequest)
      returns (QuerySmartContractStateResponse) {
    option (google.api.http).get =
        "/wasm/v1beta1/contract/{address}/smart/{query_data}";
  }
  // Code gets the binary code and metadata for a singe wasm code
  rpc Code(QueryCodeRequest) returns (QueryCodeResponse) {
    option (google.api.http).get = "/wasm/v1beta1/code/{code_id}";
  }
  // Codes gets the metadata for all stored wasm codes
  rpc Codes(QueryCodesRequest) returns (QueryCodesResponse) {
    option (google.api.http).get = "/wasm/v1beta1/code";
  }
}

// QueryContractInfoRequest is the request type for the Query/ContractInfo RPC
// method
message QueryContractInfoRequest {
  // address is the address of the contract to query
  string address = 1;
}
// QueryContractInfoResponse is the response type for the Query/ContractInfo RPC
// method
message QueryContractInfoResponse {
  option (gogoproto.equal) = true;

  // address is the address of the contract
  string address = 1;
  ContractInfo contract_info = 2 [
    (gogoproto.embed) = true,
    (gogoproto.nullable) = false,
    (gogoproto.jsontag) = ""
  ];
}

// QueryContractHistoryRequest is the request type for the Query/ContractHistory
// RPC method
message QueryContractHistoryRequest {
  // address is the address of the contract to query
  string address = 1;
  // pagination defines an optional pagination for the request.
  cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

// QueryContractHistoryResponse is the response type for the
// Query/ContractHistory RPC method
message QueryContractHistoryResponse {
  repeated ContractCodeHistoryEntry entries = 1
      [ (gogoproto.nullable) = false ];
  // pagination defines the pagination in the response.
  cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryContractsByCodeRequest is the request type for the Query/ContractsByCode
// RPC method
message QueryContractsByCodeRequest {
  uint64 code_id = 1; // grpc-gateway_out does not support Go style CodID
  // pagination defines an optional pagination for the request.
  cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

// QueryContractsByCodeResponse is the response type for the
// Query/ContractsByCode RPC method
message QueryContractsByCodeResponse {
  // contracts are a set of contract addresses
  repeated string contracts = 1;

  // pagination defines the pagination in the response.
  cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryAllContractStateRequest is the request type for the
// Query/AllContractState RPC method
message QueryAllContractStateRequest {
  // address is the address of the contract
  string address = 1;
  // pagination defines an optional pagination for the request.
  cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

// QueryAllContractStateResponse is the response type for the
// Query/AllContractState RPC method
message QueryAllContractStateResponse {
  repeated Model models = 1 [ (gogoproto.nullable) = false ];
  // pagination defines the pagination in the response.
  cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryRawContractStateRequest is the request type for the
// Query/RawContractState RPC method
message QueryRawContractStateRequest {
  // address is the address of the contract
  string address = 1;
  bytes query_data = 2;
}

// QueryRawContractStateResponse is the response type for the
// Query/RawContractState RPC method
message QueryRawContractStateResponse {
  // Data contains the raw store data
  bytes data = 1;
}

// QuerySmartContractStateRequest is the request type for the
// Query/SmartContractState RPC method
message QuerySmartContractStateRequest {
  // address is the address of the contract
  string address = 1;
  // QueryData contains the query data passed to the contract
  bytes query_data = 2;
}

// QuerySmartContractStateResponse is the response type for the
// Query/SmartContractState RPC method
message QuerySmartContractStateResponse {
  // Data contains the json data returned from the smart contract
  bytes data = 1 [ (gogoproto.casttype) = "encoding/json.RawMessage" ];
}

// QueryCodeRequest is the request type for the Query/Code RPC method
message QueryCodeRequest {
  uint64 code_id = 1; // grpc-gateway_out does not support Go style CodID
}

// CodeInfoResponse contains code meta data from CodeInfo
message CodeInfoResponse {
  option (gogoproto.equal) = true;

  uint64 code_id = 1 [
    (gogoproto.customname) = "CodeID",
    (gogoproto.jsontag) = "id"
  ]; // id for legacy support
  string creator = 2;
  bytes data_hash = 3
      [ (gogoproto.casttype) =
            "github.com/tendermint/tendermint/libs/bytes.HexBytes" ];
  string source = 4;
  string builder = 5;
}

// QueryCodeResponse is the response type for the Query/Code RPC method
message QueryCodeResponse {
  option (gogoproto.equal) = true;
  CodeInfoResponse code_info = 1
      [ (gogoproto.embed) = true, (gogoproto.jsontag) = "" ];
  bytes data = 2 [ (gogoproto.jsontag) = "data" ];
}

// QueryCodesRequest is the request type for the Query/Codes RPC method
message QueryCodesRequest {
  // pagination defines an optional pagination for the request.
  cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

// QueryCodesResponse is the response type for the Query/Codes RPC method
message QueryCodesResponse {
  repeated CodeInfoResponse code_infos = 1 [ (gogoproto.nullable) = false ];
  // pagination defines the pagination in the response.
  cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
