Skip to content

Commit 50ad26b

Browse files
committed
graph, chain: code cleanup and refactor
1 parent dffa7f8 commit 50ad26b

File tree

8 files changed

+59
-38
lines changed

8 files changed

+59
-38
lines changed

Cargo.lock

Lines changed: 45 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chain/ethereum/src/codec.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,13 @@ where
4141
}
4242
}
4343

44-
// impl TryDecodeProto<[u8; 256], H2048> for &[u8] {}
45-
// impl TryDecodeProto<[u8; 32], H256> for &[u8] {}
46-
// impl TryDecodeProto<[u8; 20], H160> for &[u8] {}
47-
4844
impl TryDecodeProto<[u8; 32], B256> for &[u8] {}
4945
impl TryDecodeProto<[u8; 256], B2048> for &[u8] {}
5046
impl TryDecodeProto<[u8; 20], Address> for &[u8] {}
5147

52-
impl From<&BigInt> for alloy::primitives::U256 {
48+
impl From<&BigInt> for U256 {
5349
fn from(val: &BigInt) -> Self {
54-
alloy::primitives::U256::from_be_slice(&val.bytes)
50+
U256::from_be_slice(&val.bytes)
5551
}
5652
}
5753

@@ -78,7 +74,7 @@ impl<'a> TryInto<EthereumCall> for CallAt<'a> {
7874
.call
7975
.value
8076
.as_ref()
81-
.map_or_else(|| alloy::primitives::U256::from(0), |v| v.into()),
77+
.map_or_else(|| U256::from(0), |v| v.into()),
8278
gas_used: self.call.gas_consumed,
8379
input: Bytes::from(self.call.input.clone()),
8480
output: Bytes::from(self.call.return_data.clone()),

chain/ethereum/src/data_source.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,9 +1521,6 @@ fn string_to_b256(s: &str) -> B256 {
15211521
sponge.update(&data);
15221522
sponge.finalize(&mut result);
15231523

1524-
// This was deprecated but the replacement seems to not be available in the
1525-
// version web3 uses.
1526-
#[allow(deprecated)]
15271524
B256::from_slice(&result)
15281525
}
15291526

chain/ethereum/src/ethereum_adapter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,7 @@ async fn filter_call_triggers_from_unsuccessful_transactions(
20472047
match &block.block {
20482048
BlockFinality::Final(ref block) => block
20492049
.transactions()
2050+
.ok_or_else(|| anyhow!("Block transactions not available"))?
20502051
.iter()
20512052
.filter(|transaction| transaction_hashes.contains(transaction.inner.tx_hash()))
20522053
.collect(),

graph/src/blockchain/types.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@ impl fmt::LowerHex for BlockHash {
8585
}
8686
}
8787

88-
// impl From<H256> for BlockHash {
89-
// fn from(hash: H256) -> Self {
90-
// BlockHash(hash.as_bytes().into())
91-
// }
92-
// }
93-
9488
impl From<Vec<u8>> for BlockHash {
9589
fn from(bytes: Vec<u8>) -> Self {
9690
BlockHash(bytes.as_slice().into())

graph/src/components/ethereum/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ impl BlockWrapper {
3434
self.0.header.timestamp
3535
}
3636

37-
pub fn transactions(&self) -> &[Transaction] {
38-
&self.0.transactions.as_transactions().unwrap()
37+
pub fn transactions(&self) -> Option<&[Transaction]> {
38+
self.0.transactions.as_transactions()
3939
}
4040

4141
pub fn inner(&self) -> &AlloyBlock {

tests/src/contract.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ use std::str::FromStr;
33
use graph::prelude::{
44
lazy_static,
55
serde_json::{self, Value},
6-
web3::{
7-
api::{Eth, Namespace},
8-
contract::{tokens::Tokenize, Contract as Web3Contract, Options},
9-
transports::Http,
10-
types::{Address, Block, BlockId, BlockNumber, Bytes, TransactionReceipt, H256},
11-
},
6+
};
7+
8+
use web3::{
9+
api::{Eth, Namespace},
10+
contract::{tokens::Tokenize, Contract as Web3Contract, Options},
11+
transports::Http,
12+
types::{Address, Block, BlockId, BlockNumber, Bytes, TransactionReceipt, H256},
1213
};
1314
// web3 version 0.18 does not expose this; once the graph crate updates to
1415
// version 0.19, we can use web3::signing::SecretKey from the graph crate

tests/tests/runner_tests.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ use graph::env::{EnvVars, TEST_WITH_NO_REORG};
1515
use graph::ipfs::test_utils::add_files_to_local_ipfs_node_for_testing;
1616
use graph::object;
1717
use graph::prelude::alloy::primitives::{Address, B256, U256};
18-
use graph::prelude::{
19-
hex, CheapClone, DeploymentHash, SubgraphAssignmentProvider, SubgraphName, SubgraphStore,
20-
};
18+
use graph::prelude::{hex, CheapClone, SubgraphAssignmentProvider, SubgraphName, SubgraphStore};
2119
use graph_tests::fixture::ethereum::{
2220
chain, empty_block, generate_empty_blocks_for_range, genesis, push_test_command, push_test_log,
2321
push_test_polling_trigger,

0 commit comments

Comments
 (0)