Skip to content

Commit 924ff9f

Browse files
committed
minor refactoring
1 parent 30012e2 commit 924ff9f

File tree

10 files changed

+16
-46
lines changed

10 files changed

+16
-46
lines changed

chain/ethereum/src/chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ impl TriggersAdapterTrait<Chain> for TriggersAdapter {
11081108
.load_blocks(
11091109
self.logger.cheap_clone(),
11101110
self.chain_store.cheap_clone(),
1111-
HashSet::from_iter(Some(block.hash_as_b256())),
1111+
HashSet::from_iter(Some(block.hash.as_b256())),
11121112
)
11131113
.await?;
11141114
assert_eq!(blocks.len(), 1);

chain/ethereum/src/ethereum_adapter.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use graph::prelude::{
3939
},
4040
transports::{RpcError, TransportErrorKind},
4141
},
42-
alloy_log_to_web3_log, h256_to_b256,
4342
tokio::try_join,
4443
};
4544
use graph::slog::o;
@@ -568,7 +567,7 @@ impl EthereumAdapter {
568567
if !self.supports_eip_1898 {
569568
alloy::rpc::types::BlockId::number(block_ptr.number as u64)
570569
} else {
571-
alloy::rpc::types::BlockId::hash(block_ptr.hash_as_b256())
570+
alloy::rpc::types::BlockId::hash(block_ptr.hash.as_b256())
572571
}
573572
}
574573

