syntax = "proto3";

package types;

import "common.proto";
import "transaction.proto";

//////////////////////////////////////////////////////////////////////////////
// message for Privacy
// start/////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
message PrivacyAction {
    oneof value {
        Public2Privacy  public2privacy  = 1;
        Privacy2Privacy privacy2privacy = 2;
        Privacy2Public  privacy2public  = 3;
    }
    int32 ty = 4;
}

message Public2Privacy {
    string        tokenname = 1;
    int64         amount    = 2;
    string        note      = 5;
    PrivacyOutput output    = 7;
    string        assetExec = 8;
}

message Privacy2Privacy {
    string        tokenname = 1;
    int64         amount    = 2;
    string        note      = 5;
    PrivacyInput  input     = 6;
    PrivacyOutput output    = 7;
    string        assetExec = 8;
}

message Privacy2Public {
    string        tokenname = 1;
    int64         amount    = 2;
    string        note      = 3;
    string        to        = 6;
    PrivacyInput  input     = 4;
    PrivacyOutput output    = 5;
    string        assetExec = 8;
}

message UTXOGlobalIndex {
    //	int64 height   = 1;
    //	int32 txindex  = 2;
    bytes txhash   = 3;
    int32 outindex = 4;
}

// privacy input
message KeyInput {
    int64    amount                          = 1;
    repeated UTXOGlobalIndex utxoGlobalIndex = 2;
    bytes                    keyImage        = 3;
}

message PrivacyInput {
    repeated KeyInput keyinput = 1;
}

// privacy output
message keyOutput {
    int64 amount        = 1;
    bytes onetimepubkey = 2;
}

message PrivacyOutput {
    bytes    RpubKeytx           = 1;
    repeated keyOutput keyoutput = 2;
}

message GroupUTXOGlobalIndex {
    int64    amount                          = 1;
    repeated UTXOGlobalIndex utxoGlobalIndex = 2;
}

message LocalUTXOItem {
    int64 height        = 1;
    int32 txindex       = 2;
    int32 outindex      = 3;
    bytes txhash        = 4;
    bytes onetimepubkey = 5;
}

message ReqUTXOPubKeys {
    string   tokenName                                 = 1;
    repeated GroupUTXOGlobalIndex groupUTXOGlobalIndex = 2;
}

// 一个公钥信息
message PublicKeyData {
    repeated bytes data = 1;
}

message GroupUTXOPubKey {
    int64 amount = 1;
    // 输出签名的所有公钥
    repeated bytes pubkey = 2;
}

message ResUTXOPubKeys {
    repeated GroupUTXOPubKey groupUTXOPubKeys = 1;
}

message ReqPrivacyToken {
    string assetExec   = 1;
    string assetSymbol = 2;
    int64  amount      = 3;
}

message AmountDetail {
    int64 amount = 1;
    int64 count  = 2;
}

message ReplyPrivacyAmounts {
    repeated AmountDetail amountDetail = 1;
}

message replyUTXOsOfAmount {
    repeated LocalUTXOItem localUTXOItems = 1;
}

message ReceiptPrivacyOutput {
    string   assetExec           = 1;
    string   assetSymbol         = 2;
    repeated keyOutput keyoutput = 3;
}
//各种amount额度的UTXO在链上的数量
message AmountsOfUTXO {
    map<int64, int64> amountMap = 1;
}

message TokenNamesOfUTXO {
    map<string, string> tokensMap = 1;
}

// 用以转换成json后继续可见的结构
message UTXOGlobalIndex4Print {
    string txhash   = 1;
    int32  outindex = 2;
}

message KeyInput4Print {
    int64    amount                                = 1;
    repeated UTXOGlobalIndex4Print utxoGlobalIndex = 2;
    string                         keyImage        = 3;
}

message keyOutput4Print {
    int64  amount        = 1;
    string onetimepubkey = 2;
}

message PrivacyInput4Print {
    repeated KeyInput4Print keyinput = 1;
}

message PrivacyOutput4Print {
    string   RpubKeytx                 = 1;
    repeated keyOutput4Print keyoutput = 2;
}

message Public2Privacy4Print {
    string              tokenname = 1;
    int64               amount    = 2;
    string              note      = 5;
    PrivacyOutput4Print output    = 7;
}

message Privacy2Privacy4Print {
    string              tokenname = 1;
    int64               amount    = 2;
    string              note      = 5;
    PrivacyInput4Print  input     = 6;
    PrivacyOutput4Print output    = 7;
}

message Privacy2Public4Print {
    string              tokenname = 1;
    int64               amount    = 2;
    string              note      = 3;
    PrivacyInput4Print  input     = 4;
    PrivacyOutput4Print output    = 5;
}

message PrivacyAction4Print {
    oneof value {
        Public2Privacy4Print  public2privacy  = 1;
        Privacy2Privacy4Print privacy2privacy = 2;
        Privacy2Public4Print  privacy2public  = 3;
    }
    int32 ty = 4;
}

message ReplyPrivacyPkPair {
    bool showSuccessful = 1;
    // string viewPub       = 2;
    // string spendPub      = 3;
    string pubkeypair = 4;
}

message ReqPrivBal4AddrToken {
    string addr      = 1;
    string token     = 2;
    string assetExec = 3;
}

message ReplyPrivacyBalance {
    string onetimeaddr = 1;
    int64  balance     = 2;
}

message PrivacyDBStore {
    bytes  txhash           = 1;
    string tokenname        = 2;
    int64  amount           = 3;
    int32  outIndex         = 4;
    bytes  txPublicKeyR     = 5;
    bytes  onetimePublicKey = 6;
    string owner            = 7;
    int64  height           = 8;
    int32  txindex          = 9;
    bytes  blockhash        = 10;
    string assetExec        = 11;
}

