Skip to content

Commit

Permalink
only allow post for json-rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Aug 16, 2024
1 parent 5b6f6ae commit 7d2ab3e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
10 changes: 0 additions & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions jsonrpc/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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)
Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions jsonrpc/namespaces/eth/filters/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 7d2ab3e

Please sign in to comment.