syntax = "proto3";

import "transaction.proto";
import "common.proto";
import "blockchain.proto";
import "executor.proto";

package types;

// stateDB
message ParacrossStatusDetails {
    repeated string addrs    = 1;
    repeated bytes blockHash = 2;
}

message ParacrossHeightStatus {
    // ing, done
    int32                  status  = 1;
    string                 title   = 2;
    int64                  height  = 3;
    ParacrossStatusDetails details = 4;
    int64                  mainHeight    = 5;
    bytes                  mainHash      = 6;
}

message ParacrossHeightStatusRsp {
    int32                  status  = 1;
    string                 title   = 2;
    int64                  height  = 3;
    int64                  mainHeight    = 4;
    string                 mainHash      = 5;
    repeated string        commitAddrs    = 6;
    repeated string        commitBlockHash = 7;

}

message ParacrossStatus {
    string title     = 1;
    int64  height    = 2;
    bytes  blockHash = 3;
}

message ParacrossConsensusStatus {
    string title            = 1;
    int64  chainHeight      = 2;
    int64  consensHeight    = 3;
    string consensBlockHash = 4;
}

message ParaNodeAddrConfig {
    string title                = 1;
    uint32 op                   = 2;
    string id                   = 3;
    string addr                 = 4;
    uint32 value                = 5;
    int64  coinsFrozen          = 6;

}

message ParaNodeVoteDetail {
    repeated string addrs      = 1;
    repeated string votes      = 2;
}

message ParaNodeAddrIdStatus {
    string addr                 = 1;
    string proposalId           = 2;
    string quitId               = 3;
    int32  status               = 4;
    string title                = 5;
}

message ParaNodeIdStatus {
    string id                   = 1;
    int32  status               = 2;
    string title                = 3;
    string targetAddr           = 4;
    int64  coinsFrozen          = 5;
    ParaNodeVoteDetail votes    = 6;
    string fromAddr             = 7;
    int64  height               = 8;
}


message ReceiptParaNodeConfig {
    string                addr    = 1;
    ParaNodeAddrConfig    config  = 2;
    ParaNodeIdStatus      prev    = 3;
    ParaNodeIdStatus      current = 4;
}

message ReceiptParaNodeAddrStatUpdate {
    string                    fromAddr = 1;
    ParaNodeAddrIdStatus      prev     = 2;
    ParaNodeAddrIdStatus      current  = 3;
}

message ReceiptParaNodeVoteDone {
    string id               = 1;
    string title            = 2;
    string targetAddr       = 3;
    int32  totalNodes       = 4;
    int32  totalVote        = 5;
    int32  mostVote         = 6;
    string voteRst          = 7;
    int32  doneStatus       = 8;

}

message ParaNodeGroupConfig {
    string title                = 1;
    uint32 op                   = 2;
    string id                   = 3;
    string addrs                = 4;
    int64  coinsFrozen          = 5;
}


message ParaNodeGroupStatus {
    string id                   = 1;
    int32  status               = 2;
    string title                = 3;
    string targetAddrs          = 4;
    int64  coinsFrozen          = 5;
    string fromAddr             = 6;
    int64  height               = 7;
}

message ReceiptParaNodeGroupConfig {
    string                 addr    = 1;
    ParaNodeGroupConfig    config  = 2;
    ParaNodeGroupStatus    prev    = 3;
    ParaNodeGroupStatus    current = 4;
}


// node query
message ReqParacrossNodeInfo {
    string title  = 1;
    string id     = 2;
    string addr   = 3;
    int32  status = 4;

}

message RespParacrossNodeAddrs {
    repeated ParaNodeIdStatus ids = 1;
}

message RespParacrossNodeGroups {
    repeated ParaNodeGroupStatus ids = 1;
}

message ParaBlock2MainMap {
    int64  height     = 1;
    string blockHash  = 2;
    int64  mainHeight = 3;
    string mainHash   = 4;
}