message UTXO {
    int64     amount    = 1;
    UTXOBasic utxoBasic = 2;
}
message UTXOHaveTxHash {
    int64     amount    = 1;
    string    txHash    = 2;
    UTXOBasic utxoBasic = 3;
}

message UTXOs {
    repeated UTXO utxos = 1;
}

message UTXOHaveTxHashs {
    repeated UTXOHaveTxHash utxoHaveTxHashs = 1;
}

message ReqUTXOGlobalIndex {
    string   assetExec    = 1;
    string   assetSymbol  = 2;
    int32    mixCount     = 3;
    repeated int64 amount = 4;
}

message UTXOBasic {
    UTXOGlobalIndex utxoGlobalIndex = 1;
    bytes           onetimePubkey   = 2;
}

message UTXOIndex4Amount {
    int64    amount          = 1;
    repeated UTXOBasic utxos = 2;
}

message ResUTXOGlobalIndex {
    repeated UTXOIndex4Amount utxoIndex4Amount = 3;
}

message FTXOsSTXOsInOneTx {
    string tokenname = 1;
    string sender    = 2;
    // FTXO的超期，设定原则与Transaction.expire一致
    int64    expire         = 3;
    string   txhash         = 4;
    repeated UTXO utxos     = 5;
    string        assetExec = 6;
}

message RealKeyInput {
    int32 realinputkey   = 1;
    bytes onetimeprivkey = 2;
}

message UTXOBasics {
    repeated UTXOBasic utxos = 1;
}

message CreateTransactionCache {
    bytes key = 1;
    // 记录创建时间，用以处理过期的交易
    int64 createtime = 2;
    // 记录签名成功的时间，用以处理过期交易
    int64 signtime = 3;
    // 缓存状态
    // 0 - 创建状态
    // 1 - 已经签名状态
    int32 status = 4;
    //
    Transaction transaction = 5;

    string   sender                    = 6;
    repeated RealKeyInput realkeyinput = 7;
    repeated UTXOBasics utxos          = 8;
    string              tokenname      = 9;
}

message ReqCacheTxList {
    string addr      = 1;
    string tokenname = 2;
}

message ReplyCacheTxList {
    repeated Transaction txs = 1;
}

message ReqPrivacyAccount {
    string addr  = 1;
    string token = 2;
    // 设定显示的数据类型信息
    // 0： 只显示账户的数值信息
    // 1： 显示UTXO明细
    // 2： 显示FTXO明细
    // 3： 全部显示
    int32  displaymode = 3;
    string assetExec   = 4;
}

// 请求隐私账户信息的应答
message ReplyPrivacyAccount {
    // 未花费的UTXO
    UTXOs utxos = 1;
    // 冻结的UTXO
    UTXOs ftxos       = 2;
    int32 displaymode = 3;
}

message ReqCreateCacheTxKey {
    string tokenname = 1;
    bytes  hashkey   = 2;
}

// get privacy transaction list in wallet
message ReqPrivacyTransactionList {
    // support BTY
    string tokenname = 1;
    // 1:sendtx  2:recvtx
    int32  sendRecvFlag = 2;
    int32  direction    = 3;
    int32  count        = 4;
    string from         = 5;
    string address      = 6;
    bytes  seedtxhash   = 7;
    string assetExec    = 8;
}

message ReqRescanUtxos {
    repeated string addrs = 1;
    int32           flag  = 2;
}

message RepRescanResult {
    string addr = 1;
    int32  flag = 2;
}

message RepRescanUtxos {
    int32    flag                             = 1;
    repeated RepRescanResult repRescanResults = 2;
}

message ReqEnablePrivacy {
    repeated string addrs = 2;
}

message PriAddrResult {
    string addr = 1;
    bool   IsOK = 2;
    string msg  = 3;
}

message RepEnablePrivacy {
    repeated PriAddrResult results = 1;
}

// 隐私交易三步发送时，临时存储签名需要的数据信息结构
message PrivacySignatureParam {
    int32    actionType                 = 1;
    repeated UTXOBasics utxobasics      = 2;
    repeated RealKeyInput realKeyInputs = 3;
}

message WalletAccountPrivacy {
    bytes viewPubkey   = 1;
    bytes viewPrivKey  = 2;
    bytes spendPubkey  = 3;
    bytes spendPrivKey = 4;
}

// 创建隐私交易请求
message ReqCreatePrivacyTx {
    string tokenname = 1;
    // 构建交易类型
    int32  actionType = 2;
    int64  amount     = 3;
    string note       = 4;
    // 普通交易的发送方
    string from = 5;
    // 普通交易的接收方
    string to = 6;
    // 隐私交易，接收方的公钥对
    string pubkeypair = 10;
    int32  mixcount   = 11;
    int64  expire     = 12;
    string assetExec  = 13;
}

service privacy {
    // Privacy Trading
    // 显示指定地址的公钥对信息，可以作为后续交易参数
    rpc ShowPrivacyKey(ReqString) returns (ReplyPrivacyPkPair) {}
    // 扫描UTXO以及获取扫描UTXO后的状态
    rpc RescanUtxos(ReqRescanUtxos) returns (RepRescanUtxos) {}
    // 使能隐私账户
    rpc EnablePrivacy(ReqEnablePrivacy) returns (RepEnablePrivacy) {}
    // 创建隐私交易
    rpc CreateRawTransaction(ReqCreatePrivacyTx) returns (Transaction) {}
}