@@ -1692,7 +1691,7 @@ pub(crate) async fn blocks_with_triggers(
16921691
debug!(logger, "Finding nearest valid `to` block to {}", to);
16931692

16941693
let to_ptr = eth.next_existing_ptr_to_number(&logger, to).await?;
1695-
let to_hash = to_ptr.hash_as_b256();
1694+
let to_hash = to_ptr.hash.as_b256();
16961695
let to = to_ptr.block_number();
16971696

16981697
// This is for `start` triggers which can be initialization handlers which needs to be run
@@ -2077,7 +2076,7 @@ async fn filter_call_triggers_from_unsuccessful_transactions(
20772076
// We'll also need the receipts for those transactions. In this step we collect all receipts
20782077
// we have in store for the current block.
20792078
let mut receipts: BTreeMap<B256, LightTransactionReceipt> = chain_store
2080-
.transaction_receipts_in_block(&block.ptr().hash_as_b256())
2079+
.transaction_receipts_in_block(&block.ptr().hash.as_b256())
20812080
.await?
20822081
.into_iter()
20832082
.map(|receipt| (receipt.transaction_hash, receipt))

chain/ethereum/src/trigger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl EthereumTrigger {
308308

309309
pub fn block_hash(&self) -> B256 {
310310
match self {
311-
EthereumTrigger::Block(block_ptr, _) => block_ptr.hash_as_b256(),
311+
EthereumTrigger::Block(block_ptr, _) => block_ptr.hash.as_b256(),
312312
EthereumTrigger::Call(call) => call.block_hash,
313313
EthereumTrigger::Log(log_ref) => log_ref.block_hash().unwrap(),
314314
}

chain/near/src/trigger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ impl NearTrigger {
8080

8181
pub fn block_hash(&self) -> B256 {
8282
match self {
83-
NearTrigger::Block(block) => block.ptr().hash_as_b256(),
84-
NearTrigger::Receipt(receipt) => receipt.block.ptr().hash_as_b256(),
83+
NearTrigger::Block(block) => block.ptr().hash.as_b256(),
84+
NearTrigger::Receipt(receipt) => receipt.block.ptr().hash.as_b256(),
8585
}
8686
}
8787

graph/src/blockchain/types.rs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use alloy::primitives::{B256, U256};
1+
use alloy::primitives::B256;
22
use anyhow::anyhow;
33
use diesel::deserialize::FromSql;
44
use diesel::pg::Pg;
@@ -178,17 +178,6 @@ impl BlockPtr {
178178
self.number
179179
}
180180

181-
// // FIXME:
182-
// //
183-
// // workaround for arweave
184-
// pub fn hash_as_h256(&self) -> H256 {
185-
// H256::from_slice(&self.hash_slice()[..32])
186-
// }
187-
188-
pub fn hash_as_b256(&self) -> B256 {
189-
B256::from_slice(&self.hash_slice()[..32])
190-
}
191-
192181
pub fn hash_slice(&self) -> &[u8] {
193182
self.hash.0.as_ref()
194183
}
@@ -268,8 +257,6 @@ impl From<(B256, u64)> for BlockPtr {
268257
}
269258
}
270259

271-
272-
273260
impl From<(alloy::primitives::B256, i64)> for BlockPtr {
274261
fn from((hash, number): (alloy::primitives::B256, i64)) -> BlockPtr {
275262
let number = i32::try_from(number).unwrap();
@@ -341,7 +328,7 @@ impl IntoValue for BlockPtr {
341328

342329
impl From<BlockPtr> for B256 {
343330
fn from(ptr: BlockPtr) -> Self {
344-
ptr.hash_as_b256()
331+
ptr.hash.as_b256()
345332
}
346333
}
347334

@@ -425,22 +412,6 @@ impl ExtendedBlockPtr {
425412
pub fn block_number(&self) -> BlockNumber {
426413
self.number
427414
}
428-
429-
pub fn hash_as_b256(&self) -> B256 {
430-
B256::from_slice(&self.hash_slice()[..32])
431-
}
432-
433-
pub fn parent_hash_as_b256(&self) -> B256 {
434-
B256::from_slice(&self.parent_hash_slice()[..32])
435-
}
436-
437-
pub fn hash_slice(&self) -> &[u8] {
438-
self.hash.0.as_ref()
439-
}
440-
441-
pub fn parent_hash_slice(&self) -> &[u8] {
442-
self.parent_hash.0.as_ref()
443-
}
444415
}
445416

446417
impl fmt::Display for ExtendedBlockPtr {

graph/src/components/ethereum/types.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ impl BlockWrapper {
4242
}
4343

4444
pub fn timestamp_u64(&self) -> u64 {
45-
alloy_todo!()
46-
// self.0.timestamp.as_u64()
45+
self.0.header.timestamp
4746
}
4847

4948
pub fn transactions(&self) -> &[Transaction] {

graph/src/data_source/common.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ impl CallDecl {
359359
Ok(DynSolValue::Int(x, x.bits() as usize))
360360
}
361361
(DynSolType::Int(_), Value::BigInt(i)) => {
362-
let x = abi::I256::from_le_bytes(i.to_signed_u256().to_le_bytes::<{U256::BYTES}>());
362+
let x =
363+
abi::I256::from_le_bytes(i.to_signed_u256().to_le_bytes::<{ U256::BYTES }>());
363364
Ok(DynSolValue::Int(x, x.bits() as usize))
364365
}
365366
(DynSolType::Uint(_), Value::Int(i)) if *i >= 0 => {

graphql/src/store/resolver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl StoreResolver {
205205
// locate_block indicates that we do not have a block hash
206206
// by setting the hash to `zero`
207207
// See 7a7b9708-adb7-4fc2-acec-88680cb07ec1
208-
let hash_b256 = ptr.hash_as_b256();
208+
let hash_b256 = ptr.hash.as_b256();
209209
if hash_b256 == B256::ZERO {
210210
None
211211
} else {

store/postgres/src/chain_store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,7 +2135,7 @@ impl ChainStoreTrait for ChainStore {
21352135

21362136
let (missing, ptr) = {
21372137
let chain_store = self.clone();
2138-
let genesis_block_ptr = self.genesis_block_ptr()?.hash_as_b256();
2138+
let genesis_block_ptr = self.genesis_block_ptr()?.hash.as_b256();
21392139
self.pool
21402140
.with_conn(move |conn, _| {
21412141
let candidate = chain_store
@@ -2153,7 +2153,7 @@ impl ChainStoreTrait for ChainStore {
21532153
conn,
21542154
&chain_store.chain,
21552155
first_block as i64,
2156-
ptr.hash_as_b256(),
2156+
ptr.hash.as_b256(),
21572157
genesis_block_ptr,
21582158
)
21592159
.map_err(CancelableError::from)?

store/postgres/src/subgraph_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::{
1111
};
1212
use std::{iter::FromIterator, time::Duration};
1313

14-
use graph::{futures03::future::join_all, prelude::alloy::primitives::Address};
1514
use graph::{
1615
cheap_clone::CheapClone,
1716
components::{
@@ -35,6 +34,7 @@ use graph::{
3534
url::Url,
3635
util::timed_cache::TimedCache,
3736
};
37+
use graph::{futures03::future::join_all, prelude::alloy::primitives::Address};
3838

3939
use crate::{
4040
deployment::{OnSync, SubgraphHealth},

0 commit comments

Comments
 (0)