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

View File

@ -3,9 +3,9 @@ package subscriptions
import (
gethnode "github.com/ethereum/go-ethereum/node"
"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.
@ -17,9 +17,9 @@ type Service struct {
}
// New returns a new Service.
func New(node *node.StatusNode) *Service {
func New(rpcPrivateClientFunc func() *rpc.Client) *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.
func (s *Service) APIs() []rpc.API {
return []rpc.API{
func (s *Service) APIs() []gethrpc.API {
return []gethrpc.API{
{
Namespace: "eth",
Version: "1.0",