syntax = "proto3";
package secret.compute.v1beta1;

import "gogoproto/gogo.proto";
import "secret/compute/v1beta1/types.proto";
import "google/protobuf/empty.proto";
import "google/api/annotations.proto";
import "cosmos/base/abci/v1beta1/abci.proto";

option go_package = "github.com/enigmampc/SecretNetwork/x/compute/internal/types";
option (gogoproto.goproto_getters_all) = false;
option (gogoproto.equal_all) = true;


// Query provides defines the gRPC querier service
service Query {
    // Query contract
    rpc ContractInfo (QueryContractInfoRequest) returns (QueryContractInfoResponse) {
        option (google.api.http).get = "/compute/v1beta1/contract/{address}";
    }
    // Query contract
    rpc ContractsByCode (QueryContractsByCodeRequest) returns (QueryContractsByCodeResponse) {
        option (google.api.http).get = "/compute/v1beta1/code/{code_id}/contracts";
    }
    // Query contract
    rpc SmartContractState (QuerySmartContractStateRequest) returns (QuerySmartContractStateResponse) {
        option (google.api.http).get = "/compute/v1beta1/contract/{address}/smart";
    }
    // Query a specific contract code
    rpc Code (QueryCodeRequest) returns (QueryCodeResponse) {
        option (google.api.http).get = "/compute/v1beta1/code/{code_id}";
    }
    // Query all contract codes on-chain
    rpc Codes (google.protobuf.Empty) returns (QueryCodesResponse) {
        option (google.api.http).get = "/compute/v1beta1/code";
    }
}

// QueryContractInfoRequest is the request type for the Query/ContractInfo RPC method
message QueryContractInfoRequest {
    // address is the address of the contract to query
    bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}
// QueryContractInfoResponse is the response type for the Query/ContractInfo RPC method
message QueryContractInfoResponse {
    // address is the address of the contract
    bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
    ContractInfo ContractInfo = 2 [(gogoproto.embed) = true, (gogoproto.jsontag) = ""];
}

message QueryContractHistoryRequest {
    // address is the address of the contract to query
    bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}

/*
message QueryContractHistoryResponse {
    repeated ContractCodeHistoryEntry entries = 1 [(gogoproto.nullable) = false];
}
*/

message QueryContractsByCodeRequest {
    uint64 code_id = 1; // grpc-gateway_out does not support Go style CodID
}

// ContractInfoWithAddress adds the address (key) to the ContractInfo representation
message ContractInfoWithAddress {
    bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
    ContractInfo ContractInfo = 2 [(gogoproto.embed) = true, (gogoproto.jsontag) = ""];
}

message QueryContractsByCodeResponse {
    repeated ContractInfoWithAddress contract_infos = 1 [(gogoproto.nullable) = false];
}

/*
message QueryAllContractStateRequest {
    // address is the address of the contract
    bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}

message QueryAllContractStateResponse {
    repeated Model models = 1 [(gogoproto.nullable) = false];
}

message QueryRawContractStateRequest {
    // address is the address of the contract
    bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
    bytes query_data = 2;
}

message QueryRawContractStateResponse {
    bytes data = 1;
}
*/

message QuerySmartContractStateRequest {
    // address is the address of the contract
    bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
    bytes query_data = 2;
}

message QueryContractAddressByLabelRequest {
    string label = 1;
}

message QueryContractKeyRequest {
    // address is the address of the contract
    bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}

message QueryContractHashRequest {
    // address is the address of the contract
    bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}

message QuerySmartContractStateResponse {
    bytes data = 1;
}

message QueryCodeRequest {
    uint64 code_id = 1; // grpc-gateway_out does not support Go style CodID
}

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

message QueryCodeResponse {
    CodeInfoResponse code_info = 1 [(gogoproto.embed) = true, (gogoproto.jsontag) = ""];
    bytes data = 2 [(gogoproto.jsontag) = "data"];
}

message QueryCodesResponse {
    repeated CodeInfoResponse code_infos = 1 [(gogoproto.nullable) = false];
}

message QueryContractAddressByLabelResponse {
    // address is the address of the contract
    bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}

message QueryContractKeyResponse {
    // address is the address of the contract
    bytes key = 1 [(gogoproto.casttype) = "github.com/tendermint/tendermint/libs/bytes.HexBytes"];
}

message QueryContractHashResponse {
    bytes code_hash = 1 [(gogoproto.casttype) = "github.com/tendermint/tendermint/libs/bytes.HexBytes"];
}

// DecryptedAnswer is a struct that represents a decrypted tx-query
message DecryptedAnswer {
    option (gogoproto.equal) = false;

    string type = 1;
    string input = 2;
    string output_data = 3;
    string output_data_as_string = 4;
    repeated cosmos.base.abci.v1beta1.StringEvent output_logs = 5 [(gogoproto.nullable) = false];
    bytes output_error = 6 [(gogoproto.casttype) = "encoding/json.RawMessage"];
    string plaintext_error = 7;
}
