OSDN Git Service

pow
[bytom/bytom.git] / rpc / core / types / responses.go
1 package core_types
2
3 import (
4         "strings"
5
6         abci "github.com/tendermint/abci/types"
7         "github.com/tendermint/go-crypto"
8         "github.com/tendermint/go-wire/data"
9         "github.com/blockchain/protocol/bc"
10         "github.com/blockchain/p2p"
11         "github.com/blockchain/types"
12 )
13
14 type BlockNonce [8]byte
15
16 type ResultBlockchainInfo struct {
17         LastHeight int                `json:"last_height"`
18         BlockMetas []*types.BlockMeta `json:"block_metas"`
19 }
20
21 type ResultGenesis struct {
22         Genesis *types.GenesisDoc `json:"genesis"`
23 }
24
25 type ResultBlock struct {
26         BlockMeta *types.BlockMeta `json:"block_meta"`
27         Block     *types.Block     `json:"block"`
28 }
29
30 type ResultCommit struct {
31         Header          *types.Header `json:"header"`
32         Commit          *types.Commit `json:"commit"`
33         CanonicalCommit bool          `json:"canonical"`
34 }
35
36 type ResultStatus struct {
37         NodeInfo          *p2p.NodeInfo `json:"node_info"`
38         PubKey            crypto.PubKey `json:"pub_key"`
39         LatestBlockHash   data.Bytes    `json:"latest_block_hash"`
40         LatestAppHash     data.Bytes    `json:"latest_app_hash"`
41         LatestBlockHeight int           `json:"latest_block_height"`
42         LatestBlockTime   int64         `json:"latest_block_time"` // nano
43 }
44
45 func (s *ResultStatus) TxIndexEnabled() bool {
46         if s == nil || s.NodeInfo == nil {
47                 return false
48         }
49         for _, s := range s.NodeInfo.Other {
50                 info := strings.Split(s, "=")
51                 if len(info) == 2 && info[0] == "tx_index" {
52                         return info[1] == "on"
53                 }
54         }
55         return false
56 }
57
58 type ResultNetInfo struct {
59         Listening bool     `json:"listening"`
60         Listeners []string `json:"listeners"`
61         Peers     []Peer   `json:"peers"`
62 }
63
64 type ResultBlockHeaderInfo struct {
65         Version uint64   `json:"version"`
66         Height uint64    `json:"height"`
67         MerkleRoot bc.Hash  `json:"merkleroot"`
68         PreviousBlockHash bc.Hash  `json:"prevblockhash"`
69         TimestampMS uint64   `json:"timestamp"`
70         Bits uint64      `json:"bits"`
71         Nonce uint64     `json:"nonce"`
72 }
73
74 type ResultDialSeeds struct {
75         Log string `json:"log"`
76 }
77
78 type Peer struct {
79         p2p.NodeInfo     `json:"node_info"`
80         IsOutbound       bool                 `json:"is_outbound"`
81         ConnectionStatus p2p.ConnectionStatus `json:"connection_status"`
82 }
83
84 type ResultValidators struct {
85         BlockHeight int                `json:"block_height"`
86         Validators  []*types.Validator `json:"validators"`
87 }
88
89 type ResultDumpConsensusState struct {
90         RoundState      string   `json:"round_state"`
91         PeerRoundStates []string `json:"peer_round_states"`
92 }
93
94 type ResultBroadcastTx struct {
95         Code abci.CodeType `json:"code"`
96         Data data.Bytes    `json:"data"`
97         Log  string        `json:"log"`
98
99         Hash data.Bytes `json:"hash"`
100 }
101
102 type ResultBroadcastTxCommit struct {
103         CheckTx   abci.Result `json:"check_tx"`
104         DeliverTx abci.Result `json:"deliver_tx"`
105         Hash      data.Bytes  `json:"hash"`
106         Height    int         `json:"height"`
107 }
108
109 type ResultTx struct {
110         Height   int           `json:"height"`
111         Index    int           `json:"index"`
112         TxResult abci.Result   `json:"tx_result"`
113         Tx       types.Tx      `json:"tx"`
114         Proof    types.TxProof `json:"proof,omitempty"`
115 }
116
117 type ResultUnconfirmedTxs struct {
118         N   int        `json:"n_txs"`
119         Txs []types.Tx `json:"txs"`
120 }
121
122 type ResultABCIInfo struct {
123         Response abci.ResponseInfo `json:"response"`
124 }
125
126 type ResultABCIQuery struct {
127         *abci.ResultQuery `json:"response"`
128 }
129
130 type ResultUnsafeFlushMempool struct{}
131
132 type ResultUnsafeProfile struct{}
133
134 type ResultSubscribe struct{}
135
136 type ResultUnsubscribe struct{}
137
138 type ResultEvent struct {
139         Name string            `json:"name"`
140         Data types.TMEventData `json:"data"`
141 }