OSDN Git Service

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