Avoid passing node to subscriptions service

This commit is contained in:
Pedro Pombeiro 2020-01-10 11:09:07 +01:00 committed by Pedro Pombeiro
parent 6537cae606
commit db01f0b3e4
4 changed files with 16 additions and 18 deletions

View File

@ -383,7 +383,7 @@ func (b *GethStatusBackend) rpcFiltersService() gethnode.ServiceConstructor {
func (b *GethStatusBackend) subscriptionService() gethnode.ServiceConstructor { func (b *GethStatusBackend) subscriptionService() gethnode.ServiceConstructor {
return func(*gethnode.ServiceContext) (gethnode.Service, error) { return func(*gethnode.ServiceContext) (gethnode.Service, error) {
return subscriptions.New(b.statusNode), nil return subscriptions.New(func() *rpc.Client { return b.statusNode.RPCPrivateClient() }), nil
} }
} }

View File

@ -377,7 +377,7 @@ func (b *nimbusStatusBackend) rpcFiltersService() nimbussvc.ServiceConstructor {
func (b *nimbusStatusBackend) subscriptionService() nimbussvc.ServiceConstructor { func (b *nimbusStatusBackend) subscriptionService() nimbussvc.ServiceConstructor {
return func(*nimbussvc.ServiceContext) (nimbussvc.Service, error) { return func(*nimbussvc.ServiceContext) (nimbussvc.Service, error) {
return subscriptions.New(b.statusNode), nil return subscriptions.New(func() *rpc.Client { return b.statusNode.RPCPrivateClient() }), nil
} }
} }

View File

@ -4,18 +4,18 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/status-im/status-go/node" "github.com/status-im/status-go/rpc"
) )
type API struct { type API struct {
node *node.StatusNode rpcPrivateClientFunc func() *rpc.Client
activeSubscriptions *Subscriptions activeSubscriptions *Subscriptions
} }
func NewPublicAPI(node *node.StatusNode) *API { func NewPublicAPI(rpcPrivateClientFunc func() *rpc.Client) *API {
return &API{ return &API{
node: node, rpcPrivateClientFunc: rpcPrivateClientFunc,
activeSubscriptions: NewSubscriptions(100 * time.Millisecond), activeSubscriptions: NewSubscriptions(100 * time.Millisecond),
} }
} }
@ -26,13 +26,11 @@ func (api *API) SubscribeSignal(method string, args []interface{}) (Subscription
namespace = method[:3] namespace = method[:3]
) )
rpc := api.node.RPCPrivateClient()
switch namespace { switch namespace {
case "shh": case "shh":
filter, err = installShhFilter(rpc, method, args) filter, err = installShhFilter(api.rpcPrivateClientFunc(), method, args)
case "eth": case "eth":
filter, err = installEthFilter(rpc, method, args) filter, err = installEthFilter(api.rpcPrivateClientFunc(), method, args)
default: default:
err = fmt.Errorf("unexpected namespace: %s", namespace) err = fmt.Errorf("unexpected namespace: %s", namespace)
} }

View File

@ -3,9 +3,9 @@ package subscriptions
import ( import (
gethnode "github.com/ethereum/go-ethereum/node" gethnode "github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rpc" gethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/status-im/status-go/node" "github.com/status-im/status-go/rpc"
) )
// Make sure that Service implements gethnode.Service interface. // Make sure that Service implements gethnode.Service interface.
@ -17,9 +17,9 @@ type Service struct {
} }
// New returns a new Service. // New returns a new Service.
func New(node *node.StatusNode) *Service { func New(rpcPrivateClientFunc func() *rpc.Client) *Service {
return &Service{ return &Service{
api: NewPublicAPI(node), api: NewPublicAPI(rpcPrivateClientFunc),
} }
} }
@ -29,8 +29,8 @@ func (s *Service) Protocols() []p2p.Protocol {
} }
// APIs returns a list of new APIs. // APIs returns a list of new APIs.
func (s *Service) APIs() []rpc.API { func (s *Service) APIs() []gethrpc.API {
return []rpc.API{ return []gethrpc.API{
{ {
Namespace: "eth", Namespace: "eth",
Version: "1.0", Version: "1.0",