console: use default APIs when server doesn't have rpc_modules (#26267)
This commit is contained in:
parent
743e404906
commit
1b8a392153
@ -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 {
|
|||||||
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" {
|
||||||
|
Loading…
Reference in New Issue
Block a user