Skip to content

Commit 5f8af01

Browse files
committed
graph, chain: code cleanup and refactor
1 parent 21d7cce commit 5f8af01

File tree

9 files changed

+23
-33
lines changed

9 files changed

+23
-33
lines changed

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
@@ -1589,9 +1589,6 @@ fn string_to_b256(s: &str) -> B256 {
15891589
sponge.update(&data);
15901590
sponge.finalize(&mut result);
15911591

1592-
// This was deprecated but the replacement seems to not be available in the
1593-
// version web3 uses.
1594-
#[allow(deprecated)]
15951592
B256::from_slice(&result)
15961593
}
15971594

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 {

graph/src/data_source/common.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,11 @@ impl CallDecl {
415415
self.expr.validate_args()
416416
}
417417

418-
pub fn address_for_log(&self, log: &Log, params: &[abi::DynSolParam]) -> Result<Address, Error> {
418+
pub fn address_for_log(
419+
&self,
420+
log: &Log,
421+
params: &[abi::DynSolParam],
422+
) -> Result<Address, Error> {
419423
self.address_for_log_with_abi(log, params)
420424
}
421425

runtime/wasm/src/to_from/external.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use graph::{
1616
},
1717
runtime::FromAscObj,
1818
};
19-
use graph_runtime_derive::AscType;
2019

2120
use crate::asc_abi::class::*;
2221

tests/src/contract.rs

Lines changed: 11 additions & 10 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
@@ -161,16 +162,16 @@ impl Contract {
161162
if contract.name == "DeclaredCallsContract" {
162163
status!("contracts", "Emitting transfers from DeclaredCallsContract");
163164
let addr1 = "0x1111111111111111111111111111111111111111"
164-
.parse::<graph::prelude::web3::types::Address>()
165+
.parse::<web3::types::Address>()
165166
.unwrap();
166167
let addr2 = "0x2222222222222222222222222222222222222222"
167-
.parse::<graph::prelude::web3::types::Address>()
168+
.parse::<web3::types::Address>()
168169
.unwrap();
169170
let addr3 = "0x3333333333333333333333333333333333333333"
170-
.parse::<graph::prelude::web3::types::Address>()
171+
.parse::<web3::types::Address>()
171172
.unwrap();
172173
let addr4 = "0x4444444444444444444444444444444444444444"
173-
.parse::<graph::prelude::web3::types::Address>()
174+
.parse::<web3::types::Address>()
174175
.unwrap();
175176

176177
contract

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)