message ParaBlock2MainInfo {
    repeated ParaBlock2MainMap items = 1;
}

// action
message ParacrossNodeStatus {
    bytes    mainBlockHash       = 1;
    int64    mainBlockHeight     = 2;
    string   title               = 3;
    int64    height              = 4;
    bytes    preBlockHash        = 5;
    bytes    blockHash           = 6;
    bytes    preStateHash        = 7;
    bytes    stateHash           = 8;
    uint32   txCounts            = 9;
    bytes    txResult            = 10;
    repeated bytes txHashs       = 11;
    bytes          crossTxResult = 12;
    repeated bytes crossTxHashs  = 13;
    uint32   nonCommitTxCounts   = 14;
}

message ParacrossCommitAction {
    ParacrossNodeStatus status = 1;
}

message ParacrossMinerAction {
    ParacrossNodeStatus status = 1;
    bool       isSelfConsensus = 2;
}

message ParacrossAction {
    oneof value {
        ParacrossCommitAction commit         = 1;
        ParacrossMinerAction  miner          = 3;
        AssetsTransfer        assetTransfer  = 4;
        AssetsWithdraw        assetWithdraw  = 5;
        AssetsTransfer        transfer       = 6;
        AssetsWithdraw        withdraw       = 7;
        AssetsTransferToExec  transferToExec = 8;
        ParaNodeAddrConfig    nodeConfig     = 9;
        ParaNodeGroupConfig   nodeGroupConfig = 10;


    }
    int32 ty = 2;
}

// logs
message ReceiptParacrossCommit {
    string                addr    = 1;
    ParacrossNodeStatus   status  = 2;
    ParacrossHeightStatus prev    = 3;
    ParacrossHeightStatus current = 4;
}

message ReceiptParacrossMiner {
    ParacrossNodeStatus status = 1;
}

message ReceiptParacrossDone {
    int32  totalNodes     = 1;
    int32  totalCommit    = 2;
    int32  mostSameCommit = 3;
    string title          = 4;
    int64  height         = 5;
    bytes  stateHash      = 6;
    uint32 txCounts       = 7;
    bytes  txResult       = 8;
}

message ReceiptParacrossRecord {
    string              addr   = 1;
    ParacrossNodeStatus status = 2;
}

// LocalDB
// title-height-addr : txHash
message ParacrossTx {
    string txHash = 1;
}

// query
message ReqParacrossTitleHeight {
    string title  = 1;
    int64  height = 2;
}

message RespParacrossDone {
    int32  totalNodes     = 1;
    int32  totalCommit    = 2;
    int32  mostSameCommit = 3;
    string title          = 4;
    int64  height         = 5;
    string stateHash      = 6;
    uint32 txCounts       = 7;
    string txResult       = 8;
}

message RespParacrossTitles {
    repeated RespParacrossDone titles = 1;
}

message ReqParacrossTitleHash {
    string title        = 1;
    bytes  blockHash    = 2;
}

// 跨链转账相关
message ParacrossAsset {
    // input
    string from       = 1;
    string to         = 2;
    bool   isWithdraw = 3;
    bytes  txHash     = 4;
    int64  amount     = 5;
    string exec       = 6;
    string symbol     = 7;
    // 主链部分
    int64 height = 10;
    // 平行链部分
    int64 commitDoneHeight = 21;
    int64 paraHeight       = 22;
    bool  success          = 23;
}



service paracross {
    rpc GetTitle(ReqString) returns (ParacrossConsensusStatus) {}
    rpc ListTitles(ReqNil) returns (RespParacrossTitles) {}
    rpc GetDoneTitleHeight(ReqParacrossTitleHeight) returns (RespParacrossDone) {}
    rpc GetTitleHeight(ReqParacrossTitleHeight) returns (ParacrossHeightStatusRsp) {}
    rpc GetAssetTxResult(ReqHash) returns (ParacrossAsset) {}
    rpc IsSync(ReqNil) returns (IsCaughtUp) {}
}