Skip to content

Commit e150b02

Browse files
committed
cleanup typos, commented out code and minor refactoring
1 parent d211801 commit e150b02

File tree

15 files changed

+64
-132
lines changed

15 files changed

+64
-132
lines changed

chain/ethereum/src/ethereum_adapter.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ use graph::futures03::future::try_join_all;
2020
use graph::futures03::{
2121
self, compat::Future01CompatExt, FutureExt, StreamExt, TryFutureExt, TryStreamExt,
2222
};
23-
use graph::prelude::alloy::primitives::Address;
2423
use graph::prelude::{
2524
alloy::{
2625
self,
2726
network::{AnyNetwork, TransactionResponse},
28-
primitives::B256,
27+
primitives::{Address, B256},
2928
providers::{
3029
ext::TraceApi,
3130
fillers::{
@@ -182,7 +181,7 @@ impl EthereumAdapter {
182181
subgraph_metrics: Arc<SubgraphEthRpcMetrics>,
183182
from: BlockNumber,
184183
to: BlockNumber,
185-
addresses: Vec<alloy::primitives::Address>,
184+
addresses: Vec<Address>,
186185
) -> Result<Vec<LocalizedTransactionTrace>, Error> {
187186
assert!(!self.call_only);
188187

@@ -223,7 +222,7 @@ impl EthereumAdapter {
223222
subgraph_metrics: Arc<SubgraphEthRpcMetrics>,
224223
from: BlockNumber,
225224
to: BlockNumber,
226-
addresses: Vec<alloy::primitives::Address>,
225+
addresses: Vec<Address>,
227226
) -> Result<Vec<LocalizedTransactionTrace>, Error> {
228227
let alloy_trace_filter = Self::build_trace_filter(from, to, &addresses);
229228
let start = Instant::now();
@@ -249,7 +248,7 @@ impl EthereumAdapter {
249248
fn build_trace_filter(
250249
from: BlockNumber,
251250
to: BlockNumber,
252-
addresses: &[alloy::primitives::Address],
251+
addresses: &[Address],
253252
) -> AlloyTraceFilter {
254253
let filter = AlloyTraceFilter::default()
255254
.from_block(from as u64)
@@ -420,7 +419,7 @@ impl EthereumAdapter {
420419
subgraph_metrics: Arc<SubgraphEthRpcMetrics>,
421420
from: BlockNumber,
422421
to: BlockNumber,
423-
addresses: Vec<alloy::primitives::Address>,
422+
addresses: Vec<Address>,
424423
) -> impl futures03::Stream<Item = Result<LocalizedTransactionTrace, Error>> + Send {
425424
if from > to {
426425
panic!(
@@ -575,7 +574,7 @@ impl EthereumAdapter {
575574
async fn code(
576575
&self,
577576
logger: &Logger,
578-
address: alloy::primitives::Address,
577+
address: Address,
579578
block_ptr: BlockPtr,
580579
) -> Result<alloy::primitives::Bytes, EthereumRpcError> {
581580
let alloy = self.alloy.clone();
@@ -609,7 +608,7 @@ impl EthereumAdapter {
609608
async fn balance(
610609
&self,
611610
logger: &Logger,
612-
address: alloy::primitives::Address,
611+
address: Address,
613612
block_ptr: BlockPtr,
614613
) -> Result<alloy::primitives::U256, EthereumRpcError> {
615614
let alloy = self.alloy.clone();
@@ -1372,7 +1371,7 @@ impl EthereumAdapterTrait for EthereumAdapter {
13721371
async fn get_balance(
13731372
&self,
13741373
logger: &Logger,
1375-
address: alloy::primitives::Address,
1374+
address: Address,
13761375
block_ptr: BlockPtr,
13771376
) -> Result<alloy::primitives::U256, EthereumRpcError> {
13781377
debug!(
@@ -1386,7 +1385,7 @@ impl EthereumAdapterTrait for EthereumAdapter {
13861385
async fn get_code(
13871386
&self,
13881387
logger: &Logger,
1389-
address: alloy::primitives::Address,
1388+
address: Address,
13901389
block_ptr: BlockPtr,
13911390
) -> Result<alloy::primitives::Bytes, EthereumRpcError> {
13921391
debug!(

chain/ethereum/src/runtime/abi.rs

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ where
595595
EthereumTransactionData<'a>: ToAscObj<T>,
596596
EthereumBlockData<'a>: ToAscObj<B>,
597597
Inner: Send + Sync,
598-
for<'b> &'b TransactionReceipt<Inner>: ToAscObj<AscEthereumTransactionReceipt>,
598+
TransactionReceipt<Inner>: ToAscObj<AscEthereumTransactionReceipt>,
599599
{
600600
fn to_asc_obj<H: AscHeap + ?Sized>(
601601
&self,
@@ -673,51 +673,8 @@ impl ToAscObj<AscEthereumLog> for Log {
673673
}
674674
}
675675

676-
impl ToAscObj<AscEthereumTransactionReceipt> for &alloy::rpc::types::TransactionReceipt {
677-
fn to_asc_obj<H: AscHeap + ?Sized>(
678-
&self,
679-
heap: &mut H,
680-
gas: &GasCounter,
681-
) -> Result<AscEthereumTransactionReceipt, HostExportError> {
682-
Ok(AscEthereumTransactionReceipt {
683-
transaction_hash: asc_new(heap, &self.transaction_hash, gas)?,
684-
transaction_index: asc_new(
685-
heap,
686-
&BigInt::from(
687-
self.transaction_index
688-
.ok_or(HostExportError::Unknown(anyhow!(
689-
"Transaction index is missing"
690-
)))?,
691-
),
692-
gas,
693-
)?,
694-
block_hash: self
695-
.block_hash
696-
.map(|block_hash| asc_new(heap, &block_hash, gas))
697-
.unwrap_or(Ok(AscPtr::null()))?,
698-
block_number: self
699-
.block_number
700-
.map(|block_number| asc_new(heap, &BigInt::from(block_number), gas))
701-
.unwrap_or(Ok(AscPtr::null()))?,
702-
cumulative_gas_used: asc_new(heap, &BigInt::from(self.gas_used), gas)?,
703-
gas_used: asc_new(heap, &BigInt::from(self.gas_used), gas)?,
704-
contract_address: self
705-
.contract_address
706-
.map(|contract_address| asc_new(heap, &contract_address, gas))
707-
.unwrap_or(Ok(AscPtr::null()))?,
708-
logs: asc_new(heap, &self.logs(), gas)?,
709-
status: asc_new(heap, &BigInt::from(self.status() as u64), gas)?,
710-
root: self
711-
.state_root()
712-
.map(|root| asc_new(heap, &root, gas))
713-
.unwrap_or(Ok(AscPtr::null()))?,
714-
logs_bloom: asc_new(heap, self.inner.logs_bloom().as_slice(), gas)?,
715-
})
716-
}
717-
}
718-
719676
impl ToAscObj<AscEthereumTransactionReceipt>
720-
for &TransactionReceipt<alloy::network::AnyReceiptEnvelope<Log>>
677+
for TransactionReceipt<alloy::network::AnyReceiptEnvelope<Log>>
721678
{
722679
fn to_asc_obj<H: AscHeap + ?Sized>(
723680
&self,

chain/ethereum/src/runtime/runtime_adapter.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use graph::slog::debug;
2222
use graph::{
2323
blockchain::{self, BlockPtr, HostFnCtx},
2424
cheap_clone::CheapClone,
25-
prelude::{alloy, EthereumCallCache},
25+
prelude::{alloy::primitives::Address, EthereumCallCache},
2626
runtime::{asc_get, asc_new, AscPtr, HostExportError},
2727
slog::Logger,
2828
};
@@ -221,7 +221,7 @@ fn eth_get_balance(
221221
let logger = &ctx.logger;
222222
let block_ptr = &ctx.block_ptr;
223223

224-
let address: alloy::primitives::Address = asc_get(ctx.heap, wasm_ptr.into(), &ctx.gas, 0)?;
224+
let address: Address = asc_get(ctx.heap, wasm_ptr.into(), &ctx.gas, 0)?;
225225

226226
let result = graph::block_on(eth_adapter.get_balance(logger, address, block_ptr.clone()));
227227

@@ -255,7 +255,7 @@ fn eth_has_code(
255255
let logger = &ctx.logger;
256256
let block_ptr = &ctx.block_ptr;
257257

258-
let address: alloy::primitives::Address = asc_get(ctx.heap, wasm_ptr.into(), &ctx.gas, 0)?;
258+
let address: Address = asc_get(ctx.heap, wasm_ptr.into(), &ctx.gas, 0)?;
259259

260260
let result = graph::block_on(eth_adapter.get_code(logger, address, block_ptr.clone()))
261261
.map(|v| !v.is_empty());
@@ -386,7 +386,7 @@ fn eth_call(
386386
#[derive(Clone, Debug)]
387387
pub struct UnresolvedContractCall {
388388
pub contract_name: String,
389-
pub contract_address: alloy::primitives::Address,
389+
pub contract_address: Address,
390390
pub function_name: String,
391391
pub function_signature: Option<String>,
392392
pub function_args: Vec<abi::DynSolValue>,

graph/src/blockchain/types.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,15 @@ impl From<(Vec<u8>, i32)> for BlockPtr {
222222
}
223223

224224
impl From<(B256, i32)> for BlockPtr {
225-
fn from((hash, number): (alloy::primitives::B256, i32)) -> BlockPtr {
225+
fn from((hash, number): (B256, i32)) -> BlockPtr {
226226
BlockPtr {
227227
hash: hash.into(),
228228
number,
229229
}
230230
}
231231
}
232232
impl From<(B256, u64)> for BlockPtr {
233-
fn from((hash, number): (alloy::primitives::B256, u64)) -> BlockPtr {
233+
fn from((hash, number): (B256, u64)) -> BlockPtr {
234234
let number = i32::try_from(number).unwrap();
235235
BlockPtr {
236236
hash: hash.into(),
@@ -239,8 +239,8 @@ impl From<(B256, u64)> for BlockPtr {
239239
}
240240
}
241241

242-
impl From<(alloy::primitives::B256, i64)> for BlockPtr {
243-
fn from((hash, number): (alloy::primitives::B256, i64)) -> BlockPtr {
242+
impl From<(B256, i64)> for BlockPtr {
243+
fn from((hash, number): (B256, i64)) -> BlockPtr {
244244
let number = i32::try_from(number).unwrap();
245245
BlockPtr {
246246
hash: hash.into(),
@@ -446,9 +446,7 @@ impl IntoValue for ExtendedBlockPtr {
446446
impl TryFrom<(B256, i32, B256, u64)> for ExtendedBlockPtr {
447447
type Error = anyhow::Error;
448448

449-
fn try_from(
450-
tuple: (alloy::primitives::B256, i32, alloy::primitives::B256, u64),
451-
) -> Result<Self, Self::Error> {
449+
fn try_from(tuple: (B256, i32, B256, u64)) -> Result<Self, Self::Error> {
452450
let (hash, block_number, parent_hash, timestamp) = tuple;
453451

454452
// Convert timestamp to `BlockTime`

graph/src/components/transaction_receipt.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
66
use alloy::network::ReceiptResponse;
77
use alloy::primitives::B256;
8-
use alloy::rpc::types::TransactionReceipt;
98

109
#[derive(Debug, PartialEq, Eq)]
1110
pub struct LightTransactionReceipt {
@@ -17,24 +16,11 @@ pub struct LightTransactionReceipt {
1716
pub status: bool,
1817
}
1918

20-
impl From<TransactionReceipt> for LightTransactionReceipt {
21-
fn from(receipt: alloy::rpc::types::TransactionReceipt) -> Self {
22-
LightTransactionReceipt {
23-
transaction_hash: receipt.transaction_hash,
24-
transaction_index: receipt.transaction_index.unwrap(),
25-
block_hash: receipt.block_hash,
26-
block_number: receipt.block_number,
27-
gas_used: receipt.gas_used,
28-
status: receipt.status(),
29-
}
30-
}
31-
}
32-
3319
impl From<alloy::network::AnyTransactionReceipt> for LightTransactionReceipt {
3420
fn from(receipt: alloy::network::AnyTransactionReceipt) -> Self {
3521
LightTransactionReceipt {
3622
transaction_hash: receipt.transaction_hash,
37-
transaction_index: receipt.transaction_index.unwrap(),
23+
transaction_index: receipt.transaction_index.unwrap(), // unwrap is safe because its None only for pending transactions, graph-node does not ingest pending transactions
3824
block_hash: receipt.block_hash,
3925
block_number: receipt.block_number,
4026
gas_used: receipt.gas_used,

graph/src/data/store/ethereum.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ impl From<U64> for Value {
4343
pub mod call {
4444
use std::sync::Arc;
4545

46+
use alloy::primitives::Address;
47+
4648
use crate::data::store::scalar::Bytes;
4749

4850
use super::CheapClone;
@@ -104,15 +106,15 @@ pub mod call {
104106
/// on the call's return value
105107
#[derive(Debug, Clone, CheapClone)]
106108
pub struct Request {
107-
pub address: alloy::primitives::Address,
109+
pub address: Address,
108110
pub encoded_call: Arc<Bytes>,
109111
/// The index is set by the caller and is used to identify the
110112
/// request in related data structures that the caller might have
111113
pub index: u32,
112114
}
113115

114116
impl Request {
115-
pub fn new(address: alloy::primitives::Address, encoded_call: Vec<u8>, index: u32) -> Self {
117+
pub fn new(address: Address, encoded_call: Vec<u8>, index: u32) -> Self {
116118
Request {
117119
address,
118120
encoded_call: Arc::new(Bytes::from(encoded_call)),

graph/src/data/store/scalar/bytes.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use alloy::primitives::Address;
12
use diesel::deserialize::FromSql;
23
use diesel::pg::PgValue;
34
use diesel::serialize::ToSql;
@@ -57,8 +58,8 @@ impl<'a> From<&'a [u8]> for Bytes {
5758
}
5859
}
5960

60-
impl From<alloy::primitives::Address> for Bytes {
61-
fn from(address: alloy::primitives::Address) -> Bytes {
61+
impl From<Address> for Bytes {
62+
fn from(address: Address) -> Bytes {
6263
Bytes::from(address.as_ref())
6364
}
6465
}

graph/src/data_source/common.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use crate::{
1010
data::value::Word,
1111
prelude::Link,
1212
};
13-
use alloy::primitives::Address;
14-
use alloy::primitives::U256;
13+
use alloy::primitives::{Address, U256};
1514
use alloy::rpc::types::Log;
1615
use anyhow::{anyhow, Context, Error};
1716
use graph_derive::CheapClone;
@@ -1327,7 +1326,7 @@ impl DeclaredCall {
13271326
#[derive(Clone, Debug)]
13281327
pub struct ContractCall {
13291328
pub contract_name: String,
1330-
pub address: alloy::primitives::Address,
1329+
pub address: Address,
13311330
pub block_ptr: BlockPtr,
13321331
pub function: abi::Function,
13331332
pub args: Vec<abi::DynSolValue>,
@@ -1336,6 +1335,8 @@ pub struct ContractCall {
13361335

13371336
#[cfg(test)]
13381337
mod tests {
1338+
use alloy::primitives::B256;
1339+
13391340
use crate::data::subgraph::SPEC_VERSION_1_3_0;
13401341

13411342
use super::*;
@@ -1706,15 +1707,15 @@ mod tests {
17061707

17071708
// Test scenario 1: Unknown parameter
17081709
let inner_log = alloy::primitives::Log {
1709-
address: alloy::primitives::Address::ZERO,
1710+
address: Address::ZERO,
17101711
data: alloy::primitives::LogData::new_unchecked(vec![].into(), vec![].into()),
17111712
};
17121713
let log = Log {
17131714
inner: inner_log,
1714-
block_hash: Some(alloy::primitives::B256::ZERO),
1715+
block_hash: Some(B256::ZERO),
17151716
block_number: Some(1),
17161717
block_timestamp: None,
1717-
transaction_hash: Some(alloy::primitives::B256::ZERO),
1718+
transaction_hash: Some(B256::ZERO),
17181719
transaction_index: Some(0),
17191720
log_index: Some(0),
17201721
removed: false,
@@ -1772,9 +1773,9 @@ mod tests {
17721773
// Create a structure where base has only 2 fields instead of 3
17731774
// The parser thinks there should be 3 fields based on ABI, but at runtime we provide only 2
17741775
let base_struct = DynSolValue::Tuple(vec![
1775-
DynSolValue::Address(alloy::primitives::Address::from([1u8; 20])), // addr at index 0
1776-
DynSolValue::Uint(U256::from(100u64), 256), // amount at index 1
1777-
// Missing the active field at index 2!
1776+
DynSolValue::Address(Address::from([1u8; 20])), // addr at index 0
1777+
DynSolValue::Uint(U256::from(100u64), 256), // amount at index 1
1778+
// Missing the active field at index 2!
17781779
]);
17791780

17801781
let params = vec![DynSolParam {

graph/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ pub mod abi;
4141

4242
/// Wrapper for spawning tasks that abort on panic, which is our default.
4343
mod task_spawn;
44-
4544
pub use task_spawn::{
4645
block_on, spawn, spawn_allow_panic, spawn_blocking, spawn_blocking_allow_panic, spawn_thread,
4746
};

node/src/manager/commands/chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ pub async fn ingest(
280280
let number = block.header.number;
281281
// For inserting the block, it doesn't matter whether the block is final or not.
282282
let block = Arc::new(BlockFinality::Final(Arc::new(LightEthereumBlock::new(
283-
block.into(),
283+
block,
284284
))));
285285
chain_store.upsert_block(block).await?;
286286

0 commit comments

Comments
 (0)