Skip to content

Commit 9e06d1a

Browse files
committed
graph, node: Allow rpc clients when using firehose
1 parent 1a37129 commit 9e06d1a

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

graph/src/blockchain/client.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ use anyhow::anyhow;
1111
// Substreams only requires the FirehoseEndpoints.
1212
#[derive(Debug)]
1313
pub enum ChainClient<C: Blockchain> {
14-
Firehose(FirehoseEndpoints),
14+
Firehose(FirehoseEndpoints, Option<C::Client>),
1515
Rpc(C::Client),
1616
}
1717

1818
impl<C: Blockchain> ChainClient<C> {
1919
pub fn new_firehose(firehose_endpoints: FirehoseEndpoints) -> Self {
20-
Self::Firehose(firehose_endpoints)
20+
Self::Firehose(firehose_endpoints, None)
21+
}
22+
23+
pub fn new_firehose_with_rpc(firehose_endpoints: FirehoseEndpoints, rpc: C::Client) -> Self {
24+
Self::Firehose(firehose_endpoints, Some(rpc))
2125
}
2226

2327
pub fn new_rpc(rpc: C::Client) -> Self {
@@ -26,21 +30,22 @@ impl<C: Blockchain> ChainClient<C> {
2630

2731
pub fn is_firehose(&self) -> bool {
2832
match self {
29-
ChainClient::Firehose(_) => true,
33+
ChainClient::Firehose(_, _) => true,
3034
ChainClient::Rpc(_) => false,
3135
}
3236
}
3337

3438
pub async fn firehose_endpoint(&self) -> anyhow::Result<Arc<FirehoseEndpoint>> {
3539
match self {
36-
ChainClient::Firehose(endpoints) => endpoints.endpoint().await,
40+
ChainClient::Firehose(endpoints, _) => endpoints.endpoint().await,
3741
_ => Err(anyhow!("firehose endpoint requested on rpc chain client")),
3842
}
3943
}
4044

4145
pub fn rpc(&self) -> anyhow::Result<&C::Client> {
4246
match self {
4347
Self::Rpc(rpc) => Ok(rpc),
48+
Self::Firehose(_, Some(rpc)) => Ok(rpc),
4449
_ => Err(anyhow!("rpc endpoint requested on firehose chain client")),
4550
}
4651
}

node/src/chain.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,10 @@ pub async fn networks_as_chains(
523523
let eth_adapters = networks.ethereum_rpcs(chain_id.clone());
524524

525525
let cc = if firehose_endpoints.len() > 0 {
526-
ChainClient::<graph_chain_ethereum::Chain>::new_firehose(firehose_endpoints)
526+
ChainClient::<graph_chain_ethereum::Chain>::new_firehose_with_rpc(
527+
firehose_endpoints,
528+
eth_adapters.clone(),
529+
)
527530
} else {
528531
ChainClient::<graph_chain_ethereum::Chain>::new_rpc(eth_adapters.clone())
529532
};

0 commit comments

Comments
 (0)