syntax = "proto3";
package neutron.interchainqueries;

import "cosmos/base/v1beta1/coin.proto";
import "gogoproto/gogo.proto";
import "ibc/core/client/v1/client.proto";
import "neutron/interchainqueries/params.proto";

option go_package = "github.com/neutron-org/neutron/v7/x/interchainqueries/types";

// Information about an Interchain Query registered in the interchainqueries module.
message RegisteredQuery {
  // The unique id of the registered query.
  uint64 id = 1;
  // The address of the contract that registered the query.
  string owner = 2;
  // The query type identifier: `kv` or `tx`.
  string query_type = 3;
  // The KV-storage keys for which to get values from the remote chain. Only applicable for the
  // KV Interchain Queries. Max amount of keys is limited by the module's `max_kv_query_keys_count`
  // parameters.
  repeated KVKey keys = 4;
  // A stringified list of filters for remote transactions search. Only applicable for the TX
  // Interchain Queries. Example: "[{\"field\":\"tx.height\",\"op\":\"Gte\",\"value\":2644737}]".
  // Supported operators: "eq", "lt", "gt", "lte", "gte". Max amount of filter conditions is limited
  // by the module's `max_transactions_filters` parameters.
  string transactions_filter = 5;
  // The IBC connection ID to the remote chain (the source of querying data). Is used for getting
  // ConsensusState from the respective IBC client to verify query result proofs.
  string connection_id = 6;
  // Parameter that defines the minimal delay between consecutive query executions (i.e. the
  // minimal delay between query results update).
  uint64 update_period = 7;
  // The local chain block height of the last query results update.
  uint64 last_submitted_result_local_height = 8;
  // The remote chain block height that corresponds to the last query result update.
  ibc.core.client.v1.Height last_submitted_result_remote_height = 9;
  // Amount of coins paid for the Interchain Query registration. The deposit is paid back to the
  // remover. The remover can be either the query owner (during the submit timeout) or anybody.
  repeated cosmos.base.v1beta1.Coin deposit = 10 [
    (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
    (gogoproto.nullable) = false
  ];
  // The duration, measured in blocks, that must pass since the query's registration or its last
  // result submission before the query becomes eligible for removal by anyone.
  uint64 submit_timeout = 11;
  // The local chain block height of the Interchain Query registration.
  uint64 registered_at_height = 12;
}

// Represents a path to an IAVL storage node.
message KVKey {
  // The substore name used in an Interchain Query. Typically, this corresponds to the keeper's
  // storeKey, usually the module's name, such as "bank", "staking", etc.
  string path = 1;
  // A bytes field representing the key for specific data in the module's storage.
  bytes key = 2;
}

// The interchainqueries module's genesis state model.
message GenesisState {
  // The parameters of the module.
  Params params = 1 [(gogoproto.nullable) = false];
  // A list of registered Interchain Queries.
  repeated RegisteredQuery registered_queries = 2;
}
