forked from umbracle/ethgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
net.go
36 lines (31 loc) · 826 Bytes
/
net.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
package jsonrpc
// Net is the net namespace
type Net struct {
c *Client
}
// Net returns the reference to the net namespace
func (c *Client) Net() *Net {
return c.endpoints.n
}
// Version returns the current network id
func (n *Net) Version() (uint64, error) {
var out string
if err := n.c.Call("net_version", &out); err != nil {
return 0, err
}
return parseUint64orHex(out)
}
// Listening returns true if client is actively listening for network connections
func (n *Net) Listening() (bool, error) {
var out bool
err := n.c.Call("net_listening", &out)
return out, err
}
// PeerCount returns number of peers currently connected to the client
func (n *Net) PeerCount() (uint64, error) {
var out string
if err := n.c.Call("net_peerCount", &out); err != nil {
return 0, err
}
return parseUint64orHex(out)
}