Skip to content

Commit 54c3e30

Browse files
committed
ethereum: Remove support for old config
1 parent ac76222 commit 54c3e30

File tree

9 files changed

+31
-163
lines changed

9 files changed

+31
-163
lines changed

Cargo.lock

Lines changed: 1 addition & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chain/ethereum/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ lazy_static = "1.2.0"
1313
mockall = "0.9.1"
1414
state_machine_future = "0.2"
1515
serde = "1.0"
16-
config = { version = "0.11", features = ["toml"], default-features = false }
1716
dirs-next = "2.0"
1817
anyhow = "1.0"
1918
tiny-keccak = "1.5.0"

chain/ethereum/src/config.rs

Lines changed: 0 additions & 65 deletions
This file was deleted.

chain/ethereum/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
mod adapter;
2-
mod config;
32
mod data_source;
43
mod ethereum_adapter;
54
pub mod network_indexer;

chain/ethereum/src/transport.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use web3::RequestId;
88

99
use graph::prelude::*;
1010

11-
use super::config::ETHEREUM_CONFIG;
12-
1311
/// Abstraction over the different web3 transports.
1412
#[derive(Clone, Debug)]
1513
pub enum Transport {
@@ -37,14 +35,11 @@ impl Transport {
3735
///
3836
/// Note: JSON-RPC over HTTP doesn't always support subscribing to new
3937
/// blocks (one such example is Infura's HTTP endpoint).
40-
pub fn new_rpc(rpc: &str) -> (EventLoopHandle, Self) {
38+
pub fn new_rpc(rpc: &str, headers: ::http::HeaderMap) -> (EventLoopHandle, Self) {
4139
let max_parallel_http: usize = env::var_os("ETHEREUM_RPC_MAX_PARALLEL_REQUESTS")
4240
.map(|s| s.to_str().unwrap().parse().unwrap())
4341
.unwrap_or(64);
4442

45-
let cfg = ETHEREUM_CONFIG.rpc.get(rpc);
46-
let headers = cfg.map(|cfg| cfg.http_headers.clone()).unwrap_or_default();
47-
4843
http::Http::with_max_parallel_and_headers(rpc, max_parallel_http, headers)
4944
.map(|(event_loop, transport)| (event_loop, Transport::RPC(transport)))
5045
.expect("Failed to connect to Ethereum RPC")

docs/ethereum-config.md

Lines changed: 0 additions & 52 deletions
This file was deleted.

node/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ toml = "0.5.7"
4141
shellexpand = "2.1.0"
4242
diesel = "1.4.6"
4343
fail = "0.4"
44+
http = "0.1.21" # must be compatible with the version rust-web3 uses
4445

4546
[dev-dependencies]
4647
assert_cli = "0.6"

node/src/config.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use graph::{
88
};
99
use graph_store_postgres::{DeploymentPlacer, Shard as ShardName, PRIMARY_SHARD};
1010

11+
use http::HeaderMap;
1112
use regex::Regex;
1213
use serde::{Deserialize, Serialize};
1314
use std::collections::{BTreeMap, BTreeSet};
@@ -436,6 +437,7 @@ impl ChainSection {
436437
transport,
437438
url: url.to_string(),
438439
features,
440+
headers: Default::default(),
439441
};
440442
let entry = chains.entry(name.to_string()).or_insert_with(|| Chain {
441443
shard: PRIMARY_SHARD.to_string(),
@@ -466,13 +468,38 @@ impl Chain {
466468
}
467469
}
468470

471+
fn deserialize_http_headers<'de, D>(deserializer: D) -> Result<HeaderMap, D::Error>
472+
where
473+
D: serde::Deserializer<'de>,
474+
{
475+
let kvs: BTreeMap<String, String> = Deserialize::deserialize(deserializer)?;
476+
let mut headers = HeaderMap::new();
477+
for (k, v) in kvs.into_iter() {
478+
headers.insert(
479+
k.parse::<http::header::HeaderName>()
480+
.expect(&format!("invalid HTTP header name: {}", k)),
481+
v.parse::<http::header::HeaderValue>()
482+
.expect(&format!("invalid HTTP header value: {}: {}", k, v)),
483+
);
484+
}
485+
Ok(headers)
486+
}
487+
469488
#[derive(Clone, Debug, Deserialize, Serialize)]
470489
pub struct Provider {
471490
pub label: String,
472491
#[serde(default)]
473492
pub transport: Transport,
474493
pub url: String,
475494
pub features: BTreeSet<String>,
495+
496+
// TODO: This should be serialized.
497+
#[serde(
498+
skip_serializing,
499+
default,
500+
deserialize_with = "deserialize_http_headers"
501+
)]
502+
pub headers: HeaderMap,
476503
}
477504

478505
const PROVIDER_FEATURES: [&str; 3] = ["traces", "archive", "no_eip1898"];

node/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ async fn create_ethereum_networks(
468468
use crate::config::Transport::*;
469469

470470
let (transport_event_loop, transport) = match provider.transport {
471-
Rpc => Transport::new_rpc(&provider.url),
471+
Rpc => Transport::new_rpc(&provider.url, provider.headers),
472472
Ipc => Transport::new_ipc(&provider.url),
473473
Ws => Transport::new_ws(&provider.url),
474474
};

0 commit comments

Comments
 (0)