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

import "common.proto";

message Ticket {
    string ticketId = 1;
    // 0 -> 未成熟 1 -> 可挖矿 2 -> 已挖成功 3-> 已关闭
    int32 status = 2;
    // genesis 创建的私钥比较特殊
    bool isGenesis = 3;
    //创建时间
    int64 createTime = 4;
    //挖矿时间
    int64 minerTime = 5;
    //挖到的币的数目
    int64  minerValue   = 8;
    string minerAddress = 6;
    // return wallet
    string returnAddress = 7;
    // miner Price
    int64 price = 9;
}

// message for execs.ticket
message TicketAction {
    oneof value {
        TicketBind    tbind   = 5;
        TicketOpen    topen   = 1;
        TicketGenesis genesis = 2;
        TicketClose   tclose  = 3;
        TicketMiner   miner   = 4;
    }
    int32 ty = 10;
}

message TicketMiner {
    uint32 bits     = 1;
    int64  reward   = 2;
    string ticketId = 3;
    bytes  modify   = 4;
    //挖到区块时公开
    bytes privHash = 5;
    // VRF计算得到的hash
    bytes vrfHash = 6;
    // VRF计算得到的proof
    bytes vrfProof = 7;
}

message TicketMinerOld {
    uint32 bits     = 1;
    int64  reward   = 2;
    string ticketId = 3;
    bytes  modify   = 4;
}

message MinerFlag {
    int32 flag    = 1;
    int64 reserve = 2;
}

message TicketBind {
    string minerAddress  = 1;
    string returnAddress = 2;
}

message TicketOpen {
    //用户挖矿的ticket 地址
    string minerAddress = 1;
    //购买ticket的数目
    int32 count = 2;
    //币实际存储的地址
    string returnAddress = 3;
    //随机种子
    int64 randSeed = 4;
    //购买ticket时公开
    repeated bytes pubHashes = 5;
}

message TicketGenesis {
    string minerAddress  = 1;
    string returnAddress = 2;
    int32  count         = 3;
}

message TicketClose {
    repeated string ticketId     = 1;
    string          minerAddress = 2;
}

message TicketList {
    string addr   = 1;
    int32  status = 3;
}

message TicketInfos {
    repeated string ticketIds = 1;
}

message ReplyTicketList {
    repeated Ticket tickets = 1;
}

message ReplyWalletTickets {
    repeated Ticket tickets = 1;
    repeated bytes privkeys = 2;
}

message ReceiptTicket {
    string ticketId   = 1;
    int32  status     = 2;
    int32  prevStatus = 3;
    string addr       = 4;
}

message ReceiptTicketBind {
    string oldMinerAddress = 1;
    string newMinerAddress = 2;
    string returnAddress   = 3;
}

message ReqBindMiner {
    string bindAddr     = 1;
    string originAddr   = 2;
    int64  amount       = 3;
    bool   checkBalance = 4;
}

message ReplyBindMiner {
    string txHex = 1;
}

service ticket {
    //创建绑定挖矿
    rpc CreateBindMiner(ReqBindMiner) returns (ReplyBindMiner) {}
    //查询钱包票数
    rpc GetTicketCount(types.ReqNil) returns (Int64) {}
    // Miner
    //设置自动挖矿
    rpc SetAutoMining(MinerFlag) returns (Reply) {}
}
