cmd/geth, cmd/utils: geth attach with custom headers (#25829)
This PR makes it possible to set custom headers, in particular for two scenarios: - geth attach - geth commands which can use --remotedb, e..g geth db inspect The ability to use custom headers is typically useful for connecting to cloud-apis, e.g. providing an infura- or alchemy key, or for that matter access-keys for environments behind cloudflare. Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
co-authored by
Felix Lange
parent
07e0704ca9
commit
ea26fc8a6c
@@ -22,9 +22,6 @@
|
||||
package remotedb
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
@@ -150,24 +147,8 @@ func (db *Database) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func dialRPC(endpoint string) (*rpc.Client, error) {
|
||||
if endpoint == "" {
|
||||
return nil, errors.New("endpoint must be specified")
|
||||
}
|
||||
if strings.HasPrefix(endpoint, "rpc:") || strings.HasPrefix(endpoint, "ipc:") {
|
||||
// Backwards compatibility with geth < 1.5 which required
|
||||
// these prefixes.
|
||||
endpoint = endpoint[4:]
|
||||
}
|
||||
return rpc.Dial(endpoint)
|
||||
}
|
||||
|
||||
func New(endpoint string) (ethdb.Database, error) {
|
||||
client, err := dialRPC(endpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
func New(client *rpc.Client) ethdb.Database {
|
||||
return &Database{
|
||||
remote: client,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user