syntax = "proto3";

package types;
option go_package = "../types";

//合约对象信息
message EVMContractObject {
    string           addr  = 1;
    EVMContractData  data  = 2;
    EVMContractState state = 3;
}

// 存放合约固定数据
message EVMContractData {
    string creator  = 1;
    string name     = 2;
    string alias    = 3;
    string addr     = 4;
    bytes  code     = 5;
    bytes  codeHash = 6;
    // 绑定ABI数据 ForkEVMABI
    string abi = 7;
}

// 存放合约变化数据
message EVMContractState {
    uint64             nonce       = 1;
    bool               suicided    = 2;
    bytes              storageHash = 3;
    map<string, bytes> storage     = 4;
}

// 创建/调用合约的请求结构
message EVMContractAction {
    // 转账金额
    uint64 amount = 1;
    // 消耗限制，默认为Transaction.Fee
    uint64 gasLimit = 2;
    // gas价格，默认为1
    uint32 gasPrice = 3;
    // 合约数据
    bytes code = 4;
    //交易参数
    bytes para = 5;
    // 合约别名，方便识别
    string alias = 6;
    // 交易备注
    string note = 7;
    // 调用合约地址
    string contractAddr = 8;
}

// 合约创建/调用日志
message ReceiptEVMContract {
    string caller       = 1;
    string contractName = 2;
    string contractAddr = 3;
    uint64 usedGas      = 4;
    // 创建合约返回的代码
    bytes ret = 5;
    // json格式化后的返回值
    string jsonRet = 6;
}

// 用于保存EVM只能合约中的状态数据变更
message EVMStateChangeItem {
    string key          = 1;
    bytes  preValue     = 2;
    bytes  currentValue = 3;
}

// 存放合约固定数据
message EVMContractDataCmd {
    string creator  = 1;
    string name     = 2;
    string alias    = 3;
    string addr     = 4;
    string code     = 5;
    string codeHash = 6;
}

// 存放合约变化数据
message EVMContractStateCmd {
    uint64              nonce       = 1;
    bool                suicided    = 2;
    string              storageHash = 3;
    map<string, string> storage     = 4;
}

// 合约创建/调用日志
message ReceiptEVMContractCmd {
    string caller = 1;
    // 合约创建时才会返回此内容
    string contractName = 2;
    string contractAddr = 3;
    uint64 usedGas      = 4;
    // 创建合约返回的代码
    string ret = 5;
}

message CheckEVMAddrReq {
    string addr = 1;
}
message CheckEVMAddrResp {
    bool   contract     = 1;
    string contractAddr = 2;
    string contractName = 3;
    string aliasName    = 4;
}

message EstimateEVMGasReq {
    string tx     = 1;
    string from   = 2;
}
message EstimateEVMGasResp {
    uint64 gas = 1;
}

message EvmDebugReq {
    // 0 query, 1 set, -1 clear
    int32 optype = 1;
}

message EvmDebugResp {
    string debugStatus = 1;
}

message EvmQueryAbiReq {
    string address = 1;
}

message EvmQueryAbiResp {
    string address = 1;
    string abi     = 2;
}

message EvmQueryReq {
    string address = 1;
    string input   = 2;
    string caller  = 3;
}

message EvmQueryResp {
    string address  = 1;
    string input    = 2;
    string caller   = 3;
    string rawData  = 4;
    string jsonData = 5;
}

message EvmContractCreateReq {
    string code     = 1;
    string abi      = 2;
    int64  fee      = 3;
    string note     = 4;
    string alias    = 5;
    string parameter= 6;
    string expire   = 7;
    string paraName = 8;
    int64 amount    = 9;
}

message EvmContractCallReq {
    int64 amount        = 1;
    int64  fee          = 2;
    string note          = 3;
    string parameter     = 4;
    string contractAddr  = 5;
    string expire        = 6;
    string paraName      = 7;
    string abi           = 8;
}

message EvmTransferOnlyReq {
    string to         = 1;
    int64  amount     = 2;
    string paraName   = 3;
    string note       = 4;
}

message EvmGetNonceReq {
    string address     = 1;
}

message EvmGetNonceRespose {
    int64 nonce     = 1;
}

message EvmCalcNewContractAddrReq {
    string caller     = 1;
    string txhash     = 2;
}

message EvmGetPackDataReq {
    string abi          = 1;
    string parameter    = 2;
}

message EvmGetPackDataRespose {
    string packData     = 1;
}

message EvmGetUnpackDataReq {
    string abi          = 1;
    string parameter    = 2;
    string data         = 3;
}

message EvmGetUnpackDataRespose {
    repeated string unpackData     = 1;
}

