-
Notifications
You must be signed in to change notification settings - Fork 39
/
net.go
42 lines (34 loc) · 1 KB
/
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
37
38
39
40
41
42
package api
import (
"fmt"
"github.com/ethereum/go-ethereum/common/hexutil"
)
// We must implement our own net service since we don't have access to `internal/ethapi`
// NetRPCService mirrors the implementation of `internal/ethapi`
// #unstable
type NetRPCService struct {
backend *Backend
networkVersion uint64
}
// NewNetRPCService creates a new net API instance.
// #unstable
func NewNetRPCService(b *Backend) *NetRPCService {
return &NetRPCService{
backend: b,
networkVersion: b.ethConfig.NetworkId,
}
}
// Listening returns an indication if the node is listening for network connections.
// #unstable
func (s *NetRPCService) Listening() bool {
return true // always listening
}
// PeerCount returns the number of connected peers
func (s *NetRPCService) PeerCount() hexutil.Uint {
return hexutil.Uint(s.backend.PeerCount())
}
// Version returns the current ethereum protocol version.
// #unstable
func (s *NetRPCService) Version() string {
return fmt.Sprintf("%d", s.networkVersion)
}