Skip to content

Commit b44014f

Browse files
committed
checkpoint
1 parent 72bf098 commit b44014f

File tree

3 files changed

+59
-95
lines changed

3 files changed

+59
-95
lines changed

chain/ethereum/src/data_source.rs

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use anyhow::{anyhow, Error};
22
use anyhow::{ensure, Context};
3-
use graph::abi;
43
use graph::abi::EventExt;
54
use graph::abi::FunctionExt;
65
use graph::blockchain::{BlockPtr, TriggerWithHandler};
@@ -19,8 +18,11 @@ use graph::env::ENV_VARS;
1918
use graph::futures03::future::try_join;
2019
use graph::futures03::stream::FuturesOrdered;
2120
use graph::futures03::TryStreamExt;
22-
use graph::prelude::{Link, SubgraphManifestValidationError};
21+
use graph::prelude::alloy::primitives::{Address, B256};
22+
use graph::prelude::alloy::rpc::types::Log;
23+
use graph::prelude::{alloy, b256_to_h256, Link, SubgraphManifestValidationError};
2324
use graph::slog::{debug, error, o, trace};
25+
use graph::{abi, alloy_todo};
2426
use itertools::Itertools;
2527
use serde::de::Error as ErrorD;
2628
use serde::{Deserialize, Deserializer};
@@ -35,7 +37,7 @@ use graph::{
3537
blockchain::{self, Blockchain},
3638
prelude::{
3739
async_trait, serde_json, warn,
38-
web3::types::{Address, Log, Transaction, H160, H256},
40+
web3::types::{H160, H256},
3941
BlockNumber, CheapClone, EthereumCall, LightEthereumBlock, LightEthereumBlockExt,
4042
LinkResolver, Logger,
4143
},
@@ -462,7 +464,7 @@ impl DataSource {
462464
})
463465
}
464466

