From 7d2ab3ef3fd053167df9fc642ca48918bf4be887 Mon Sep 17 00:00:00 2001 From: beer-1 Date: Fri, 16 Aug 2024 16:21:40 +0900 Subject: [PATCH] only allow post for json-rpc --- .golangci.yml | 10 ---------- jsonrpc/jsonrpc.go | 12 ++++++------ jsonrpc/namespaces/eth/filters/subscriptions.go | 8 ++++---- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index a9aaa90..49393d0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,17 +4,7 @@ linters: - thelper - varnamelen - tagliatelle - - interfacer - wrapcheck - - deadcode - - exhaustivestruct - - golint - - ifshort - - maligned - - nosnakecase - - scopelint - - structcheck - - varcheck linters-settings: gocyclo: min-complexity: 11 diff --git a/jsonrpc/jsonrpc.go b/jsonrpc/jsonrpc.go index 9e12edd..8896616 100644 --- a/jsonrpc/jsonrpc.go +++ b/jsonrpc/jsonrpc.go @@ -123,7 +123,7 @@ func StartJSONRPC( var addr string if !isWebSocket { addr = jsonRPCConfig.Address - router.Handle("/", rpcServer).Methods("GET").Methods("POST") + router.Handle("/", rpcServer).Methods("POST") } else { allowedOrigins := []string{} if jsonRPCConfig.EnableUnsafeCORS { @@ -148,7 +148,7 @@ func StartJSONRPC( IdleTimeout: jsonRPCConfig.HTTPIdleTimeout, } - ln, err := listen(httpSrv.Addr, jsonRPCConfig) + ln, err := listen(addr, jsonRPCConfig) if err != nil { return err } @@ -158,9 +158,9 @@ func StartJSONRPC( go func() { if !isWebSocket { - svrCtx.Logger.Info("Starting JSON-RPC server", "address", jsonRPCConfig.Address) + svrCtx.Logger.Info("Starting JSON-RPC server", "address", addr) } else { - svrCtx.Logger.Info("Starting JSON-RPC WebSocket server", "address", jsonRPCConfig.AddressWS) + svrCtx.Logger.Info("Starting JSON-RPC WebSocket server", "address", addr) } errCh <- httpSrv.Serve(ln) @@ -173,9 +173,9 @@ func StartJSONRPC( // The calling process canceled or closed the provided context, so we must // gracefully stop the gRPC server. if !isWebSocket { - logger.Info("stopping Ethereum JSONRPC server...", "address", jsonRPCConfig.Address) + logger.Info("stopping Ethereum JSONRPC server...", "address", addr) } else { - logger.Info("stopping Ethereum JSONRPC WebSocket server...", "address", jsonRPCConfig.AddressWS) + logger.Info("stopping Ethereum JSONRPC WebSocket server...", "address", addr) } return httpSrv.Close() diff --git a/jsonrpc/namespaces/eth/filters/subscriptions.go b/jsonrpc/namespaces/eth/filters/subscriptions.go index 3aa4f3c..d804d8f 100644 --- a/jsonrpc/namespaces/eth/filters/subscriptions.go +++ b/jsonrpc/namespaces/eth/filters/subscriptions.go @@ -48,7 +48,7 @@ func (api *FilterAPI) NewHeads(ctx context.Context) (*rpc.Subscription, error) { for { select { case h := <-headerChan: - notifier.Notify(rpcSub.ID, h) + _ = notifier.Notify(rpcSub.ID, h) case <-rpcSub.Err(): return } @@ -109,7 +109,7 @@ func (api *FilterAPI) Logs(ctx context.Context, crit ethfilters.FilterCriteria) case logs := <-logsChan: for _, log := range logs { log := log - notifier.Notify(rpcSub.ID, &log) + _ = notifier.Notify(rpcSub.ID, &log) } case <-rpcSub.Err(): // client send an unsubscribe request return @@ -151,9 +151,9 @@ func (api *FilterAPI) NewPendingTransactions(ctx context.Context, fullTx *bool) for { select { case rpcTx := <-txChan: - notifier.Notify(rpcSub.ID, rpcTx) + _ = notifier.Notify(rpcSub.ID, rpcTx) case hash := <-hashChan: - notifier.Notify(rpcSub.ID, hash) + _ = notifier.Notify(rpcSub.ID, hash) case <-rpcSub.Err(): return }