diff --git a/rpc/apis.go b/rpc/apis.go index c8d9804bab..0f647404d6 100644 --- a/rpc/apis.go +++ b/rpc/apis.go @@ -72,7 +72,7 @@ func init() { apiCreators = map[string]APICreator{ EthNamespace: func(ctx *server.Context, clientCtx client.Context, - tmWSClient rpcclient.EventsClient, + evtClient rpcclient.EventsClient, allowUnprotectedTxs bool, indexer ethermint.EVMTxIndexer, ) []rpc.API { @@ -87,7 +87,7 @@ func init() { { Namespace: EthNamespace, Version: apiVersion, - Service: filters.NewPublicAPI(ctx.Logger, clientCtx, tmWSClient, evmBackend), + Service: filters.NewPublicAPI(ctx.Logger, clientCtx, evtClient, evmBackend), Public: true, }, } @@ -176,7 +176,7 @@ func init() { // GetRPCAPIs returns the list of all APIs func GetRPCAPIs(ctx *server.Context, clientCtx client.Context, - tmWSClient rpcclient.EventsClient, + evtClient rpcclient.EventsClient, allowUnprotectedTxs bool, indexer ethermint.EVMTxIndexer, selectedAPIs []string, @@ -185,7 +185,7 @@ func GetRPCAPIs(ctx *server.Context, for _, ns := range selectedAPIs { if creator, ok := apiCreators[ns]; ok { - apis = append(apis, creator(ctx, clientCtx, tmWSClient, allowUnprotectedTxs, indexer)...) + apis = append(apis, creator(ctx, clientCtx, evtClient, allowUnprotectedTxs, indexer)...) } else { ctx.Logger.Error("invalid namespace value", "namespace", ns) } diff --git a/rpc/namespaces/ethereum/eth/filters/api.go b/rpc/namespaces/ethereum/eth/filters/api.go index e0de70f693..cd75f66eb0 100644 --- a/rpc/namespaces/ethereum/eth/filters/api.go +++ b/rpc/namespaces/ethereum/eth/filters/api.go @@ -93,14 +93,14 @@ type PublicFilterAPI struct { } // NewPublicAPI returns a new PublicFilterAPI instance. -func NewPublicAPI(logger log.Logger, clientCtx client.Context, tmWSClient rpcclient.EventsClient, backend Backend) *PublicFilterAPI { +func NewPublicAPI(logger log.Logger, clientCtx client.Context, evtClient rpcclient.EventsClient, backend Backend) *PublicFilterAPI { logger = logger.With("api", "filter") api := &PublicFilterAPI{ logger: logger, clientCtx: clientCtx, backend: backend, filters: make(map[rpc.ID]*filter), - events: NewEventSystem(logger, tmWSClient), + events: NewEventSystem(logger, evtClient), } go api.timeoutLoop() diff --git a/rpc/namespaces/ethereum/eth/filters/filter_system.go b/rpc/namespaces/ethereum/eth/filters/filter_system.go index fbfd2194dc..f209d2b810 100644 --- a/rpc/namespaces/ethereum/eth/filters/filter_system.go +++ b/rpc/namespaces/ethereum/eth/filters/filter_system.go @@ -56,9 +56,9 @@ var ( // EventSystem creates subscriptions, processes events and broadcasts them to the // subscription which match the subscription criteria using the Tendermint's RPC client. type EventSystem struct { - logger log.Logger - ctx context.Context - tmWSClient rpcclient.EventsClient + logger log.Logger + ctx context.Context + evtClient rpcclient.EventsClient // light client mode lightMode bool @@ -78,7 +78,7 @@ type EventSystem struct { // // The returned manager has a loop that needs to be stopped with the Stop function // or by stopping the given mux. -func NewEventSystem(logger log.Logger, tmWSClient rpcclient.EventsClient) *EventSystem { +func NewEventSystem(logger log.Logger, evtClient rpcclient.EventsClient) *EventSystem { index := make(filterIndex) for i := filters.UnknownSubscription; i < filters.LastIndexSubscription; i++ { index[i] = make(map[rpc.ID]*Subscription) @@ -87,7 +87,7 @@ func NewEventSystem(logger log.Logger, tmWSClient rpcclient.EventsClient) *Event es := &EventSystem{ logger: logger, ctx: context.Background(), - tmWSClient: tmWSClient, + evtClient: evtClient, lightMode: false, index: index, topicChans: make(map[string]chan<- coretypes.ResultEvent, len(index)), @@ -134,11 +134,11 @@ func (es *EventSystem) subscribe(sub *Subscription) (*Subscription, pubsub.Unsub switch sub.typ { case filters.LogsSubscription: - chEvents, err = es.tmWSClient.Subscribe(ctx, subscriberName, sub.event) + chEvents, err = es.evtClient.Subscribe(ctx, subscriberName, sub.event) case filters.BlocksSubscription: - chEvents, err = es.tmWSClient.Subscribe(ctx, subscriberName, sub.event) + chEvents, err = es.evtClient.Subscribe(ctx, subscriberName, sub.event) case filters.PendingTransactionsSubscription: - chEvents, err = es.tmWSClient.Subscribe(ctx, subscriberName, sub.event) + chEvents, err = es.evtClient.Subscribe(ctx, subscriberName, sub.event) default: err = fmt.Errorf("invalid filter subscription type %d", sub.typ) } @@ -248,7 +248,7 @@ func (es *EventSystem) eventLoop() { // remove topic only when channel is not used by other subscriptions if !channelInUse { - if err := es.tmWSClient.Unsubscribe(es.ctx, subscriberName, f.event); err != nil { + if err := es.evtClient.Unsubscribe(es.ctx, subscriberName, f.event); err != nil { es.logger.Error("failed to unsubscribe from query", "query", f.event, "error", err.Error()) } diff --git a/rpc/websockets.go b/rpc/websockets.go index 34e93a96f8..b76de41761 100644 --- a/rpc/websockets.go +++ b/rpc/websockets.go @@ -90,7 +90,7 @@ type websocketsServer struct { logger log.Logger } -func NewWebsocketsServer(clientCtx client.Context, logger log.Logger, tmWSClient rpcclient.EventsClient, cfg *config.Config) WebsocketsServer { +func NewWebsocketsServer(clientCtx client.Context, logger log.Logger, evtClient rpcclient.EventsClient, cfg *config.Config) WebsocketsServer { logger = logger.With("api", "websocket-server") _, port, _ := net.SplitHostPort(cfg.JSONRPC.Address) @@ -99,7 +99,7 @@ func NewWebsocketsServer(clientCtx client.Context, logger log.Logger, tmWSClient wsAddr: cfg.JSONRPC.WsAddress, certFile: cfg.TLS.CertificatePath, keyFile: cfg.TLS.KeyPath, - api: newPubSubAPI(clientCtx, logger, tmWSClient), + api: newPubSubAPI(clientCtx, logger, evtClient), logger: logger, } } @@ -359,10 +359,10 @@ type pubSubAPI struct { } // newPubSubAPI creates an instance of the ethereum PubSub API. -func newPubSubAPI(clientCtx client.Context, logger log.Logger, tmWSClient rpcclient.EventsClient) *pubSubAPI { +func newPubSubAPI(clientCtx client.Context, logger log.Logger, evtClient rpcclient.EventsClient) *pubSubAPI { logger = logger.With("module", "websocket-client") return &pubSubAPI{ - events: rpcfilters.NewEventSystem(logger, tmWSClient), + events: rpcfilters.NewEventSystem(logger, evtClient), logger: logger, clientCtx: clientCtx, } diff --git a/server/json_rpc.go b/server/json_rpc.go index 12a5b112d6..51ad83b020 100644 --- a/server/json_rpc.go +++ b/server/json_rpc.go @@ -41,7 +41,7 @@ func StartJSONRPC(ctx *server.Context, config *config.Config, indexer ethermint.EVMTxIndexer, ) (*http.Server, chan struct{}, error) { - tmWsClient, ok := clientCtx.Client.(rpcclient.EventsClient) + evtClient, ok := clientCtx.Client.(rpcclient.EventsClient) if !ok { return nil, nil, fmt.Errorf("client %T does not implement EventsClient", clientCtx.Client) } @@ -64,7 +64,7 @@ func StartJSONRPC(ctx *server.Context, allowUnprotectedTxs := config.JSONRPC.AllowUnprotectedTxs rpcAPIArr := config.JSONRPC.API - apis := rpc.GetRPCAPIs(ctx, clientCtx, tmWsClient, allowUnprotectedTxs, indexer, rpcAPIArr) + apis := rpc.GetRPCAPIs(ctx, clientCtx, evtClient, allowUnprotectedTxs, indexer, rpcAPIArr) for _, api := range apis { if err := rpcServer.RegisterName(api.Namespace, api.Service); err != nil { @@ -123,7 +123,7 @@ func StartJSONRPC(ctx *server.Context, ctx.Logger.Info("Starting JSON WebSocket server", "address", config.JSONRPC.WsAddress) - wsSrv := rpc.NewWebsocketsServer(clientCtx, ctx.Logger, tmWsClient, config) + wsSrv := rpc.NewWebsocketsServer(clientCtx, ctx.Logger, evtClient, config) wsSrv.Start() return httpSrv, httpSrvDone, nil }