From 1b8a392153b39fbbde17536c730d96510e57341f Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 28 Nov 2022 20:27:01 +0100 Subject: [PATCH] console: use default APIs when server doesn't have rpc_modules (#26267) --- console/console.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/console/console.go b/console/console.go index 7b9ed27e15..fde673be8b 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,13 +199,22 @@ 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. + const methodNotFound = -32601 apis, err := c.client.SupportedModules() if err != nil { - return fmt.Errorf("api modules: %v", err) + 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" {