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

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

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

// ContractExecutionAuthorization defines authorization for wasm execute.
// Since: wasmd 0.30
message ContractExecutionAuthorization {
  option (cosmos_proto.implements_interface) = "cosmos.authz.Authorization";

  // Grants for contract executions
  repeated ContractGrant grants = 1 [ (gogoproto.nullable) = false ];
}

// ContractMigrationAuthorization defines authorization for wasm contract
// migration. Since: wasmd 0.30
message ContractMigrationAuthorization {
  option (cosmos_proto.implements_interface) = "cosmos.authz.Authorization";

  // Grants for contract migrations
  repeated ContractGrant grants = 1 [ (gogoproto.nullable) = false ];
}

// ContractGrant a granted permission for a single contract
// Since: wasmd 0.30
message ContractGrant {
  // Contract is the bech32 address of the smart contract
  string contract = 1;

  // Limit defines execution limits that are enforced and updated when the grant
  // is applied. When the limit lapsed the grant is removed.
  google.protobuf.Any limit = 2
      [ (cosmos_proto.accepts_interface) = "ContractAuthzLimitX" ];

  // Filter define more fine-grained control on the message payload passed
  // to the contract in the operation. When no filter applies on execution, the
  // operation is prohibited.
  google.protobuf.Any filter = 3
      [ (cosmos_proto.accepts_interface) = "ContractAuthzFilterX" ];
}

// MaxCallsLimit limited number of calls to the contract. No funds transferable.
// Since: wasmd 0.30
message MaxCallsLimit {
  option (cosmos_proto.implements_interface) = "ContractAuthzLimitX";

  // Remaining number that is decremented on each execution
  uint64 remaining = 1;
}

// MaxFundsLimit defines the maximal amounts that can be sent to the contract.
// Since: wasmd 0.30
message MaxFundsLimit {
  option (cosmos_proto.implements_interface) = "ContractAuthzLimitX";

  // Amounts is the maximal amount of tokens transferable to the contract.
  repeated cosmos.base.v1beta1.Coin amounts = 1 [
    (gogoproto.nullable) = false,
    (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
  ];
}

// CombinedLimit defines the maximal amounts that can be sent to a contract and
// the maximal number of calls executable. Both need to remain >0 to be valid.
// Since: wasmd 0.30
message CombinedLimit {
  option (cosmos_proto.implements_interface) = "ContractAuthzLimitX";

  // Remaining number that is decremented on each execution
  uint64 calls_remaining = 1;
  // Amounts is the maximal amount of tokens transferable to the contract.
  repeated cosmos.base.v1beta1.Coin amounts = 2 [
    (gogoproto.nullable) = false,
    (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
  ];
}

// AllowAllMessagesFilter is a wildcard to allow any type of contract payload
// message.
// Since: wasmd 0.30
message AllowAllMessagesFilter {
  option (cosmos_proto.implements_interface) = "ContractAuthzFilterX";
}

// AcceptedMessageKeysFilter accept only the specific contract message keys in
// the json object to be executed.
// Since: wasmd 0.30
message AcceptedMessageKeysFilter {
  option (cosmos_proto.implements_interface) = "ContractAuthzFilterX";

  // Messages is the list of unique keys
  repeated string keys = 1;
}

// AcceptedMessagesFilter accept only the specific raw contract messages to be
// executed.
// Since: wasmd 0.30
message AcceptedMessagesFilter {
  option (cosmos_proto.implements_interface) = "ContractAuthzFilterX";

  // Messages is the list of raw contract messages
  repeated bytes messages = 1 [ (gogoproto.casttype) = "RawContractMessage" ];
}
