Skip to content

Commit 17b94b9

Browse files
committed
chain/ethereum: migrate get_code call to use alloy
1 parent 8ab16ef commit 17b94b9

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

chain/ethereum/src/adapter.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use graph::data_source::common::ContractCall;
99
use graph::firehose::CallToFilter;
1010
use graph::firehose::CombinedFilter;
1111
use graph::firehose::LogFilter;
12-
use graph::prelude::web3::types::Bytes;
1312
use graph::prelude::web3::types::H160;
1413
use itertools::Itertools;
1514
use prost::Message;
@@ -1182,9 +1181,9 @@ pub trait EthereumAdapter: Send + Sync + 'static {
11821181
async fn get_code(
11831182
&self,
11841183
logger: &Logger,
1185-
address: H160,
1184+
address: alloy::primitives::Address,
11861185
block_ptr: BlockPtr,
1187-
) -> Result<Bytes, EthereumRpcError>;
1186+
) -> Result<alloy::primitives::Bytes, EthereumRpcError>;
11881187
}
11891188

11901189
#[cfg(test)]

chain/ethereum/src/ethereum_adapter.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ use graph::{
3333
web3::{
3434
self,
3535
types::{
36-
Address, BlockId, BlockNumber as Web3BlockNumber, Bytes, CallRequest, Filter,
37-
FilterBuilder, Log, Transaction, TransactionReceipt, H256,
36+
BlockId, BlockNumber as Web3BlockNumber, Bytes, CallRequest, Filter, FilterBuilder,
37+
Log, Transaction, TransactionReceipt, H256,
3838
},
3939
},
4040
BlockNumber, ChainStore, CheapClone, DynTryFuture, Error, EthereumCallCache, Logger,
@@ -659,13 +659,13 @@ impl EthereumAdapter {
659659
async fn code(
660660
&self,
661661
logger: &Logger,
662-
address: Address,
662+
address: alloy::primitives::Address,
663663
block_ptr: BlockPtr,
664-
) -> Result<Bytes, EthereumRpcError> {
665-
let web3 = self.web3.clone();
664+
) -> Result<alloy::primitives::Bytes, EthereumRpcError> {
665+
let alloy = self.alloy.clone();
666666
let logger = Logger::new(&logger, o!("provider" => self.provider.clone()));
667667

668-
let block_id = self.block_ptr_to_id(&block_ptr);
668+
let block_id = self.block_ptr_to_alloy_block_id(&block_ptr);
669669
let retry_log_message = format!("eth_getCode RPC call for block {}", block_ptr);
670670

671671
retry(retry_log_message, &logger)
@@ -677,13 +677,12 @@ impl EthereumAdapter {
677677
.limit(ENV_VARS.request_retries)
678678
.timeout_secs(ENV_VARS.json_rpc_timeout.as_secs())
679679
.run(move || {
680-
let web3 = web3.cheap_clone();
680+
let alloy = alloy.cheap_clone();
681681
async move {
682-
let result: Result<Bytes, web3::Error> =
683-
web3.eth().code(address, Some(block_id)).boxed().await;
682+
let result = alloy.get_code_at(address).block_id(block_id).await;
684683
match result {
685684
Ok(code) => Ok(code),
686-
Err(err) => Err(EthereumRpcError::Web3Error(err)),
685+
Err(err) => Err(EthereumRpcError::AlloyError(err)),
687686
}
688687
}
689688
})
@@ -1528,9 +1527,9 @@ impl EthereumAdapterTrait for EthereumAdapter {
15281527
async fn get_code(
15291528
&self,
15301529
logger: &Logger,
1531-
address: H160,
1530+
address: alloy::primitives::Address,
15321531
block_ptr: BlockPtr,
1533-
) -> Result<Bytes, EthereumRpcError> {
1532+
) -> Result<alloy::primitives::Bytes, EthereumRpcError> {
15341533
debug!(
15351534
logger, "eth_getCode";
15361535
"address" => format!("{}", address),

chain/ethereum/src/runtime/runtime_adapter.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use graph::data::subgraph::API_VERSION_0_0_9;
1717
use graph::data_source;
1818
use graph::data_source::common::{ContractCall, MappingABI};
1919
use graph::prelude::web3::types::Address;
20-
use graph::prelude::web3::types::H160;
2120
use graph::runtime::gas::Gas;
2221
use graph::runtime::{AscIndexId, IndexForAscTypeId};
2322
use graph::slog::debug;
@@ -259,10 +258,10 @@ fn eth_has_code(
259258
let logger = &ctx.logger;
260259
let block_ptr = &ctx.block_ptr;
261260

262-
let address: H160 = asc_get(ctx.heap, wasm_ptr.into(), &ctx.gas, 0)?;
261+
let address: alloy::primitives::Address = asc_get(ctx.heap, wasm_ptr.into(), &ctx.gas, 0)?;
263262

264263
let result = graph::block_on(eth_adapter.get_code(logger, address, block_ptr.clone()))
265-
.map(|v| !v.0.is_empty());
264+
.map(|v| !v.is_empty());
266265

267266
match result {
268267
Ok(v) => Ok(asc_new(ctx.heap, &AscWrapped { inner: v }, &ctx.gas)?),

0 commit comments

Comments
 (0)