Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Nov 9, 2023
1 parent b1c72ee commit ba83cb0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions rpc/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
},
}
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions rpc/namespaces/ethereum/eth/filters/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
18 changes: 9 additions & 9 deletions rpc/namespaces/ethereum/eth/filters/filter_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)),
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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())
}

Expand Down
8 changes: 4 additions & 4 deletions rpc/websockets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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,
}
}
Expand Down Expand Up @@ -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,
}
Expand Down
6 changes: 3 additions & 3 deletions server/json_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit ba83cb0

Please sign in to comment.