From f32c1d96cbb6838095fa0ee202f44101b719b1c7 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 28 Nov 2022 11:15:29 +0100 Subject: [PATCH 1/2] console: use default APIs when server doesn't have rpc_modules --- console/console.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/console/console.go b/console/console.go index 7b9ed27e15ec..864b11c10359 100644 --- a/console/console.go +++ b/console/console.go @@ -34,6 +34,7 @@ import ( "github.com/ethereum/go-ethereum/internal/jsre" "github.com/ethereum/go-ethereum/internal/jsre/deps" "github.com/ethereum/go-ethereum/internal/web3ext" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rpc" "github.com/mattn/go-colorable" "github.com/peterh/liner" @@ -198,12 +199,19 @@ func (c *Console) initWeb3(bridge *bridge) error { return err } +var defaultAPIs = map[string]string{"eth": "1.0", "net": "1.0", "debug": "1.0"} + // initExtensions loads and registers web3.js extensions. func (c *Console) initExtensions() error { // Compute aliases from server-provided modules. apis, err := c.client.SupportedModules() if err != nil { - return fmt.Errorf("api modules: %v", err) + if rpcErr, ok := err.(rpc.Error); ok && rpcErr.ErrorCode() == -32601 { + log.Warn("Server does not support method rpc_modules, using default API list.") + apis = defaultAPIs + } else { + return err + } } aliases := map[string]struct{}{"eth": {}, "personal": {}} for api := range apis { From 936a016c06b438df5b9020ce8ce6056b6dd5c34c Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 28 Nov 2022 13:36:25 +0100 Subject: [PATCH 2/2] console: add constant for error code --- console/console.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/console/console.go b/console/console.go index 864b11c10359..fde673be8be9 100644 --- a/console/console.go +++ b/console/console.go @@ -203,16 +203,18 @@ var defaultAPIs = map[string]string{"eth": "1.0", "net": "1.0", "debug": "1.0"} // initExtensions loads and registers web3.js extensions. func (c *Console) initExtensions() error { - // Compute aliases from server-provided modules. + const methodNotFound = -32601 apis, err := c.client.SupportedModules() if err != nil { - if rpcErr, ok := err.(rpc.Error); ok && rpcErr.ErrorCode() == -32601 { + if rpcErr, ok := err.(rpc.Error); ok && rpcErr.ErrorCode() == methodNotFound { log.Warn("Server does not support method rpc_modules, using default API list.") apis = defaultAPIs } else { return err } } + + // Compute aliases from server-provided modules. aliases := map[string]struct{}{"eth": {}, "personal": {}} for api := range apis { if api == "web3" {