From 72b932acbf7b6576a53ac9b4a5395d38a33eee65 Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Sun, 21 Sep 2025 19:36:04 +0800 Subject: [PATCH] console: use default APIs when server doesn't have rpc_modules #26267 (#1537) --- console/console.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/console/console.go b/console/console.go index 69c8c63c33..783cc4e6b5 100644 --- a/console/console.go +++ b/console/console.go @@ -33,6 +33,7 @@ import ( "github.com/XinFinOrg/XDPoSChain/internal/jsre" "github.com/XinFinOrg/XDPoSChain/internal/jsre/deps" "github.com/XinFinOrg/XDPoSChain/internal/web3ext" + "github.com/XinFinOrg/XDPoSChain/log" "github.com/XinFinOrg/XDPoSChain/rpc" "github.com/dop251/goja" "github.com/mattn/go-colorable" @@ -197,13 +198,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": {}} for api := range apis { if api == "web3" {