Skip to content

Commit f7242f9

Browse files
committed
fix clippy warnings
1 parent eea49aa commit f7242f9

File tree

11 files changed

+130
-107
lines changed

11 files changed

+130
-107
lines changed

chain/ethereum/src/codec.rs

Lines changed: 79 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#[rustfmt::skip]
2+
#[allow(clippy::doc_lazy_continuation, clippy::doc_overindented_list_items)]
23
#[path = "protobuf/sf.ethereum.r#type.v2.rs"]
34
mod pbcodec;
45

@@ -844,6 +845,33 @@ impl BlockchainBlock for HeaderOnlyBlock {
844845
}
845846
}
846847

848+
fn extract_signature_from_trace(
849+
_trace: &TransactionTrace,
850+
_tx_type: TxType,
851+
) -> Result<alloy::signers::Signature, Error> {
852+
use alloy::primitives::{Signature as PrimitiveSignature, U256};
853+
854+
// Create a dummy signature with r = 0, s = 0 and even y-parity (false)
855+
let dummy = PrimitiveSignature::new(U256::ZERO, U256::ZERO, false);
856+
857+
Ok(dummy)
858+
}
859+
860+
fn get_to_address(trace: &TransactionTrace) -> Result<Option<Address>, Error> {
861+
// Try to detect contract creation transactions, which have no 'to' address
862+
let is_contract_creation = trace.to.is_empty()
863+
|| trace
864+
.calls
865+
.first()
866+
.is_some_and(|call| CallType::try_from(call.call_type) == Ok(CallType::Create));
867+
868+
if is_contract_creation {
869+
Ok(None)
870+
} else {
871+
Ok(Some(trace.to.try_decode_proto("transaction to address")?))
872+
}
873+
}
874+
847875
#[cfg(test)]
848876
mod test {
849877
use graph::{blockchain::Block as _, prelude::chrono::Utc};
@@ -886,25 +914,31 @@ mod test {
886914
use graph::prelude::alloy::network::AnyTxEnvelope;
887915
use graph::prelude::alloy::primitives::B256;
888916

889-
let mut block = Block::default();
890-
let mut header = BlockHeader::default();
891-
header.number = 123456;
892-
header.timestamp = Some(Timestamp {
893-
seconds: 1234567890,
894-
nanos: 0,
895-
});
896-
block.header = Some(header);
897-
block.number = 123456;
898-
block.hash = vec![0u8; 32];
899-
900-
let mut trace = TransactionTrace::default();
901-
trace.r#type = 126; // 0x7e Optimism deposit transaction
902-
trace.hash = vec![1u8; 32];
903-
trace.from = vec![2u8; 20];
904-
trace.to = vec![3u8; 20];
905-
trace.nonce = 42;
906-
trace.gas_limit = 21000;
907-
trace.index = 0;
917+
let header = BlockHeader {
918+
number: 123456,
919+
timestamp: Some(Timestamp {
920+
seconds: 1234567890,
921+
nanos: 0,
922+
}),
923+
..Default::default()
924+
};
925+
let block = Block {
926+
header: Some(header),
927+
number: 123456,
928+
hash: vec![0u8; 32],
929+
..Default::default()
930+
};
931+
932+
let trace = TransactionTrace {
933+
r#type: 126, // 0x7e Optimism deposit transaction
934+
hash: vec![1u8; 32],
935+
from: vec![2u8; 20],
936+
to: vec![3u8; 20],
937+
nonce: 42,
938+
gas_limit: 21000,
939+
index: 0,
940+
..Default::default()
941+
};
908942

909943
let trace_at = TransactionTraceAt::new(&trace, &block);
910944
let result: Result<
@@ -941,25 +975,32 @@ mod test {
941975
use super::transaction_trace_to_alloy_txn_reciept;
942976
use crate::codec::TransactionTrace;
943977

944-
let mut block = Block::default();
945-
let mut header = BlockHeader::default();
946-
header.number = 123456;
947-
block.header = Some(header);
948-
block.hash = vec![0u8; 32];
949-
950-
let mut trace = TransactionTrace::default();
951-
trace.r#type = 126; // 0x7e Optimism deposit transaction
952-
trace.hash = vec![1u8; 32];
953-
trace.from = vec![2u8; 20];
954-
trace.to = vec![3u8; 20];
955-
trace.index = 0;
956-
trace.gas_used = 21000;
957-
trace.status = 1;
958-
959-
let mut receipt = super::TransactionReceipt::default();
960-
receipt.cumulative_gas_used = 21000;
961-
receipt.logs_bloom = vec![0u8; 256];
962-
trace.receipt = Some(receipt);
978+
let header = BlockHeader {
979+
number: 123456,
980+
..Default::default()
981+
};
982+
let block = Block {
983+
header: Some(header),
984+
hash: vec![0u8; 32],
985+
..Default::default()
986+
};
987+
988+
let receipt = super::TransactionReceipt {
989+
cumulative_gas_used: 21000,
990+
logs_bloom: vec![0u8; 256],
991+
..Default::default()
992+
};
993+
let trace = TransactionTrace {
994+
r#type: 126, // 0x7e Optimism deposit transaction
995+
hash: vec![1u8; 32],
996+
from: vec![2u8; 20],
997+
to: vec![3u8; 20],
998+
index: 0,
999+
gas_used: 21000,
1000+
status: 1,
1001+
receipt: Some(receipt),
1002+
..Default::default()
1003+
};
9631004

9641005
let result = transaction_trace_to_alloy_txn_reciept(&trace, &block);
9651006

@@ -978,30 +1019,3 @@ mod test {
9781019
assert_eq!(receipt.transaction_index, Some(0));
9791020
}
9801021
}
981-
982-
fn extract_signature_from_trace(
983-
_trace: &TransactionTrace,
984-
_tx_type: TxType,
985-
) -> Result<alloy::signers::Signature, Error> {
986-
use alloy::primitives::{Signature as PrimitiveSignature, U256};
987-
988-
// Create a dummy signature with r = 0, s = 0 and even y-parity (false)
989-
let dummy = PrimitiveSignature::new(U256::ZERO, U256::ZERO, false);
990-
991-
Ok(dummy)
992-
}
993-
994-
fn get_to_address(trace: &TransactionTrace) -> Result<Option<Address>, Error> {
995-
// Try to detect contract creation transactions, which have no 'to' address
996-
let is_contract_creation = trace.to.is_empty()
997-
|| trace
998-
.calls
999-
.first()
1000-
.is_some_and(|call| CallType::try_from(call.call_type) == Ok(CallType::Create));
1001-
1002-
if is_contract_creation {
1003-
Ok(None)
1004-
} else {
1005-
Ok(Some(trace.to.try_decode_proto("transaction to address")?))
1006-
}
1007-
}

chain/ethereum/src/ethereum_adapter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ impl EthereumAdapterTrait for EthereumAdapter {
14831483
let encoded_call = call
14841484
.function
14851485
.abi_encode_input(&call.args)
1486-
.map_err(|err| ContractCallError::EncodingError(err))?;
1486+
.map_err(ContractCallError::EncodingError)?;
14871487
call::Request::new(call.address, encoded_call, index)
14881488
};
14891489

chain/ethereum/src/tests.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ fn test_trigger_ordering() {
7777
};
7878
let call1 = EthereumTrigger::Call(Arc::new(call1));
7979

80-
let mut call2 = EthereumCall::default();
81-
call2.transaction_index = 2;
82-
call2.input = Bytes::from(vec![0]);
80+
let call2 = EthereumCall {
81+
transaction_index: 2,
82+
input: Bytes::from(vec![0]),
83+
..Default::default()
84+
};
8385
let call2 = EthereumTrigger::Call(Arc::new(call2));
8486

8587
let call3 = EthereumCall {
@@ -89,10 +91,12 @@ fn test_trigger_ordering() {
8991
let call3 = EthereumTrigger::Call(Arc::new(call3));
9092

9193
// Call with the same tx index as call2
92-
let mut call4 = EthereumCall::default();
93-
call4.transaction_index = 2;
9494
// different than call2 so they don't get mistaken as the same
95-
call4.input = Bytes::from(vec![1]);
95+
let call4 = EthereumCall {
96+
transaction_index: 2,
97+
input: Bytes::from(vec![1]),
98+
..Default::default()
99+
};
96100
let call4 = EthereumTrigger::Call(Arc::new(call4));
97101

98102
// Event with transaction_index 1 and log_index 0;

graph/src/abi/event_ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub trait EventExt {
1414
impl EventExt for Event {
1515
fn decode_log(&self, log: &Log) -> Result<Vec<DynSolParam>> {
1616
let log_data = log.data();
17-
let decoded_event = alloy::dyn_abi::EventExt::decode_log(self, &log_data)?;
17+
let decoded_event = alloy::dyn_abi::EventExt::decode_log(self, log_data)?;
1818
let mut indexed: VecDeque<DynSolValue> = decoded_event.indexed.into();
1919
let mut body: VecDeque<DynSolValue> = decoded_event.body.into();
2020

graph/src/abi/function_ext.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ impl FunctionExt for Function {
5252

5353
let mut sig = String::with_capacity(sig_cap);
5454

55-
sig.push_str(&name);
56-
signature_part(&inputs, &mut sig);
55+
sig.push_str(name);
56+
signature_part(inputs, &mut sig);
5757

5858
if !outputs.is_empty() {
5959
sig.push(':');
60-
signature_part(&outputs, &mut sig);
60+
signature_part(outputs, &mut sig);
6161
}
6262

6363
sig
@@ -122,12 +122,12 @@ fn signature_part(params: &[Param], out: &mut String) {
122122
1 => {
123123
params[0].selector_type_raw(out);
124124
}
125-
n => {
125+
_ => {
126126
params[0].selector_type_raw(out);
127127

128-
for i in 1..n {
128+
for param in params.iter().skip(1) {
129129
out.push(',');
130-
params[i].selector_type_raw(out);
130+
param.selector_type_raw(out);
131131
}
132132
}
133133
}

graph/src/amp/sql/query_builder/parser.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ struct AllowOnlySelectQueries;
4242

4343
impl AllowOnlySelectQueries {
4444
/// Returns an error if the `set_expr` is not a `SELECT` expression.
45-
fn visit_set_expr(&self, set_expr: &ast::SetExpr) -> Result<()> {
45+
fn visit_set_expr(set_expr: &ast::SetExpr) -> Result<()> {
4646
match set_expr {
4747
ast::SetExpr::Select(_)
4848
| ast::SetExpr::Query(_)
4949
| ast::SetExpr::Values(_)
5050
| ast::SetExpr::Table(_) => Ok(()),
5151
ast::SetExpr::SetOperation { left, right, .. } => {
52-
self.visit_set_expr(left)?;
53-
self.visit_set_expr(right)?;
52+
Self::visit_set_expr(left)?;
53+
Self::visit_set_expr(right)?;
5454
Ok(())
5555
}
5656
ast::SetExpr::Insert(_) | ast::SetExpr::Update(_) | ast::SetExpr::Delete(_) => {
@@ -64,7 +64,7 @@ impl Visitor for AllowOnlySelectQueries {
6464
type Break = anyhow::Error;
6565

6666
fn pre_visit_query(&mut self, query: &ast::Query) -> ControlFlow<Self::Break> {
67-
match self.visit_set_expr(&query.body) {
67+
match Self::visit_set_expr(&query.body) {
6868
Ok(()) => ControlFlow::Continue(()),
6969
Err(e) => ControlFlow::Break(e),
7070
}

graph/src/components/ethereum/types.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl LightEthereumBlockExt for AnyBlock {
9292
log.transaction_hash.and_then(|hash| {
9393
self.transactions
9494
.txns()
95-
.find(|tx| &tx.tx_hash() == &hash)
95+
.find(|tx| tx.tx_hash() == hash)
9696
.cloned()
9797
})
9898
}
@@ -101,7 +101,7 @@ impl LightEthereumBlockExt for AnyBlock {
101101
call.transaction_hash.and_then(|hash| {
102102
self.transactions
103103
.txns()
104-
.find(|tx| &tx.tx_hash() == &hash)
104+
.find(|tx| tx.tx_hash() == hash)
105105
.cloned()
106106
})
107107
}
@@ -227,15 +227,15 @@ impl EthereumCall {
227227

228228
// The only traces without transactions are those from Parity block reward contracts, we
229229
// don't support triggering on that.
230-
let transaction_index = trace.transaction_position? as u64;
230+
let transaction_index = trace.transaction_position?;
231231

232232
Some(EthereumCall {
233233
from: call.from,
234234
to: call.to,
235235
value: call.value,
236-
gas_used: gas_used,
236+
gas_used,
237237
input: call.input.clone(),
238-
output: output,
238+
output,
239239
block_number: BlockNumber::try_from(
240240
trace
241241
.block_number

graph/src/data_source/common.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,11 @@ impl AbiJson {
270270
return Ok(Some(vec![]));
271271
}
272272
// Recursively resolve the nested path
273-
return self
274-
.resolve_field_path(components, nested_path)
275-
.map(Some);
273+
return Self::resolve_field_path(
274+
components,
275+
nested_path,
276+
)
277+
.map(Some);
276278
}
277279
}
278280
}
@@ -297,7 +299,6 @@ impl AbiJson {
297299
/// Supports both numeric indices and field names
298300
/// Returns the index path to access the final field
299301
fn resolve_field_path(
300-
&self,
301302
components: &serde_json::Value,
302303
field_path: &[&str],
303304
) -> Result<Vec<usize>, Error> {
@@ -334,7 +335,7 @@ impl AbiJson {
334335
// Recursively resolve the remaining path
335336
let mut result = vec![index];
336337
let nested_result =
337-
self.resolve_field_path(nested_components, remaining_path)?;
338+
Self::resolve_field_path(nested_components, remaining_path)?;
338339
result.extend(nested_result);
339340
return Ok(result);
340341
} else {
@@ -374,8 +375,10 @@ impl AbiJson {
374375
if let Some(nested_components) = component.get("components") {
375376
// Recursively resolve the remaining path
376377
let mut result = vec![index];
377-
let nested_result =
378-
self.resolve_field_path(nested_components, remaining_path)?;
378+
let nested_result = Self::resolve_field_path(
379+
nested_components,
380+
remaining_path,
381+
)?;
379382
result.extend(nested_result);
380383
return Ok(result);
381384
} else {
@@ -1782,7 +1785,7 @@ mod tests {
17821785
// Test scenario 1: Unknown parameter
17831786
let inner_log = alloy::primitives::Log {
17841787
address: Address::ZERO,
1785-
data: alloy::primitives::LogData::new_unchecked(vec![].into(), vec![].into()),
1788+
data: alloy::primitives::LogData::new_unchecked(vec![], vec![].into()),
17861789
};
17871790
let log = Log {
17881791
inner: inner_log,

graph/src/util/test_utils.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ use crate::prelude::alloy::rpc::types::{Block, Header};
99
/// Creates a minimal Alloy Block for testing purposes.
1010
pub fn create_minimal_block_for_test(block_number: u64, block_hash: B256) -> Block {
1111
// Create consensus header with defaults, but set the specific number
12-
let mut consensus_header = ConsensusHeader::default();
13-
consensus_header.number = block_number;
12+
let consensus_header = ConsensusHeader {
13+
number: block_number,
14+
..Default::default()
15+
};
1416

1517
// Create RPC header with the specific hash
1618
let rpc_header = Header {
@@ -51,7 +53,7 @@ pub fn create_dummy_transaction(
5153
inner: recovered,
5254
block_hash: Some(block_hash),
5355
block_number: Some(block_number),
54-
transaction_index: transaction_index,
56+
transaction_index,
5557
effective_gas_price: None,
5658
}
5759
}

0 commit comments

Comments
 (0)