OSDN Git Service

710f001679a36d3a4332031b0b26f74f875254fb
[bytom/bytom.git] / blockchain / rpc / types / responses.go
1 package core_types
2
3 import (
4         "strings"
5         "time"
6
7         "github.com/tendermint/go-crypto"
8         "github.com/tendermint/go-wire/data"
9
10         "github.com/bytom/p2p"
11         "github.com/bytom/protocol/bc"
12 )
13
14 type BlockNonce [8]byte
15
16 type ResultBlockchainInfo struct {
17         LastHeight uint64 `json:"last_height"`
18 }
19
20 type ResultBlock struct {
21 }
22
23 type ResultStatus struct {
24         NodeInfo          *p2p.NodeInfo `json:"node_info"`
25         PubKey            crypto.PubKey `json:"pub_key"`
26         LatestBlockHash   data.Bytes    `json:"latest_block_hash"`
27         LatestAppHash     data.Bytes    `json:"latest_app_hash"`
28         LatestBlockHeight int           `json:"latest_block_height"`
29         LatestBlockTime   int64         `json:"latest_block_time"` // nano
30 }
31
32 func (s *ResultStatus) TxIndexEnabled() bool {
33         if s == nil || s.NodeInfo == nil {
34                 return false
35         }
36         for _, s := range s.NodeInfo.Other {
37                 info := strings.Split(s, "=")
38                 if len(info) == 2 && info[0] == "tx_index" {
39                         return info[1] == "on"
40                 }
41         }
42         return false
43 }
44
45 type ResultNetInfo struct {
46         Listening bool     `json:"listening"`
47         Listeners []string `json:"listeners"`
48         Peers     []Peer   `json:"peers"`
49 }
50
51 type ResultBlockHeaderInfo struct {
52         Version int32 `json:"version"`
53         //Height uint64    `json:"height"`
54         MerkleRoot        bc.Hash   `json:"merkleroot"`
55         PreviousBlockHash bc.Hash   `json:"prevblockhash"`
56         TimestampMS       time.Time `json:"timestamp"`
57         Bits              uint64    `json:"bits"`
58         Nonce             uint64    `json:"nonce"`
59 }
60
61 type ResultDialSeeds struct {
62         Log string `json:"log"`
63 }
64
65 type Peer struct {
66         p2p.NodeInfo     `json:"node_info"`
67         IsOutbound       bool                 `json:"is_outbound"`
68         ConnectionStatus p2p.ConnectionStatus `json:"connection_status"`
69 }