From b482a72960551fd39c30ab5ee6f7905adce01543 Mon Sep 17 00:00:00 2001 From: ramil Date: Wed, 10 May 2017 21:00:13 +0300 Subject: [PATCH 1/2] NetRPCService service: * version from config * `listening` and `peerCount` API --- ethereum/api.go | 32 ++++++++++++++++++++++++++++++++ ethereum/backend.go | 15 +-------------- 2 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 ethereum/api.go diff --git a/ethereum/api.go b/ethereum/api.go new file mode 100644 index 0000000000..d95d23c15b --- /dev/null +++ b/ethereum/api.go @@ -0,0 +1,32 @@ +package ethereum + +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` + +type NetRPCService struct { + networkVersion int +} + +// NewNetRPCService creates a new net API instance. +func NewNetRPCService(networkVersion int) *NetRPCService { + return &NetRPCService{networkVersion} +} + +// Listening returns an indication if the node is listening for network connections. +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(0) +} + +// Version returns the current ethereum protocol version. +func (n *NetRPCService) Version() string { + return fmt.Sprintf("%d", n.networkVersion) +} diff --git a/ethereum/backend.go b/ethereum/backend.go index 1a1ffb1034..d1e3413685 100644 --- a/ethereum/backend.go +++ b/ethereum/backend.go @@ -1,7 +1,6 @@ package ethereum import ( - "fmt" "math/big" "github.com/ethereum/go-ethereum/common" @@ -104,8 +103,7 @@ func (s *Backend) APIs() []rpc.API { retApis := []rpc.API{} for _, v := range apis { if v.Namespace == "net" { - networkVersion := 1 // TODO: this should come from a flag - v.Service = &NetRPCService{networkVersion} + v.Service = NewNetRPCService(s.config.NetworkId) } if v.Namespace == "miner" { continue @@ -138,17 +136,6 @@ func (s *Backend) Protocols() []p2p.Protocol { return nil } -//---------------------------------------------------------------------- -// We must implement our own net service since we don't have access to `internal/ethapi` - -type NetRPCService struct { - networkVersion int -} - -func (n *NetRPCService) Version() string { - return fmt.Sprintf("%d", n.networkVersion) -} - //---------------------------------------------------------------------- // We need a block processor that just ignores PoW and uncles and so on From 6ead06dd5f9102faf3539bf3acb272dded2ab842 Mon Sep 17 00:00:00 2001 From: ramil Date: Mon, 15 May 2017 03:13:15 +0300 Subject: [PATCH 2/2] s to n --- ethereum/api.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ethereum/api.go b/ethereum/api.go index d95d23c15b..e51033df4e 100644 --- a/ethereum/api.go +++ b/ethereum/api.go @@ -17,12 +17,12 @@ func NewNetRPCService(networkVersion int) *NetRPCService { } // Listening returns an indication if the node is listening for network connections. -func (s *NetRPCService) Listening() bool { +func (n *NetRPCService) Listening() bool { return true // always listening } // PeerCount returns the number of connected peers -func (s *NetRPCService) PeerCount() hexutil.Uint { +func (n *NetRPCService) PeerCount() hexutil.Uint { return hexutil.Uint(0) }