Skip to content

Commit 3a9db2f

Browse files
authored
Revert "Add GETH_HEADERS to be set as a config environment variable (#44)" (#67)
This reverts commit 68306c7.
1 parent 55269ff commit 3a9db2f

File tree

7 files changed

+8
-63
lines changed

7 files changed

+8
-63
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ at port `8080`.
6565
* `PORT`(required) - Which port to use for Rosetta.
6666
* `GETH` (optional) - Point to a remote `geth` node instead of initializing one
6767
* `SKIP_GETH_ADMIN` (optional, default: `FALSE`) - Instruct Rosetta to not use the `geth` `admin` RPC calls. This is typically disabled by hosted blockchain node services.
68-
* `GETH_HEADERS` (optional) - Pass a key:value comma-separated list to be passed to the `geth` clients. e.g. `X-Auth-Token:12345-ABCDE,X-Other-Header:SomeOtherValue`
6968

7069
#### Mainnet:Online
7170
```text

cmd/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func runRunCmd(cmd *cobra.Command, args []string) error {
9292
}
9393

9494
var err error
95-
client, err = ethereum.NewClient(cfg.GethURL, cfg.Params, cfg.SkipGethAdmin, cfg.GethHeaders)
95+
client, err = ethereum.NewClient(cfg.GethURL, cfg.Params, cfg.SkipGethAdmin)
9696
if err != nil {
9797
return fmt.Errorf("%w: cannot initialize ethereum client", err)
9898
}

configuration/configuration.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"fmt"
2020
"os"
2121
"strconv"
22-
"strings"
2322

2423
"github.com/coinbase/rosetta-ethereum/ethereum"
2524

@@ -87,11 +86,6 @@ const (
8786
// by hosted node services. When not set, defaults to false.
8887
SkipGethAdminEnv = "SKIP_GETH_ADMIN"
8988

90-
// GethHeadersEnv is an optional environment variable
91-
// of a comma-separated list of key:value pairs to apply
92-
// to geth clients as headers. When not set, defaults to []
93-
GethHeadersEnv = "GETH_HEADERS"
94-
9589
// MiddlewareVersion is the version of rosetta-ethereum.
9690
MiddlewareVersion = "0.0.4"
9791
)
@@ -106,7 +100,6 @@ type Configuration struct {
106100
Port int
107101
GethArguments string
108102
SkipGethAdmin bool
109-
GethHeaders []*ethereum.HTTPHeader
110103

111104
// Block Reward Data
112105
Params *params.ChainConfig
@@ -186,20 +179,6 @@ func LoadConfiguration() (*Configuration, error) {
186179
config.SkipGethAdmin = val
187180
}
188181

189-
envGethHeaders := os.Getenv(GethHeadersEnv)
190-
if len(envGethHeaders) > 0 {
191-
headers := strings.Split(envGethHeaders, ",")
192-
headerKVs := make([]*ethereum.HTTPHeader, len(headers))
193-
for i, pair := range headers {
194-
kv := strings.Split(pair, ":")
195-
headerKVs[i] = &ethereum.HTTPHeader{
196-
Key: kv[0],
197-
Value: kv[1],
198-
}
199-
}
200-
config.GethHeaders = headerKVs
201-
}
202-
203182
portValue := os.Getenv(PortEnv)
204183
if len(portValue) == 0 {
205184
return nil, errors.New("PORT must be populated")

configuration/configuration_test.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func TestLoadConfiguration(t *testing.T) {
3333
Port string
3434
Geth string
3535
SkipGethAdmin string
36-
GethHeaders string
3736

3837
cfg *Configuration
3938
err error
@@ -55,7 +54,6 @@ func TestLoadConfiguration(t *testing.T) {
5554
Network: Mainnet,
5655
Port: "1000",
5756
SkipGethAdmin: "FALSE",
58-
GethHeaders: "",
5957
cfg: &Configuration{
6058
Mode: Online,
6159
Network: &types.NetworkIdentifier{
@@ -68,7 +66,6 @@ func TestLoadConfiguration(t *testing.T) {
6866
GethURL: DefaultGethURL,
6967
GethArguments: ethereum.MainnetGethArguments,
7068
SkipGethAdmin: false,
71-
GethHeaders: nil,
7269
},
7370
},
7471
"all set (mainnet) + geth": {
@@ -77,7 +74,6 @@ func TestLoadConfiguration(t *testing.T) {
7774
Port: "1000",
7875
Geth: "http://blah",
7976
SkipGethAdmin: "TRUE",
80-
GethHeaders: "X-Auth-Token:12345-ABCDE,X-Api-Version:2",
8177
cfg: &Configuration{
8278
Mode: Online,
8379
Network: &types.NetworkIdentifier{
@@ -91,10 +87,6 @@ func TestLoadConfiguration(t *testing.T) {
9187
RemoteGeth: true,
9288
GethArguments: ethereum.MainnetGethArguments,
9389
SkipGethAdmin: true,
94-
GethHeaders: []*ethereum.HTTPHeader{
95-
{Key: "X-Auth-Token", Value: "12345-ABCDE"},
96-
{Key: "X-Api-Version", Value: "2"},
97-
},
9890
},
9991
},
10092
"all set (ropsten)": {
@@ -112,7 +104,6 @@ func TestLoadConfiguration(t *testing.T) {
112104
Port: 1000,
113105
GethURL: DefaultGethURL,
114106
GethArguments: ethereum.RopstenGethArguments,
115-
GethHeaders: nil,
116107
},
117108
},
118109
"all set (rinkeby)": {
@@ -130,7 +121,6 @@ func TestLoadConfiguration(t *testing.T) {
130121
Port: 1000,
131122
GethURL: DefaultGethURL,
132123
GethArguments: ethereum.RinkebyGethArguments,
133-
GethHeaders: nil,
134124
},
135125
},
136126
"all set (goerli)": {
@@ -148,15 +138,13 @@ func TestLoadConfiguration(t *testing.T) {
148138
Port: 1000,
149139
GethURL: DefaultGethURL,
150140
GethArguments: ethereum.GoerliGethArguments,
151-
GethHeaders: nil,
152141
},
153142
},
154143
"all set (testnet)": {
155144
Mode: string(Online),
156145
Network: Testnet,
157146
Port: "1000",
158147
SkipGethAdmin: "TRUE",
159-
GethHeaders: "X-Auth-Token:12345-ABCDE,X-Api-Version:2",
160148
cfg: &Configuration{
161149
Mode: Online,
162150
Network: &types.NetworkIdentifier{
@@ -169,10 +157,6 @@ func TestLoadConfiguration(t *testing.T) {
169157
GethURL: DefaultGethURL,
170158
GethArguments: ethereum.RopstenGethArguments,
171159
SkipGethAdmin: true,
172-
GethHeaders: []*ethereum.HTTPHeader{
173-
{Key: "X-Auth-Token", Value: "12345-ABCDE"},
174-
{Key: "X-Api-Version", Value: "2"},
175-
},
176160
},
177161
},
178162
"invalid mode": {
@@ -202,7 +186,6 @@ func TestLoadConfiguration(t *testing.T) {
202186
os.Setenv(PortEnv, test.Port)
203187
os.Setenv(GethEnv, test.Geth)
204188
os.Setenv(SkipGethAdminEnv, test.SkipGethAdmin)
205-
os.Setenv(GethHeadersEnv, test.GethHeaders)
206189

207190
cfg, err := LoadConfiguration()
208191
if test.err != nil {

ethereum/client.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,20 @@ type Client struct {
6565
}
6666

6767
// NewClient creates a Client that from the provided url and params.
68-
func NewClient(url string, params *params.ChainConfig, skipAdminCalls bool, headers []*HTTPHeader) (*Client, error) {
68+
func NewClient(url string, params *params.ChainConfig, skipAdminCalls bool) (*Client, error) {
6969
c, err := rpc.DialHTTPWithClient(url, &http.Client{
7070
Timeout: gethHTTPTimeout,
7171
})
7272
if err != nil {
7373
return nil, fmt.Errorf("%w: unable to dial node", err)
7474
}
7575

76-
for _, header := range headers {
77-
c.SetHeader(header.Key, header.Value)
78-
}
79-
8076
tc, err := loadTraceConfig()
8177
if err != nil {
8278
return nil, fmt.Errorf("%w: unable to load trace config", err)
8379
}
8480

85-
g, err := newGraphQLClient(url, headers)
81+
g, err := newGraphQLClient(url)
8682
if err != nil {
8783
return nil, fmt.Errorf("%w: unable to create GraphQL client", err)
8884
}

ethereum/graphql_client.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ const (
3535
// GraphQLClient is a client used to make graphQL
3636
// queries to geth's graphql endpoint.
3737
type GraphQLClient struct {
38-
client *http.Client
39-
url string
40-
headers []*HTTPHeader
38+
client *http.Client
39+
url string
4140
}
4241

4342
// Query makes a query to the graphQL endpoint.
@@ -57,10 +56,6 @@ func (g *GraphQLClient) Query(ctx context.Context, input string) (string, error)
5756
g.url,
5857
bytes.NewBuffer(jsonValue),
5958
)
60-
for _, header := range g.headers {
61-
request.Header.Set(header.Key, header.Value)
62-
}
63-
6459
if err != nil {
6560
return "", err
6661
}
@@ -79,7 +74,7 @@ func (g *GraphQLClient) Query(ctx context.Context, input string) (string, error)
7974
return string(data), nil
8075
}
8176

82-
func newGraphQLClient(baseURL string, headers []*HTTPHeader) (*GraphQLClient, error) {
77+
func newGraphQLClient(baseURL string) (*GraphQLClient, error) {
8378
// Compute GraphQL Endpoint
8479
u, err := url.Parse(baseURL)
8580
if err != nil {
@@ -102,8 +97,7 @@ func newGraphQLClient(baseURL string, headers []*HTTPHeader) (*GraphQLClient, er
10297
client.Transport = customTransport
10398

10499
return &GraphQLClient{
105-
client: client,
106-
url: u.String(),
107-
headers: headers,
100+
client: client,
101+
url: u.String(),
108102
}, nil
109103
}

ethereum/types.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,6 @@ type GraphQL interface {
216216
Query(ctx context.Context, input string) (string, error)
217217
}
218218

219-
// HTTPHeader is key, value pair to be set on the HTTP and GraphQL client.
220-
type HTTPHeader struct {
221-
Key string
222-
Value string
223-
}
224-
225219
// CallType returns a boolean indicating
226220
// if the provided trace type is a call type.
227221
func CallType(t string) bool {

0 commit comments

Comments
 (0)