syntax = "proto3";
package band.oracle.v1;

option go_package = "github.com/bandprotocol/chain/v3/x/oracle/types";

import "gogoproto/gogo.proto";
import "band/oracle/v1/oracle.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/msg/v1/msg.proto";
import "amino/amino.proto";

// Msg defines the oracle Msg service.
service Msg {
  option (cosmos.msg.v1.service) = true;

  // RequestData defines a method for submitting a new request.
  rpc RequestData(MsgRequestData) returns (MsgRequestDataResponse);

  // ReportData defines a method for reporting a data to resolve the request.
  rpc ReportData(MsgReportData) returns (MsgReportDataResponse);

  // CreateDataSource defines a method for creating a new data source.
  rpc CreateDataSource(MsgCreateDataSource) returns (MsgCreateDataSourceResponse);

  // EditDataSource defines a method for editing an existing data source.
  rpc EditDataSource(MsgEditDataSource) returns (MsgEditDataSourceResponse);

  // CreateOracleScript defines a method for creating a new oracle script.
  rpc CreateOracleScript(MsgCreateOracleScript) returns (MsgCreateOracleScriptResponse);

  // EditOracleScript defines a method for editing an existing oracle script.
  rpc EditOracleScript(MsgEditOracleScript) returns (MsgEditOracleScriptResponse);

  // Activate defines a method for applying to be an oracle validator.
  rpc Activate(MsgActivate) returns (MsgActivateResponse);

  // UpdateParams defines a governance operation for updating the x/oracle module
  // parameters.
  //
  // Since: cosmos-sdk 0.47
  rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// MsgRequestData is a message for sending a data oracle request.
message MsgRequestData {
  option (cosmos.msg.v1.signer) = "sender";
  option (amino.name)           = "oracle/Request";

  option (gogoproto.equal) = true;
  // OracleScriptID is the identifier of the oracle script to be called.
  uint64 oracle_script_id = 1 [(gogoproto.customname) = "OracleScriptID", (gogoproto.casttype) = "OracleScriptID"];
  // Calldata is the OBI-encoded call parameters for the oracle script.
  bytes calldata = 2;
  // AskCount is the number of validators to perform the oracle task.
  uint64 ask_count = 3;
  // MinCount is the minimum number of validators sufficient to resolve the
  // oracle tasks.
  uint64 min_count = 4;
  // ClientID is the client-provided unique identifier to track the request.
  string client_id = 5 [(gogoproto.customname) = "ClientID"];
  // FeeLimit is the maximum tokens that will be paid to all data source
  // providers.
  repeated cosmos.base.v1beta1.Coin fee_limit = 6
      [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
  // PrepareGas is amount of gas to pay to prepare raw requests
  uint64 prepare_gas = 7;
  // ExecuteGas is amount of gas to reserve for executing
  uint64 execute_gas = 8;
  // Sender is an account address of message sender.
  string sender = 9 [(cosmos_proto.scalar) = "cosmos.AddressString"];
  // TSSEncoder is the mode of encoding oracle result signature order.
  Encoder tss_encoder = 10 [(gogoproto.customname) = "TSSEncoder"];
}

// MsgRequestDataResponse is response data for MsgRequestData message
message MsgRequestDataResponse {}

// MsgReportData is a message for reporting to a data request by a validator.
message MsgReportData {
  option (cosmos.msg.v1.signer) = "validator";
  option (amino.name)           = "oracle/Report";

  option (gogoproto.equal) = true;
  // RequestID is the identifier of the request to be reported to.
  uint64 request_id = 1 [(gogoproto.customname) = "RequestID", (gogoproto.casttype) = "RequestID"];
  // RawReports is the list of report information provided by data sources
  // identified by external ID
  repeated RawReport raw_reports = 2 [(gogoproto.nullable) = false];
  // Validator is the address of the validator that owns this report.
  string validator = 3 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"];
}

// MsgReportDataResponse is response data for MsgReportData message
message MsgReportDataResponse {}

// MsgCreateDataSource is a message for creating a new data source.
message MsgCreateDataSource {
  option (cosmos.msg.v1.signer) = "sender";
  option (amino.name)           = "oracle/CreateDataSource";

  option (gogoproto.equal) = true;
  // Name is the name of this data source used for display (optional).
  string name = 1;
  // Description is the description of this data source used for display
  // (optional).
  string description = 2;
  // Executable is the content of executable script or binary file to be run by
  // validators upon execution.
  bytes executable = 3;
  // Fee is the data source fee per ask_count that data provider will receive
  // from requester.
  repeated cosmos.base.v1beta1.Coin fee = 4
      [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
  // Treasury is the account address who receive data source fee from requester.
  string treasury = 5 [(cosmos_proto.scalar) = "cosmos.AddressString"];
  // Owner is the account address who is allowed to make further changes to the
  // data source.
  string owner = 6 [(cosmos_proto.scalar) = "cosmos.AddressString"];
  // Sender is the signer of this message.
  string sender = 7 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MsgCreateDataSourceResponse is response data for MsgCreateDataSource message
message MsgCreateDataSourceResponse {}

// MsgEditDataSource is a message for editing an existing data source.
message MsgEditDataSource {
  option (cosmos.msg.v1.signer) = "sender";
  option (amino.name)           = "oracle/EditDataSource";

  option (gogoproto.equal) = true;
  // DataSourceID is the unique identifier of the data source to be edited.
  uint64 data_source_id = 1 [(gogoproto.customname) = "DataSourceID", (gogoproto.casttype) = "DataSourceID"];
  // Name is the name of this data source used for display (optional).
  string name = 2;
  // Description is the description of this data source used for display
  // (optional).
  string description = 3;
  // Executable is the executable script or binary to be run by validators upon
  // execution.
  bytes executable = 4;
  // Fee is the data source fee per ask_count that data provider will receive
  // from requester.
  repeated cosmos.base.v1beta1.Coin fee = 5
      [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
  // Treasury is the address who receive data source fee from requester.
  string treasury = 6 [(cosmos_proto.scalar) = "cosmos.AddressString"];
  // Owner is the address who is allowed to make further changes to the data
  // source.
  string owner = 7 [(cosmos_proto.scalar) = "cosmos.AddressString"];
  // Sender is the signer of this message. Must be the current data source's
  // owner.
  string sender = 8 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MsgEditDataSourceResponse is response data for MsgEditDataSource message
message MsgEditDataSourceResponse {}

// MsgCreateOracleScript is a message for creating an oracle script.
message MsgCreateOracleScript {
  option (cosmos.msg.v1.signer) = "sender";
  option (amino.name)           = "oracle/CreateOracleScript";

  option (gogoproto.equal) = true;
  // Name is the name of this oracle script used for display (optional).
  string name = 1;
  // Description is the description of this oracle script used for display
  // (optional).
  string description = 2;
  // Schema is the OBI schema of this oracle script (optional).
  string schema = 3;
  // SourceCodeURL is the absolute URI to the script's source code (optional).
  string source_code_url = 4 [(gogoproto.customname) = "SourceCodeURL"];
  // Code is the oracle WebAssembly binary code. Can be raw of gzip compressed.
  bytes code = 5;
  // Owner is the address who is allowed to make further changes to the oracle
  // script.
  string owner = 6 [(cosmos_proto.scalar) = "cosmos.AddressString"];
  // Sender is the signer of this message.
  string sender = 7 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MsgCreateOracleScriptResponse is response data for MsgCreateOracleScript
// message
message MsgCreateOracleScriptResponse {}

// MsgEditOracleScript is a message for editing an existing oracle script.
message MsgEditOracleScript {
  option (cosmos.msg.v1.signer) = "sender";
  option (amino.name)           = "oracle/EditOracleScript";

  option (gogoproto.equal) = true;
  // OracleScriptID is the unique identifier of the oracle script to be edited.
  uint64 oracle_script_id = 1 [(gogoproto.customname) = "OracleScriptID", (gogoproto.casttype) = "OracleScriptID"];
  // Name is the name of this oracle script used for display (optional).
  string name = 2;
  // Description is the description of this oracle script used for display
  // (optional).
  string description = 3;
  // Schema is the OBI schema of this oracle script (optional).
  string schema = 4;
  // SourceCodeURL is the absolute URI to the script's source code (optional).
  string source_code_url = 5 [(gogoproto.customname) = "SourceCodeURL"];
  // Code is the oracle WebAssembly binary code. Can be raw of gzip compressed.
  bytes code = 6;
  // Owner is an account address who is allowed to make further changes to the
  // oracle script.
  string owner = 7 [(cosmos_proto.scalar) = "cosmos.AddressString"];
  // Sender is an account address who sign this message. Must be the current
  // oracle script's owner.
  string sender = 8 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MsgEditOracleScriptResponse is response data for MsgEditOracleScript message
message MsgEditOracleScriptResponse {}

// MsgEditOracleScript is a message for activating a validator to become an
// oracle provider. However, the activation can be revoked once the validator
// is unable to provide data to fulfill requests
message MsgActivate {
  option (cosmos.msg.v1.signer) = "validator";
  option (amino.name)           = "oracle/Activate";

  option (gogoproto.equal) = true;
  // Validator is the validator address who sign this message and request to be
  // activated.
  string validator = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"];
}

// MsgActivateResponse is response data for MsgActivate message
message MsgActivateResponse {}

// MsgUpdateParams is the Msg/UpdateParams request type.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParams {
  option (cosmos.msg.v1.signer) = "authority";
  option (amino.name)           = "oracle/UpdateParams";

  // authority is the address of the governance account.
  string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

  // params defines the x/oracle parameters to update.
  //
  // NOTE: All parameters must be supplied.
  Params params = 2 [(gogoproto.nullable) = false];
}

// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParamsResponse {}
