aboutsummaryrefslogtreecommitdiffstats
path: root/node
diff options
context:
space:
mode:
authorBas van Kervel <bas@ethdev.com>2015-10-15 22:07:19 +0800
committerBas van Kervel <bas@ethdev.com>2015-12-14 23:34:05 +0800
commiteae81465c1c815c317cd30e4de6bdf4d59df2340 (patch)
treeb6f4b7787967a58416171adb79fd12ac29d89577 /node
parent8db9d44ca9fb6baf406256cae491c475de2f4989 (diff)
downloadgo-tangerine-eae81465c1c815c317cd30e4de6bdf4d59df2340.tar.gz
go-tangerine-eae81465c1c815c317cd30e4de6bdf4d59df2340.tar.zst
go-tangerine-eae81465c1c815c317cd30e4de6bdf4d59df2340.zip
rpc: new RPC implementation with pub/sub support
Diffstat (limited to 'node')
-rw-r--r--node/node.go10
-rw-r--r--node/node_example_test.go2
-rw-r--r--node/service.go4
-rw-r--r--node/utils_test.go6
4 files changed, 22 insertions, 0 deletions
diff --git a/node/node.go b/node/node.go
index 5566bc44b..d6debe123 100644
--- a/node/node.go
+++ b/node/node.go
@@ -27,6 +27,7 @@ import (
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/p2p"
+ rpc "github.com/ethereum/go-ethereum/rpc/v2"
)
var (
@@ -264,3 +265,12 @@ func (n *Node) DataDir() string {
func (n *Node) EventMux() *event.TypeMux {
return n.eventmux
}
+
+// RPCAPIs returns the collection of RPC descriptor this node offers
+func (n *Node) RPCAPIs() []rpc.API {
+ var apis []rpc.API
+ for _, api := range n.services {
+ apis = append(apis, api.APIs()...)
+ }
+ return apis
+}
diff --git a/node/node_example_test.go b/node/node_example_test.go
index 2f9b49a56..ef41dddaf 100644
--- a/node/node_example_test.go
+++ b/node/node_example_test.go
@@ -23,6 +23,7 @@ import (
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/discover"
+ rpc "github.com/ethereum/go-ethereum/rpc/v2"
)
// SampleService is a trivial network service that can be attached to a node for
@@ -35,6 +36,7 @@ import (
type SampleService struct{}
func (s *SampleService) Protocols() []p2p.Protocol { return nil }
+func (s *SampleService) APIs() []rpc.API { return nil }
func (s *SampleService) Start(*p2p.Server) error { fmt.Println("Service starting..."); return nil }
func (s *SampleService) Stop() error { fmt.Println("Service stopping..."); return nil }
diff --git a/node/service.go b/node/service.go
index bfeeb7ab9..b83d4c80d 100644
--- a/node/service.go
+++ b/node/service.go
@@ -23,6 +23,7 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/p2p"
+ rpc "github.com/ethereum/go-ethereum/rpc/v2"
)
// ServiceContext is a collection of service independent options inherited from
@@ -70,6 +71,9 @@ type Service interface {
// Protocol retrieves the P2P protocols the service wishes to start.
Protocols() []p2p.Protocol
+ // APIs retrieves the list of RPC descriptors the service provides
+ APIs() []rpc.API
+
// Start is called after all services have been constructed and the networking
// layer was also initialized to spawn any goroutines required by the service.
Start(server *p2p.Server) error
diff --git a/node/utils_test.go b/node/utils_test.go
index 756622c86..2b7bfadbe 100644
--- a/node/utils_test.go
+++ b/node/utils_test.go
@@ -23,12 +23,14 @@ import (
"reflect"
"github.com/ethereum/go-ethereum/p2p"
+ rpc "github.com/ethereum/go-ethereum/rpc/v2"
)
// NoopService is a trivial implementation of the Service interface.
type NoopService struct{}
func (s *NoopService) Protocols() []p2p.Protocol { return nil }
+func (s *NoopService) APIs() []rpc.API { return nil }
func (s *NoopService) Start(*p2p.Server) error { return nil }
func (s *NoopService) Stop() error { return nil }
@@ -67,6 +69,10 @@ func (s *InstrumentedService) Protocols() []p2p.Protocol {
return s.protocols
}
+func (s *InstrumentedService) APIs() []rpc.API {
+ return nil
+}
+
func (s *InstrumentedService) Start(server *p2p.Server) error {
if s.startHook != nil {
s.startHook(server)