From 49481a54c51e936df398c977499f3b25b9451e9c Mon Sep 17 00:00:00 2001 From: lyh169 <44960676+lyh169@users.noreply.github.com> Date: Thu, 12 Oct 2023 09:52:38 +0800 Subject: [PATCH] add switch for pending transaction filter (#18) --- jsonrpc/config.go | 3 +++ jsonrpc/endpoints_eth.go | 15 ++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/jsonrpc/config.go b/jsonrpc/config.go index d347ba41d2..16ee9e5672 100644 --- a/jsonrpc/config.go +++ b/jsonrpc/config.go @@ -38,6 +38,9 @@ type Config struct { // TraceBatchUseHTTPS enables, in the debug_traceBatchByNum endpoint, the use of the HTTPS protocol (instead of HTTP) // to do the parallel requests to RPC.debug_traceTransaction endpoint TraceBatchUseHTTPS bool `mapstructure:"TraceBatchUseHTTPS"` + + // EnablePendingTransactionFilter enables pending transaction filter that can support query L2 pending transaction + EnablePendingTransactionFilter bool `mapstructure:"EnablePendingTransactionFilter"` } // WebSocketsConfig has parameters to config the rpc websocket support diff --git a/jsonrpc/endpoints_eth.go b/jsonrpc/endpoints_eth.go index 01af85ff1d..1a2d665e51 100644 --- a/jsonrpc/endpoints_eth.go +++ b/jsonrpc/endpoints_eth.go @@ -830,13 +830,14 @@ func (e *EthEndpoints) NewPendingTransactionFilter() (interface{}, types.Error) // internal func (e *EthEndpoints) newPendingTransactionFilter(wsConn *websocket.Conn) (interface{}, types.Error) { - return nil, types.NewRPCError(types.DefaultErrorCode, "not supported yet") - // id, err := e.storage.NewPendingTransactionFilter(wsConn) - // if err != nil { - // return rpcErrorResponse(types.DefaultErrorCode, "failed to create new pending transaction filter", err) - // } - - // return id, nil + if !e.cfg.EnablePendingTransactionFilter { + return nil, types.NewRPCError(types.DefaultErrorCode, "not supported yet") + } + id, err := e.storage.NewPendingTransactionFilter(wsConn) + if err != nil { + return RPCErrorResponse(types.DefaultErrorCode, "failed to create new pending transaction filter", err) + } + return id, nil } // SendRawTransaction has two different ways to handle new transactions: