syntax = "proto3";

import "common.proto";

package types;
option go_package = "github.com/33cn/chain33/types";

// assert transfer struct
message AssetsGenesis {
    int64  amount        = 2;
    string returnAddress = 3;
}

message AssetsTransferToExec {
    string cointoken = 1;
    int64  amount    = 2;
    bytes  note      = 3;
    string execName  = 4;
    string to        = 5;
}

message AssetsWithdraw {
    string cointoken = 1;
    int64  amount    = 2;
    bytes  note      = 3;
    string execName  = 4;
    string to        = 5;
}

message AssetsTransfer {
    string cointoken = 1;
    int64  amount    = 2;
    bytes  note      = 3;
    string to        = 4;
}

message Asset {
    string exec   = 1;
    string symbol = 2;
    int64  amount = 3;
}

message CreateTx {
    string to          = 1;
    int64  amount      = 2;
    int64  fee         = 3;
    bytes  note        = 4;
    bool   isWithdraw  = 5;
    bool   isToken     = 6;
    string tokenSymbol = 7;
    string execName    = 8;
    string execer      = 9;
}

message ReWriteRawTx {
    string tx = 1;
    // bytes  execer = 2;
    string to     = 3;
    string expire = 4;
    int64  fee    = 5;
    int32  index  = 6;
}

message CreateTransactionGroup {
    repeated string txs = 1;
}

message UnsignTx {
    bytes data = 1;
}

// 支持构造多笔nobalance的交易 payAddr 可以支持 1. 地址 2. 私钥
message NoBalanceTxs {
    repeated string txHexs  = 1;
    string          payAddr = 2;
    string          privkey = 3;
    string          expire  = 4;
}

// payAddr 可以支持 1. 地址 2. 私钥
message NoBalanceTx {
    string txHex   = 1;
    string payAddr = 2;
    string privkey = 3;
    string expire  = 4;
}

message Transaction {
    bytes     execer    = 1;
    bytes     payload   = 2;
    Signature signature = 3;
    int64     fee       = 4;
    int64     expire    = 5;
    //随机ID，可以防止payload 相同的时候，交易重复
    int64 nonce = 6;
    //对方地址，如果没有对方地址，可以为空
    string to         = 7;
    int32  groupCount = 8;
    bytes  header     = 9;
    bytes  next       = 10;
}

message Transactions {
    repeated Transaction txs = 1;
}

// 环签名类型时，签名字段存储的环签名信息
message RingSignature {
    repeated RingSignatureItem items = 1;
}

// 环签名中的一组签名数据
message RingSignatureItem {
    repeated bytes pubkey    = 1;
    repeated bytes signature = 2;
}

//对于一个交易组中的交易，要么全部成功，要么全部失败
//这个要好好设计一下
//最好交易构成一个链条[prevhash].独立的交易构成链条
//只要这个组中有一个执行是出错的，那么就执行不成功
//三种签名支持
// ty = 1 -> secp256k1
// ty = 2 -> ed25519
// ty = 3 -> sm2
// ty = 4 -> OnetimeED25519
// ty = 5 -> RingBaseonED25519
message Signature {
    int32 ty     = 1;
    bytes pubkey = 2;
    //当ty为5时，格式应该用RingSignature去解析
    bytes signature = 3;
}

message AddrOverview {
    int64 reciver = 1;
    int64 balance = 2;
    int64 txCount = 3;
}

message ReqAddr {
    string addr = 1;
    //表示取所有/from/to/其他的hash列表
    int32 flag      = 2;
    int32 count     = 3;
    int32 direction = 4;
    int64 height    = 5;
    int64 index     = 6;
}

message ReqPrivacy {
    int32 count     = 1;
    int32 direction = 2;
    int64 height    = 3;
}

message HexTx {
    string tx = 1;
}

message ReplyTxInfo {
    bytes    hash         = 1;
    int64    height       = 2;
    int64    index        = 3;
    repeated Asset assets = 4;
}

message ReqTxList {
    int64 count = 1;
}

message ReplyTxList {
    repeated Transaction txs = 1;
}

message ReqGetMempool {
    bool isAll = 1;
}

message ReqProperFee {
    int32 txCount = 1;
    int32 txSize  = 2;
}

message ReplyProperFee {
    int64 properFee = 1;
}

message TxHashList {
    repeated bytes hashes = 1;
    int64          count  = 2;
    repeated int64 expire = 3;
}

message ReplyTxInfos {
    repeated ReplyTxInfo txInfos = 1;
}

message ReceiptLog {
    int32 ty  = 1;
    bytes log = 2;
}

// ty = 0 -> error Receipt
// ty = 1 -> CutFee //cut fee ,bug exec not ok
// ty = 2 -> exec ok
message Receipt {
    int32    ty              = 1;
    repeated KeyValue KV     = 2;
    repeated ReceiptLog logs = 3;
}

message ReceiptData {
    int32    ty              = 1;
    repeated ReceiptLog logs = 3;
}

message TxResult {
    int64       height      = 1;
    int32       index       = 2;
    Transaction tx          = 3;
    ReceiptData receiptdate = 4;
    int64       blocktime   = 5;
    string      actionName  = 6;
}

message TransactionDetail {
    Transaction tx            = 1;
    ReceiptData receipt       = 2;
    repeated bytes proofs     = 3;
    int64          height     = 4;
    int64          index      = 5;
    int64          blocktime  = 6;
    int64          amount     = 7;
    string         fromaddr   = 8;
    string         actionName = 9;
    repeated Asset assets     = 10;
}

message TransactionDetails {
    repeated TransactionDetail txs = 1;
}

message ReqAddrs {
    repeated string addrs = 1;
}

message ReqDecodeRawTransaction {
    string txHex = 1;
}

message UserWrite {
    string topic   = 1;
    string content = 2;
}

message UpgradeMeta {
    bool   starting = 1;
    string version  = 2;
    int64  height   = 3;
}

//通过交易hash获取交易列表，需要区分是短hash还是全hash值
message ReqTxHashList {
    repeated string hashes      = 1;
    bool            isShortHash = 2;
}
