-
Notifications
You must be signed in to change notification settings - Fork 1
/
node_info.go
110 lines (95 loc) · 2.35 KB
/
node_info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package core
import (
"encoding/json"
)
const (
// NodeUndefined ...
NodeUndefined NodeType = 0x00
// NodeAccount ...
NodeAccount NodeType = 0x01
// NodeAccelerate ...
NodeAccelerate NodeType = 0x02
// NodeRoute ...
NodeRoute NodeType = 0x03
)
// NodeType ...
type NodeType int
// DataStoreInfo ...
type DataStoreInfo struct {
ID string `json:"ID"`
PublicKey string `json:"PublicKey"`
Addresses []string `json:"Addresses"`
AgentVersion string `json:"AgentVersion"`
ProtocolVersion string `json:"ProtocolVersion"`
}
// ContractInfo ...
type ContractInfo struct {
Enode string `json:"enode"`
Enr string `json:"enr"`
ID string `json:"id"`
IP string `json:"ip"`
ListenAddr string `json:"listenAddr"`
Name string `json:"name"`
Ports Ports `json:"ports"`
Protocols Protocols `json:"protocols"`
}
// Ports ...
type Ports struct {
Discovery int64 `json:"discovery"`
Listener int64 `json:"listener"`
}
// Protocols ...
type Protocols struct {
Eth Eth `json:"eth"`
}
// Eth ...
type Eth struct {
Config Config `json:"config"`
Difficulty int64 `json:"difficulty"`
Genesis string `json:"genesis"`
Head string `json:"head"`
Network int64 `json:"network"`
}
// Config ...
type Config struct {
ByzantiumBlock int64 `json:"byzantiumBlock"`
ChainID int64 `json:"chainId"`
Clique Clique `json:"clique"`
ConstantinopleBlock int64 `json:"constantinopleBlock"`
Eip150Block int64 `json:"eip150Block"`
Eip150Hash string `json:"eip150Hash"`
Eip155Block int64 `json:"eip155Block"`
Eip158Block int64 `json:"eip158Block"`
HomesteadBlock int64 `json:"homesteadBlock"`
}
// Clique ...
type Clique struct {
Epoch int64 `json:"epoch"`
Period int64 `json:"period"`
}
// NodeInfo ...
type NodeInfo struct {
AddrInfo
AgentVersion string
ProtocolVersion string
}
// Unmarshal ...
func (i *NodeInfo) Unmarshal(bytes []byte) error {
return json.Unmarshal(bytes, i)
}
// Marshal ...
func (i NodeInfo) Marshal() ([]byte, error) {
return json.Marshal(i)
}
// JSON ...
func (i *NodeInfo) JSON() string {
marshal, err := json.MarshalIndent(i, "", " ")
if err != nil {
return ""
}
return string(marshal)
}
// CompareInt ...
func (t NodeType) CompareInt(i int) bool {
return int(t) == i
}