syntax = "proto3";

import "transaction.proto";
import "account.proto";

package types;

// action
message TokenAction {
    oneof value {
        TokenPreCreate       tokenPreCreate    = 1;
        TokenFinishCreate    tokenFinishCreate = 2;
        TokenRevokeCreate    tokenRevokeCreate = 3;
        AssetsTransfer       transfer          = 4;
        AssetsWithdraw       withdraw          = 5;
        AssetsGenesis        genesis           = 6;
        AssetsTransferToExec transferToExec    = 8;
        TokenMint            tokenMint         = 9;
        TokenBurn            tokenBurn         = 10;
    }
    int32 Ty = 7;
}

//创建token，支持最大精确度是8位小数,即存入数据库的实际总额需要放大1e8倍
message TokenPreCreate {
    string name         = 1;
    string symbol       = 2;
    string introduction = 3;
    int64  total        = 4;
    int64  price        = 5;
    string owner        = 6;
    int32  category     = 7;
}

message TokenFinishCreate {
    string symbol = 1;
    string owner  = 2;
}

message TokenRevokeCreate {
    string symbol = 1;
    string owner  = 2;
}

message TokenMint {
    string symbol = 1;
    int64  amount = 2;
}

message TokenBurn {
    string symbol = 1;
    int64  amount = 2;
}

// state db
message Token {
    string name         = 1;
    string symbol       = 2;
    string introduction = 3;
    int64  total        = 4;
    int64  price        = 5;
    string owner        = 6;
    string creator      = 7;
    int32  status       = 8;
    int32  category     = 9;
}

// log
message ReceiptToken {
    string symbol = 1;
    string owner  = 2;
    int32  status = 3;
}

message ReceiptTokenAmount {
    Token prev    = 1;
    Token current = 2;
}

// local
message LocalToken {
    string name                = 1;
    string symbol              = 2;
    string introduction        = 3;
    int64  total               = 4;
    int64  price               = 5;
    string owner               = 6;
    string creator             = 7;
    int32  status              = 8;
    int64  createdHeight       = 9;
    int64  createdTime         = 10;
    int64  prepareCreateHeight = 11;
    int64  prepareCreateTime   = 12;
    int32  precision           = 13;
    // 如果需要这个项可以单独做一个域存储
    int64 totalTransferTimes = 14;
    int64 revokedHeight      = 15;
    int64 revokedTime        = 16;
    int32 category           = 17;
}

message LocalLogs {
    string symbol     = 1;
    string txIndex    = 2;
    int32  actionType = 3;
    string txHash     = 4;
}

// query
message ReqTokens {
    bool     queryAll          = 1;
    int32    status            = 2;
    repeated string tokens     = 3;
    bool            symbolOnly = 4;
}

message ReplyTokens {
    repeated LocalToken tokens = 1;
}

message TokenRecv {
    string token = 1;
    int64  recv  = 2;
}
message ReplyAddrRecvForTokens {
    repeated TokenRecv tokenRecvs = 1;
}

message ReqTokenBalance {
    repeated string addresses   = 1;
    string          tokenSymbol = 2;
    string          execer      = 3;
}

message ReqAccountTokenAssets {
    string address = 1;
    string execer  = 2;
}

message TokenAsset {
    string  symbol  = 1;
    Account account = 2;
}

message ReplyAccountTokenAssets {
    repeated TokenAsset tokenAssets = 1;
}

message ReqAddrTokens {
    string   addr             = 1;
    int32    status           = 2;
    repeated string token     = 3;
    int32           direction = 4;
    int32           count     = 5;
    string          fromKey   = 6;
}

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

message ReplyTokenLogs {
    repeated LocalLogs logs = 1;
}

service token {
    // token 对外提供服务的接口
    //区块链接口
    rpc GetTokenBalance(ReqTokenBalance) returns (Accounts) {}
}