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

import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";

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

// AccessType permission types
enum AccessType {
  option (gogoproto.goproto_enum_prefix) = false;
  option (gogoproto.goproto_enum_stringer) = false;
  // AccessTypeUnspecified placeholder for empty value
  ACCESS_TYPE_UNSPECIFIED = 0
      [ (gogoproto.enumvalue_customname) = "AccessTypeUnspecified" ];
  // AccessTypeNobody forbidden
  ACCESS_TYPE_NOBODY = 1
      [ (gogoproto.enumvalue_customname) = "AccessTypeNobody" ];
  // AccessTypeOnlyAddress restricted to an address
  ACCESS_TYPE_ONLY_ADDRESS = 2
      [ (gogoproto.enumvalue_customname) = "AccessTypeOnlyAddress" ];
  // AccessTypeEverybody unrestricted
  ACCESS_TYPE_EVERYBODY = 3
      [ (gogoproto.enumvalue_customname) = "AccessTypeEverybody" ];
}

// AccessTypeParam
message AccessTypeParam {
  option (gogoproto.goproto_stringer) = true;
  AccessType value = 1 [ (gogoproto.moretags) = "yaml:\"value\"" ];
}

// AccessConfig access control type.
message AccessConfig {
  option (gogoproto.goproto_stringer) = true;
  AccessType permission = 1 [ (gogoproto.moretags) = "yaml:\"permission\"" ];
  string address = 2 [ (gogoproto.moretags) = "yaml:\"address\"" ];
}

// Params defines the set of wasm parameters.
message Params {
  option (gogoproto.goproto_stringer) = false;
  AccessConfig code_upload_access = 1 [
    (gogoproto.nullable) = false,
    (gogoproto.moretags) = "yaml:\"code_upload_access\""
  ];
  AccessType instantiate_default_permission = 2
      [ (gogoproto.moretags) = "yaml:\"instantiate_default_permission\"" ];
  uint64 max_wasm_code_size = 3
      [ (gogoproto.moretags) = "yaml:\"max_wasm_code_size\"" ];
}

// CodeInfo is data for the uploaded contract WASM code
message CodeInfo {
  // CodeHash is the unique identifier created by wasmvm
  bytes code_hash = 1;
  // Creator address who initially stored the code
  string creator = 2;
  // Used in v1beta1
  reserved 3, 4;
  // InstantiateConfig access control to apply on contract creation, optional
  AccessConfig instantiate_config = 5 [ (gogoproto.nullable) = false ];
}

// ContractInfo stores a WASM contract instance
message ContractInfo {
  option (gogoproto.equal) = true;

  // CodeID is the reference to the stored Wasm code
  uint64 code_id = 1 [ (gogoproto.customname) = "CodeID" ];
  // Creator address who initially instantiated the contract
  string creator = 2;
  // Admin is an optional address that can execute migrations
  string admin = 3;
  // Label is optional metadata to be stored with a contract instance.
  string label = 4;
  // Created Tx position when the contract was instantiated.
  // This data should kept internal and not be exposed via query results. Just
  // use for sorting
  AbsoluteTxPosition created = 5;
  string ibc_port_id = 6 [ (gogoproto.customname) = "IBCPortID" ];

  // Extension is an extension point to store custom metadata within the
  // persistence model.
  google.protobuf.Any extension = 7
      [ (cosmos_proto.accepts_interface) = "ContractInfoExtension" ];
}

// ContractCodeHistoryOperationType actions that caused a code change
enum ContractCodeHistoryOperationType {
  option (gogoproto.goproto_enum_prefix) = false;
  // ContractCodeHistoryOperationTypeUnspecified placeholder for empty value
  CONTRACT_CODE_HISTORY_OPERATION_TYPE_UNSPECIFIED = 0
      [ (gogoproto.enumvalue_customname) =
            "ContractCodeHistoryOperationTypeUnspecified" ];
  // ContractCodeHistoryOperationTypeInit on chain contract instantiation
  CONTRACT_CODE_HISTORY_OPERATION_TYPE_INIT = 1
      [ (gogoproto.enumvalue_customname) =
            "ContractCodeHistoryOperationTypeInit" ];
  // ContractCodeHistoryOperationTypeMigrate code migration
  CONTRACT_CODE_HISTORY_OPERATION_TYPE_MIGRATE = 2
      [ (gogoproto.enumvalue_customname) =
            "ContractCodeHistoryOperationTypeMigrate" ];
  // ContractCodeHistoryOperationTypeGenesis based on genesis data
  CONTRACT_CODE_HISTORY_OPERATION_TYPE_GENESIS = 3
      [ (gogoproto.enumvalue_customname) =
            "ContractCodeHistoryOperationTypeGenesis" ];
}

// ContractCodeHistoryEntry metadata to a contract.
message ContractCodeHistoryEntry {
  ContractCodeHistoryOperationType operation = 1;
  // CodeID is the reference to the stored WASM code
  uint64 code_id = 2 [ (gogoproto.customname) = "CodeID" ];
  // Updated Tx position when the operation was executed.
  AbsoluteTxPosition updated = 3;
  bytes msg = 4 [ (gogoproto.casttype) = "RawContractMessage" ];
}

// AbsoluteTxPosition is a unique transaction position that allows for global
// ordering of transactions.
message AbsoluteTxPosition {
  // BlockHeight is the block the contract was created at
  uint64 block_height = 1;
  // TxIndex is a monotonic counter within the block (actual transaction index,
  // or gas consumed)
  uint64 tx_index = 2;
}

// Model is a struct that holds a KV pair
message Model {
  // hex-encode key to read it better (this is often ascii)
  bytes key = 1 [ (gogoproto.casttype) =
                      "github.com/tendermint/tendermint/libs/bytes.HexBytes" ];
  // base64-encode raw value
  bytes value = 2;
}
