Skip to content

Commit

Permalink
console: use default APIs when server doesn't have rpc_modules (ether…
Browse files Browse the repository at this point in the history
  • Loading branch information
fjl authored Nov 28, 2022
1 parent 743e404 commit 1b8a392
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions console/console.go
Original file line number Diff line number Diff line change
@@ -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" {

0 comments on commit 1b8a392

Please sign in to comment.