465-
fn handlers_for_log(&self, log: &Log) -> Vec<MappingEventHandler> {
467+
fn handlers_for_log(&self, log: &alloy::rpc::types::Log) -> Vec<MappingEventHandler> {
466468
self.mapping
467469
.event_handlers
468470
.iter()
@@ -640,7 +642,7 @@ impl DataSource {
640642
return true;
641643
};
642644

643-
ds_address == *trigger_address
645+
ds_address == trigger_address
644646
}
645647

646648
/// Checks if `trigger` matches this data source, and if so decodes it into a `MappingTrigger`.
@@ -748,17 +750,18 @@ impl DataSource {
748750
// See also ca0edc58-0ec5-4c89-a7dd-2241797f5e50.
749751
// There is another special case in zkSync-era, where the transaction hash in this case would be zero
750752
// See https://docs.zksync.io/zk-stack/concepts/blocks.html#fictive-l2-block-finalizing-the-batch
751-
let transaction = if log.transaction_hash == block.hash_h256()
752-
|| log.transaction_hash == Some(H256::zero())
753+
let transaction = if log.transaction_hash == Some(block.hash())
754+
|| log.transaction_hash == Some(B256::ZERO)
753755
{
754-
Transaction {
755-
hash: log.transaction_hash.unwrap(),
756-
block_hash: block.hash_h256(),
757-
block_number: block.number_web3_u64(),
758-
transaction_index: log.transaction_index,
759-
from: Some(H160::zero()),
760-
..Transaction::default()
761-
}
756+
// Transaction {
757+
// hash: log.transaction_hash.unwrap(),
758+
// block_hash: block.hash_h256(),
759+
// block_number: block.number_web3_u64(),
760+
// transaction_index: log.transaction_index,
761+
// from: Some(H160::zero()),
762+
// ..Transaction::default()
763+
// }
764+
alloy_todo!()
762765
} else {
763766
// This is the general case where the log's transaction hash does not match the block's hash
764767
// and is not a special zero hash, implying a real transaction associated with this log.
@@ -1438,12 +1441,12 @@ pub struct MappingCallHandler {
14381441
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
14391442
pub struct UnresolvedMappingEventHandler {
14401443
pub event: String,
1441-
pub topic0: Option<H256>,
1442-
#[serde(deserialize_with = "deserialize_h256_vec", default)]
1443-
pub topic1: Option<Vec<H256>>,
1444-
#[serde(deserialize_with = "deserialize_h256_vec", default)]
1445-
pub topic2: Option<Vec<H256>>,
1446-
#[serde(deserialize_with = "deserialize_h256_vec", default)]
1444+
pub topic0: Option<B256>,
1445+
#[serde(deserialize_with = "deserialize_b256_vec", default)]
1446+
pub topic1: Option<Vec<B256>>,
1447+
#[serde(deserialize_with = "deserialize_b256_vec", default)]
1448+
pub topic2: Option<Vec<B256>>,
1449+
#[serde(deserialize_with = "deserialize_b256_vec", default)]
14471450
pub topic3: Option<Vec<H256>>,
14481451
pub handler: String,
14491452
#[serde(default)]
@@ -1488,27 +1491,27 @@ pub struct MappingEventHandler {
14881491
}
14891492

14901493
// Custom deserializer for H256 fields that removes the '0x' prefix before parsing
1491-
fn deserialize_h256_vec<'de, D>(deserializer: D) -> Result<Option<Vec<H256>>, D::Error>
1494+
fn deserialize_b256_vec<'de, D>(deserializer: D) -> Result<Option<Vec<H256>>, D::Error>
14921495
where
14931496
D: Deserializer<'de>,
14941497
{
14951498
let s: Option<Vec<String>> = Option::deserialize(deserializer)?;
14961499

14971500
match s {
14981501
Some(vec) => {
1499-
let mut h256_vec = Vec::new();
1502+
let mut b256_vec = Vec::new();
15001503
for hex_str in vec {
15011504
// Remove '0x' prefix if present
15021505
let clean_hex_str = hex_str.trim_start_matches("0x");
15031506
// Ensure the hex string is 64 characters long, after removing '0x'
15041507
let padded_hex_str = format!("{:0>64}", clean_hex_str);
15051508
// Parse the padded string into H256, handling potential errors
1506-
h256_vec.push(
1507-
H256::from_str(&padded_hex_str)
1508-
.map_err(|e| D::Error::custom(format!("Failed to parse H256: {}", e)))?,
1509+
b256_vec.push(
1510+
B256::from_str(&padded_hex_str)
1511+
.map_err(|e| D::Error::custom(format!("Failed to parse B256: {}", e)))?,
15091512
);
15101513
}
1511-
Ok(Some(h256_vec))
1514+
Ok(Some(b256_vec))
15121515
}
15131516
None => Ok(None),
15141517
}
@@ -1521,16 +1524,16 @@ impl MappingEventHandler {
15211524
}
15221525

15231526
pub fn matches(&self, log: &Log) -> bool {
1524-
let matches_topic = |index: usize, topic_opt: &Option<Vec<H256>>| -> bool {
1527+
let matches_topic = |index: usize, topic_opt: &Option<Vec<B256>>| -> bool {
15251528
topic_opt.as_ref().map_or(true, |topic_vec| {
1526-
log.topics
1529+
log.topics()
15271530
.get(index)
15281531
.map_or(false, |log_topic| topic_vec.contains(log_topic))
15291532
})
15301533
};
15311534

1532-
if let Some(topic0) = log.topics.get(0) {
1533-
return self.topic0() == *topic0
1535+
if let Some(topic0) = log.topics().get(0) {
1536+
return self.topic0() == b256_to_h256(*topic0)
15341537
&& matches_topic(1, &self.topic1)
15351538
&& matches_topic(2, &self.topic2)
15361539
&& matches_topic(3, &self.topic3);

chain/ethereum/src/trigger.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ use graph::data::subgraph::API_VERSION_0_0_2;
55
use graph::data::subgraph::API_VERSION_0_0_6;
66
use graph::data::subgraph::API_VERSION_0_0_7;
77
use graph::data_source::common::DeclaredCall;
8+
use graph::prelude::alloy::primitives::Address;
9+
use graph::prelude::alloy::primitives::B256;
10+
use graph::prelude::alloy::rpc::types::Log;
811
use graph::prelude::alloy::rpc::types::TransactionReceipt as AlloyTransactionReceipt;
9-
use graph::prelude::web3::types::Address;
10-
use graph::prelude::web3::types::Log;
1112
use graph::prelude::web3::types::Transaction;
1213
use graph::prelude::web3::types::H160;
1314
use graph::prelude::web3::types::H256;
@@ -24,7 +25,6 @@ use graph::runtime::AscHeap;
2425
use graph::runtime::AscPtr;
2526
use graph::runtime::HostExportError;
2627
use graph::semver::Version;
27-
use graph::util::conversions::alloy_log_ref_to_web3_log_ref;
2828
use graph_runtime_wasm::module::ToAscPtr;
2929
use std::{cmp::Ordering, sync::Arc};
3030

@@ -230,9 +230,7 @@ impl LogRef {
230230
pub fn log(&self) -> &Log {
231231
match self {
232232
LogRef::FullLog(log, _) => log.as_ref(),
233-
LogRef::LogPosition(index, receipt) => {
234-
alloy_log_ref_to_web3_log_ref(receipt.logs().get(*index).unwrap())
235-
}
233+
LogRef::LogPosition(index, receipt) => receipt.logs().get(*index).unwrap(),
236234
}
237235
}
238236

@@ -243,27 +241,27 @@ impl LogRef {
243241
}
244242
}
245243

246-
pub fn log_index(&self) -> Option<U256> {
244+
pub fn log_index(&self) -> Option<u64> {
247245
self.log().log_index
248246
}
249247

250-
pub fn transaction_index(&self) -> Option<U64> {
248+
pub fn transaction_index(&self) -> Option<u64> {
251249
self.log().transaction_index
252250
}
253251

254-
fn transaction_hash(&self) -> Option<H256> {
252+
fn transaction_hash(&self) -> Option<B256> {
255253
self.log().transaction_hash
256254
}
257255

258-
pub fn block_hash(&self) -> Option<H256> {
256+
pub fn block_hash(&self) -> Option<B256> {
259257
self.log().block_hash
260258
}
261259

262-
pub fn block_number(&self) -> Option<U64> {
260+
pub fn block_number(&self) -> Option<u64> {
263261
self.log().block_number
264262
}
265263

266-
pub fn address(&self) -> &H160 {
264+
pub fn address(&self) -> &Address {
267265
&self.log().address
268266
}
269267
}

graph/src/components/ethereum/types.rs

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
use alloy::rpc::types::trace::parity::{Action, LocalizedTransactionTrace, TraceOutput};
1+
use alloy::{
2+
primitives::B256,
3+
rpc::types::trace::parity::{Action, LocalizedTransactionTrace, TraceOutput},
4+
};
25
use serde::{Deserialize, Serialize};
3-
use std::{convert::TryFrom, sync::Arc};
4-
use web3::types::{Address, Bytes, Log, Transaction, TransactionReceipt, H256, U256, U64};
6+
use std::sync::Arc;
7+
use web3::types::{Address, Bytes, Log, Transaction, U256, U64};
58

69
use crate::{
710
alloy_todo,
@@ -22,11 +25,15 @@ impl BlockWrapper {
2225
Self(block)
2326
}
2427

25-
pub fn hash_h256(&self) -> Option<H256> {
28+
pub fn hash_h256(&self) -> Option<B256> {
2629
alloy_todo!()
2730
// self.0.hash
2831
}
2932

33+
pub fn hash(&self) -> B256 {
34+
self.0.header.hash
35+
}
36+
3037
pub fn number_u64(&self) -> Option<u64> {
3138
alloy_todo!()
3239
// self.0.number.map(|n| n.as_u64())
@@ -57,7 +64,7 @@ pub type LightEthereumBlock = BlockWrapper;
5764

5865
pub trait LightEthereumBlockExt {
5966
fn number(&self) -> BlockNumber;
60-
fn transaction_for_log(&self, log: &Log) -> Option<Transaction>;
67+
fn transaction_for_log(&self, log: &alloy::rpc::types::Log) -> Option<Transaction>;
6168
fn transaction_for_call(&self, call: &EthereumCall) -> Option<Transaction>;
6269
fn parent_ptr(&self) -> Option<BlockPtr>;
6370
fn format(&self) -> String;
@@ -106,7 +113,7 @@ impl LightEthereumBlockExt for LightEthereumBlock {
106113
self.0.number()
107114
}
108115

109-
fn transaction_for_log(&self, log: &Log) -> Option<Transaction> {
116+
fn transaction_for_log(&self, log: &alloy::rpc::types::Log) -> Option<Transaction> {
110117
self.0.transaction_for_log(log)
111118
}
112119

@@ -131,50 +138,6 @@ impl LightEthereumBlockExt for LightEthereumBlock {
131138
}
132139
}
133140

134-
impl LightEthereumBlockExt for web3::types::Block<Transaction> {
135-
fn number(&self) -> BlockNumber {
136-
BlockNumber::try_from(self.number.unwrap().as_u64()).unwrap()
137-
}
138-
139-
fn transaction_for_log(&self, log: &Log) -> Option<Transaction> {
140-
log.transaction_hash
141-
.and_then(|hash| self.transactions.iter().find(|tx| tx.hash == hash))
142-
.cloned()
143-
}
144-
145-
fn transaction_for_call(&self, call: &EthereumCall) -> Option<Transaction> {
146-
call.transaction_hash
147-
.and_then(|hash| self.transactions.iter().find(|tx| tx.hash == hash))
148-
.cloned()
149-
}
150-
151-
fn parent_ptr(&self) -> Option<BlockPtr> {
152-
match self.number() {
153-
0 => None,
154-
n => Some(BlockPtr::from((self.parent_hash, n - 1))),
155-
}
156-
}
157-
158-
fn format(&self) -> String {
159-
format!(
160-
"{} ({})",
161-
self.number
162-
.map_or(String::from("none"), |number| format!("#{}", number)),
163-
self.hash
164-
.map_or(String::from("-"), |hash| format!("{:x}", hash))
165-
)
166-
}
167-
168-
fn block_ptr(&self) -> BlockPtr {
169-
BlockPtr::from((self.hash.unwrap(), self.number.unwrap().as_u64()))
170-
}
171-
172-
fn timestamp(&self) -> BlockTime {
173-
let ts = i64::try_from(self.timestamp.as_u64()).unwrap();
174-
BlockTime::since_epoch(ts, 0)
175-
}
176-
}
177-
178141
#[derive(Clone, Debug)]
179142
pub struct EthereumBlockWithCalls {
180143
pub ethereum_block: EthereumBlock,
@@ -228,8 +191,8 @@ pub struct EthereumCall {
228191
pub input: Bytes,
229192
pub output: Bytes,
230193
pub block_number: BlockNumber,
231-
pub block_hash: H256,
232-
pub transaction_hash: Option<H256>,
194+
pub block_hash: B256,
195+
pub transaction_hash: Option<B256>,
233196
pub transaction_index: u64,
234197
}
235198

0 commit comments

Comments
 (0)