Skip to content

Commit 75ae18a

Browse files
committed
graph: Rename BlockWrapper to LightEthereumBlock and fix silent truncations
- Rename BlockWrapper struct to LightEthereumBlock directly, removing the unnecessary type alias indirection - Fix silent truncation in AnyBlock::number() - use try_from().unwrap() instead of `as BlockNumber` - Fix silent truncation in AnyBlock::block_ptr() - route through From<(B256, u64)> instead of direct `as i32` cast
1 parent 4f1d415 commit 75ae18a

3 files changed

Lines changed: 12 additions & 15 deletions

File tree

graph/src/blockchain/types.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::convert::TryFrom;
1111
use std::time::Duration;
1212
use std::{fmt, str::FromStr};
1313

14-
use crate::components::ethereum::BlockWrapper;
14+
use crate::components::ethereum::LightEthereumBlock;
1515

1616
use crate::cheap_clone::CheapClone;
1717
use crate::components::store::BlockNumber;
@@ -200,14 +200,14 @@ impl slog::Value for BlockPtr {
200200
}
201201
}
202202

203-
impl From<BlockWrapper> for BlockPtr {
204-
fn from(b: BlockWrapper) -> BlockPtr {
203+
impl From<LightEthereumBlock> for BlockPtr {
204+
fn from(b: LightEthereumBlock) -> BlockPtr {
205205
BlockPtr::from((b.hash(), b.number_u64()))
206206
}
207207
}
208208

209-
impl From<&BlockWrapper> for BlockPtr {
210-
fn from(b: &BlockWrapper) -> BlockPtr {
209+
impl From<&LightEthereumBlock> for BlockPtr {
210+
fn from(b: &LightEthereumBlock) -> BlockPtr {
211211
BlockPtr::from((b.hash(), b.number_u64()))
212212
}
213213
}

graph/src/components/ethereum/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
mod types;
22

33
pub use self::types::{
4-
evaluate_transaction_status, AnyBlock, AnyTransaction, BlockWrapper, EthereumBlock,
5-
EthereumBlockWithCalls, EthereumCall, LightEthereumBlock, LightEthereumBlockExt,
4+
evaluate_transaction_status, AnyBlock, AnyTransaction, EthereumBlock, EthereumBlockWithCalls,
5+
EthereumCall, LightEthereumBlock, LightEthereumBlockExt,
66
};
77

88
// Re-export Alloy network types for convenience

graph/src/components/ethereum/types.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ use crate::{
1818
pub type AnyTransaction = AnyRpcTransaction;
1919
pub type AnyBlock = AnyRpcBlock;
2020

21-
// BlockWrapper wraps AnyBlock
2221
#[allow(dead_code)]
2322
#[derive(Debug, Deserialize, Serialize)]
24-
pub struct BlockWrapper(AnyBlock);
23+
pub struct LightEthereumBlock(AnyBlock);
2524

26-
impl Default for BlockWrapper {
25+
impl Default for LightEthereumBlock {
2726
fn default() -> Self {
2827
use alloy::rpc::types::{Block, BlockTransactions};
2928
use alloy::serde::WithOtherFields;
@@ -38,7 +37,7 @@ impl Default for BlockWrapper {
3837
}
3938
}
4039

41-
impl BlockWrapper {
40+
impl LightEthereumBlock {
4241
pub fn new(block: AnyBlock) -> Self {
4342
Self(block)
4443
}
@@ -68,8 +67,6 @@ impl BlockWrapper {
6867
}
6968
}
7069

71-
pub type LightEthereumBlock = BlockWrapper;
72-
7370
pub trait LightEthereumBlockExt {
7471
fn number(&self) -> BlockNumber;
7572
fn transaction_for_log(&self, log: &Log) -> Option<AnyTransaction>;
@@ -82,7 +79,7 @@ pub trait LightEthereumBlockExt {
8279

8380
impl LightEthereumBlockExt for AnyBlock {
8481
fn number(&self) -> BlockNumber {
85-
self.header.number as BlockNumber
82+
BlockNumber::try_from(self.header.number).unwrap()
8683
}
8784

8885
fn timestamp(&self) -> BlockTime {
@@ -124,7 +121,7 @@ impl LightEthereumBlockExt for AnyBlock {
124121
}
125122

126123
fn block_ptr(&self) -> BlockPtr {
127-
BlockPtr::new(self.header.hash.into(), self.header.number as i32)
124+
BlockPtr::from((self.header.hash, self.header.number))
128125
}
129126
}
130127

0 commit comments

Comments
 (0)