Unverified Commit 1b8a3921 authored by Felix Lange's avatar Felix Lange Committed by GitHub

console: use default APIs when server doesn't have rpc_modules (#26267)

parent 743e4049
...@@ -34,6 +34,7 @@ import ( ...@@ -34,6 +34,7 @@ import (
"github.com/ethereum/go-ethereum/internal/jsre" "github.com/ethereum/go-ethereum/internal/jsre"
"github.com/ethereum/go-ethereum/internal/jsre/deps" "github.com/ethereum/go-ethereum/internal/jsre/deps"
"github.com/ethereum/go-ethereum/internal/web3ext" "github.com/ethereum/go-ethereum/internal/web3ext"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/mattn/go-colorable" "github.com/mattn/go-colorable"
"github.com/peterh/liner" "github.com/peterh/liner"
...@@ -198,13 +199,22 @@ func (c *Console) initWeb3(bridge *bridge) error { ...@@ -198,13 +199,22 @@ func (c *Console) initWeb3(bridge *bridge) error {
return err return err
} }
var defaultAPIs = map[string]string{"eth": "1.0", "net": "1.0", "debug": "1.0"}
// initExtensions loads and registers web3.js extensions. // initExtensions loads and registers web3.js extensions.
func (c *Console) initExtensions() error { func (c *Console) initExtensions() error {
// Compute aliases from server-provided modules. const methodNotFound = -32601
apis, err := c.client.SupportedModules() apis, err := c.client.SupportedModules()
if err != nil { 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": {}} aliases := map[string]struct{}{"eth": {}, "personal": {}}
for api := range apis { for api := range apis {
if api == "web3" { if api == "web3" {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment