Skip to content

Commit 1d5b555

Browse files
committed
graph, chain, runtime: re export alloy from graph crate and use it
1 parent b2fa246 commit 1d5b555

File tree

8 files changed

+23
-58
lines changed

8 files changed

+23
-58
lines changed

Cargo.lock

Lines changed: 0 additions & 41 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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ version.workspace = true
44
edition.workspace = true
55

66
[dependencies]
7-
alloy.workspace = true
8-
alloy-rpc-types.workspace = true
97
envconfig = "0.11.0"
108
jsonrpc-core = "18.0.0"
119
graph = { path = "../../graph" }

chain/ethereum/src/adapter.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use alloy::transports::RpcError;
2-
use alloy::transports::TransportErrorKind;
31
use anyhow::Error;
42
use graph::abi;
53
use graph::blockchain::ChainIdentifier;
@@ -9,6 +7,7 @@ use graph::data_source::common::ContractCall;
97
use graph::firehose::CallToFilter;
108
use graph::firehose::CombinedFilter;
119
use graph::firehose::LogFilter;
10+
use graph::prelude::alloy::transports::{RpcError, TransportErrorKind};
1211
use graph::prelude::web3::types::H160;
1312
use itertools::Itertools;
1413
use prost::Message;

chain/ethereum/src/ethereum_adapter.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use alloy::primitives::B256;
2-
use alloy::providers::{Provider, ProviderBuilder};
31
use futures03::{future::BoxFuture, stream::FuturesUnordered};
42
use graph::abi;
53
use graph::abi::DynSolValueExt;
@@ -21,6 +19,7 @@ use graph::futures03::future::try_join_all;
2119
use graph::futures03::{
2220
self, compat::Future01CompatExt, FutureExt, StreamExt, TryFutureExt, TryStreamExt,
2321
};
22+
use graph::prelude::alloy;
2423
use graph::prelude::tokio::try_join;
2524
use graph::slog::o;
2625
use graph::tokio::sync::RwLock;
@@ -78,7 +77,7 @@ pub struct EthereumAdapter {
7877
logger: Logger,
7978
provider: String,
8079
web3: Arc<Web3<Transport>>,
81-
alloy: Arc<dyn Provider>,
80+
alloy: Arc<dyn alloy::providers::Provider>,
8281
metrics: Arc<ProviderEthRpcMetrics>,
8382
supports_eip_1898: bool,
8483
call_only: bool,
@@ -267,7 +266,12 @@ impl EthereumAdapter {
267266
Transport::WS(_web_socket) => todo!(),
268267
};
269268
let web3 = Arc::new(Web3::new(transport));
270-
let alloy = Arc::new(ProviderBuilder::new().connect(&rpc_url).await.unwrap());
269+
let alloy = Arc::new(
270+
alloy::providers::ProviderBuilder::new()
271+
.connect(&rpc_url)
272+
.await
273+
.unwrap(),
274+
);
271275

272276
EthereumAdapter {
273277
logger,
@@ -648,11 +652,13 @@ impl EthereumAdapter {
648652
}
649653
}
650654

651-
fn block_ptr_to_alloy_block_id(&self, block_ptr: &BlockPtr) -> alloy_rpc_types::BlockId {
655+
fn block_ptr_to_alloy_block_id(&self, block_ptr: &BlockPtr) -> alloy::rpc::types::BlockId {
652656
if !self.supports_eip_1898 {
653-
alloy_rpc_types::BlockId::number(block_ptr.number as u64)
657+
alloy::rpc::types::BlockId::number(block_ptr.number as u64)
654658
} else {
655-
alloy_rpc_types::BlockId::hash(B256::new(*block_ptr.hash_as_h256().as_fixed_bytes()))
659+
alloy::rpc::types::BlockId::hash(alloy::primitives::B256::new(
660+
*block_ptr.hash_as_h256().as_fixed_bytes(),
661+
))
656662
}
657663
}
658664

@@ -853,7 +859,7 @@ impl EthereumAdapter {
853859

854860
async move {
855861
let block_result = alloy
856-
.get_block_by_number(alloy_rpc_types::BlockNumberOrTag::Number(
862+
.get_block_by_number(alloy::rpc::types::BlockNumberOrTag::Number(
857863
number as u64,
858864
))
859865
.await;
@@ -912,7 +918,7 @@ impl EthereumAdapter {
912918
let alloy = alloy.cheap_clone();
913919
async move {
914920
let block = alloy
915-
.get_block_by_number(alloy_rpc_types::BlockNumberOrTag::Number(
921+
.get_block_by_number(alloy::rpc::types::BlockNumberOrTag::Number(
916922
block_num as u64,
917923
))
918924
.await?;
@@ -1524,7 +1530,7 @@ impl EthereumAdapterTrait for EthereumAdapter {
15241530
let alloy = alloy.cheap_clone();
15251531
async move {
15261532
alloy
1527-
.get_block_by_number(alloy_rpc_types::BlockNumberOrTag::Number(
1533+
.get_block_by_number(alloy::rpc::types::BlockNumberOrTag::Number(
15281534
next_number as u64,
15291535
))
15301536
.await

chain/ethereum/src/runtime/runtime_adapter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use graph::slog::debug;
2323
use graph::{
2424
blockchain::{self, BlockPtr, HostFnCtx},
2525
cheap_clone::CheapClone,
26-
prelude::EthereumCallCache,
26+
prelude::{alloy, EthereumCallCache},
2727
runtime::{asc_get, asc_new, AscPtr, HostExportError},
2828
semver::Version,
2929
slog::Logger,

graph/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub use url;
7979
/// ```
8080
pub mod prelude {
8181
pub use ::anyhow;
82+
pub use alloy;
8283
pub use anyhow::{anyhow, Context as _, Error};
8384
pub use async_trait::async_trait;
8485
pub use atty;

runtime/wasm/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ version.workspace = true
44
edition.workspace = true
55

66
[dependencies]
7-
alloy = { workspace = true }
87
async-trait = "0.1.50"
98
hex = "0.4.3"
109
graph = { path = "../../graph" }

runtime/wasm/src/to_from/external.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ use graph::runtime::{
88
asc_get, asc_new, AscIndexId, AscPtr, AscType, AscValue, HostExportError, ToAscObj,
99
};
1010
use graph::{data::store, runtime::DeterministicHostError};
11-
use graph::{prelude::serde_json, runtime::FromAscObj};
1211
use graph::{prelude::web3::types as web3, runtime::AscHeap};
12+
use graph::{
13+
prelude::{alloy, serde_json},
14+
runtime::FromAscObj,
15+
};
1316
use graph_runtime_derive::AscType;
1417

1518
use crate::asc_abi::class::*;

0 commit comments

Comments
 (0)