Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.

NetRPCService service #81

Merged
merged 3 commits into from
May 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions ethereum/api.go
Original file line number Diff line number Diff line change
@@ -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 (n *NetRPCService) Listening() bool {
return true // always listening
}

// PeerCount returns the number of connected peers
func (n *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)
}
15 changes: 1 addition & 14 deletions ethereum/backend.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ethereum

import (
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -109,8 +108,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
Expand Down Expand Up @@ -143,17 +141,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

Expand Down