Skip to content

Commit

Permalink
use stable fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
1xstj committed Dec 16, 2024
1 parent 8c58a05 commit 130955c
Show file tree
Hide file tree
Showing 71 changed files with 516 additions and 408 deletions.
2 changes: 1 addition & 1 deletion client/evm-tracing/src/formatters/blockscout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl super::ResponseFormatter for Formatter {
if let Some(entry) = listener.entries.last() {
return Some(TransactionTrace::CallList(
entry.iter().map(|(_, value)| Call::Blockscout(value.clone())).collect(),
))
));
}
None
}
Expand Down
37 changes: 21 additions & 16 deletions client/evm-tracing/src/formatters/call_tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ impl super::ResponseFormatter for Formatter {
gas_used,
trace_address: Some(trace_address.clone()),
inner: match inner.clone() {
BlockscoutCallInner::Call { input, to, res, call_type } =>
BlockscoutCallInner::Call { input, to, res, call_type } => {
CallTracerInner::Call {
call_type: match call_type {
CallType::Call => "CALL".as_bytes().to_vec(),
CallType::CallCode => "CALLCODE".as_bytes().to_vec(),
CallType::DelegateCall =>
"DELEGATECALL".as_bytes().to_vec(),
CallType::DelegateCall => {
"DELEGATECALL".as_bytes().to_vec()
},
CallType::StaticCall => "STATICCALL".as_bytes().to_vec(),
},
to,
Expand All @@ -73,7 +74,8 @@ impl super::ResponseFormatter for Formatter {
CallResult::Output { .. } => it.logs.clone(),
CallResult::Error { .. } => Vec::new(),
},
},
}
},
BlockscoutCallInner::Create { init, res } => CallTracerInner::Create {
input: init,
error: match res {
Expand All @@ -87,19 +89,21 @@ impl super::ResponseFormatter for Formatter {
CreateResult::Error { .. } => None,
},
output: match res {
CreateResult::Success { created_contract_code, .. } =>
Some(created_contract_code),
CreateResult::Success { created_contract_code, .. } => {
Some(created_contract_code)
},
CreateResult::Error { .. } => None,
},
value,
call_type: "CREATE".as_bytes().to_vec(),
},
BlockscoutCallInner::SelfDestruct { balance, to } =>
BlockscoutCallInner::SelfDestruct { balance, to } => {
CallTracerInner::SelfDestruct {
value: balance,
to,
call_type: "SELFDESTRUCT".as_bytes().to_vec(),
},
}
},
},
calls: Vec::new(),
})
Expand Down Expand Up @@ -161,11 +165,11 @@ impl super::ResponseFormatter for Formatter {
let sibling_greater_than = |a: &Vec<u32>, b: &Vec<u32>| -> bool {
for (i, a_value) in a.iter().enumerate() {
if a_value > &b[i] {
return true
return true;
} else if a_value < &b[i] {
return false
return false;
} else {
continue
continue;
}
}
false
Expand All @@ -189,10 +193,11 @@ impl super::ResponseFormatter for Formatter {
(
Call::CallTracer(CallTracerCall { trace_address: Some(a), .. }),
Call::CallTracer(CallTracerCall { trace_address: Some(b), .. }),
) =>
&b[..] ==
a.get(0..a.len() - 1)
.expect("non-root element while traversing trace result"),
) => {
&b[..]
== a.get(0..a.len() - 1)
.expect("non-root element while traversing trace result")
},
_ => unreachable!(),
}) {
// Remove `trace_address` from result.
Expand Down Expand Up @@ -223,7 +228,7 @@ impl super::ResponseFormatter for Formatter {
}
}
if traces.is_empty() {
return None
return None;
}
Some(traces)
}
Expand Down
15 changes: 9 additions & 6 deletions client/evm-tracing/src/formatters/trace_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ impl super::ResponseFormatter for Formatter {
// Can't be known here, must be inserted upstream.
block_number: 0,
output: match res {
CallResult::Output(output) =>
CallResult::Output(output) => {
TransactionTraceOutput::Result(TransactionTraceResult::Call {
gas_used: trace.gas_used,
output,
}),
})
},
CallResult::Error(error) => TransactionTraceOutput::Error(error),
},
subtraces: trace.subtraces,
Expand All @@ -86,14 +87,16 @@ impl super::ResponseFormatter for Formatter {
CreateResult::Success {
created_contract_address_hash,
created_contract_code,
} =>
} => {
TransactionTraceOutput::Result(TransactionTraceResult::Create {
gas_used: trace.gas_used,
code: created_contract_code,
address: created_contract_address_hash,
}),
CreateResult::Error { error } =>
TransactionTraceOutput::Error(error),
})
},
CreateResult::Error { error } => {
TransactionTraceOutput::Error(error)
},
},
subtraces: trace.subtraces,
trace_address: trace.trace_address.clone(),
Expand Down
71 changes: 42 additions & 29 deletions client/evm-tracing/src/listeners/call_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ impl Listener {

pub fn gasometer_event(&mut self, event: GasometerEvent) {
match event {
GasometerEvent::RecordCost { snapshot, .. } |
GasometerEvent::RecordDynamicCost { snapshot, .. } |
GasometerEvent::RecordStipend { snapshot, .. } => {
GasometerEvent::RecordCost { snapshot, .. }
| GasometerEvent::RecordDynamicCost { snapshot, .. }
| GasometerEvent::RecordStipend { snapshot, .. } => {
if let Some(context) = self.context_stack.last_mut() {
if context.start_gas.is_none() {
context.start_gas = Some(snapshot.gas());
Expand Down Expand Up @@ -497,12 +497,13 @@ impl Listener {
// behavior (like batch precompile does) thus we simply consider this a call.
self.call_type = Some(CallType::Call);
},
EvmEvent::Log { address, topics, data } =>
EvmEvent::Log { address, topics, data } => {
if self.with_log {
if let Some(stack) = self.context_stack.last_mut() {
stack.logs.push(Log { address, topics, data });
}
},
}
},

// We ignore other kinds of message if any (new ones may be added in the future).
#[allow(unreachable_patterns)]
Expand Down Expand Up @@ -536,13 +537,15 @@ impl Listener {
match context.context_type {
ContextType::Call(call_type) => {
let res = match &reason {
ExitReason::Succeed(ExitSucceed::Returned) =>
CallResult::Output(return_value.to_vec()),
ExitReason::Succeed(ExitSucceed::Returned) => {
CallResult::Output(return_value.to_vec())
},
ExitReason::Succeed(_) => CallResult::Output(vec![]),
ExitReason::Error(error) => CallResult::Error(error_message(error)),

ExitReason::Revert(_) =>
CallResult::Error(b"execution reverted".to_vec()),
ExitReason::Revert(_) => {
CallResult::Error(b"execution reverted".to_vec())
},
ExitReason::Fatal(_) => CallResult::Error(vec![]),
};

Expand All @@ -568,10 +571,12 @@ impl Listener {
created_contract_address_hash: context.to,
created_contract_code: return_value.to_vec(),
},
ExitReason::Error(error) =>
CreateResult::Error { error: error_message(error) },
ExitReason::Revert(_) =>
CreateResult::Error { error: b"execution reverted".to_vec() },
ExitReason::Error(error) => {
CreateResult::Error { error: error_message(error) }
},
ExitReason::Revert(_) => {
CreateResult::Error { error: b"execution reverted".to_vec() }
},
ExitReason::Fatal(_) => CreateResult::Error { error: vec![] },
};

Expand Down Expand Up @@ -620,14 +625,15 @@ impl ListenerT for Listener {
Event::Gasometer(gasometer_event) => self.gasometer_event(gasometer_event),
Event::Runtime(runtime_event) => self.runtime_event(runtime_event),
Event::Evm(evm_event) => self.evm_event(evm_event),
Event::CallListNew() =>
Event::CallListNew() => {
if !self.call_list_first_transaction {
self.finish_transaction();
self.skip_next_context = false;
self.entries.push(BTreeMap::new());
} else {
self.call_list_first_transaction = false;
},
}
},
};
}

Expand Down Expand Up @@ -726,8 +732,9 @@ mod tests {
target: H160::default(),
balance: U256::zero(),
},
TestEvmEvent::Exit =>
EvmEvent::Exit { reason: exit_reason.unwrap(), return_value: Vec::new() },
TestEvmEvent::Exit => {
EvmEvent::Exit { reason: exit_reason.unwrap(), return_value: Vec::new() }
},
TestEvmEvent::TransactCall => EvmEvent::TransactCall {
caller: H160::default(),
address: H160::default(),
Expand All @@ -750,8 +757,9 @@ mod tests {
gas_limit: 0u64,
address: H160::default(),
},
TestEvmEvent::Log =>
EvmEvent::Log { address: H160::default(), topics: Vec::new(), data: Vec::new() },
TestEvmEvent::Log => {
EvmEvent::Log { address: H160::default(), topics: Vec::new(), data: Vec::new() }
},
}
}

Expand All @@ -764,8 +772,9 @@ mod tests {
stack: test_stack(),
memory: test_memory(),
},
TestRuntimeEvent::StepResult =>
RuntimeEvent::StepResult { result: Ok(()), return_value: Vec::new() },
TestRuntimeEvent::StepResult => {
RuntimeEvent::StepResult { result: Ok(()), return_value: Vec::new() }
},
TestRuntimeEvent::SLoad => RuntimeEvent::SLoad {
address: H160::default(),
index: H256::default(),
Expand All @@ -781,20 +790,24 @@ mod tests {

fn test_emit_gasometer_event(event_type: TestGasometerEvent) -> GasometerEvent {
match event_type {
TestGasometerEvent::RecordCost =>
GasometerEvent::RecordCost { cost: 0u64, snapshot: test_snapshot() },
TestGasometerEvent::RecordRefund =>
GasometerEvent::RecordRefund { refund: 0i64, snapshot: test_snapshot() },
TestGasometerEvent::RecordStipend =>
GasometerEvent::RecordStipend { stipend: 0u64, snapshot: test_snapshot() },
TestGasometerEvent::RecordCost => {
GasometerEvent::RecordCost { cost: 0u64, snapshot: test_snapshot() }
},
TestGasometerEvent::RecordRefund => {
GasometerEvent::RecordRefund { refund: 0i64, snapshot: test_snapshot() }
},
TestGasometerEvent::RecordStipend => {
GasometerEvent::RecordStipend { stipend: 0u64, snapshot: test_snapshot() }
},
TestGasometerEvent::RecordDynamicCost => GasometerEvent::RecordDynamicCost {
gas_cost: 0u64,
memory_gas: 0u64,
gas_refund: 0i64,
snapshot: test_snapshot(),
},
TestGasometerEvent::RecordTransaction =>
GasometerEvent::RecordTransaction { cost: 0u64, snapshot: test_snapshot() },
TestGasometerEvent::RecordTransaction => {
GasometerEvent::RecordTransaction { cost: 0u64, snapshot: test_snapshot() }
},
}
}

Expand Down
12 changes: 6 additions & 6 deletions client/evm-tracing/src/listeners/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl Listener {
.and_then(|inner| inner.checked_sub(memory.data.len()));

if self.remaining_memory_usage.is_none() {
return
return;
}

Some(memory.data.clone())
Expand All @@ -176,7 +176,7 @@ impl Listener {
.and_then(|inner| inner.checked_sub(stack.data.len()));

if self.remaining_memory_usage.is_none() {
return
return;
}

Some(stack.data.clone())
Expand Down Expand Up @@ -205,7 +205,7 @@ impl Listener {
});

if self.remaining_memory_usage.is_none() {
return
return;
}

Some(context.storage_cache.clone())
Expand Down Expand Up @@ -277,8 +277,8 @@ impl Listener {
_ => (),
}
},
RuntimeEvent::SLoad { address: _, index, value } |
RuntimeEvent::SStore { address: _, index, value } => {
RuntimeEvent::SLoad { address: _, index, value }
| RuntimeEvent::SStore { address: _, index, value } => {
if let Some(context) = self.context_stack.last_mut() {
if !self.disable_storage {
context.storage_cache.insert(index, value);
Expand All @@ -295,7 +295,7 @@ impl Listener {
impl ListenerT for Listener {
fn event(&mut self, event: Event) {
if self.remaining_memory_usage.is_none() {
return
return;
}

match event {
Expand Down
4 changes: 2 additions & 2 deletions client/evm-tracing/src/types/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ where
S: Serializer,
{
if let Some(bytes) = bytes.as_ref() {
return serializer.serialize_str(&format!("0x{}", hex::encode(&bytes[..])))
return serializer.serialize_str(&format!("0x{}", hex::encode(&bytes[..])));
}
Err(S::Error::custom("String serialize error."))
}
Expand Down Expand Up @@ -87,7 +87,7 @@ where
let d = std::str::from_utf8(&value[..])
.map_err(|_| S::Error::custom("String serialize error."))?
.to_string();
return serializer.serialize_str(&d)
return serializer.serialize_str(&d);
}
Err(S::Error::custom("String serialize error."))
}
Expand Down
15 changes: 9 additions & 6 deletions client/rpc-core/txpool/src/types/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ where
impl GetT for Transaction {
fn get(hash: H256, from_address: H160, txn: &EthereumTransaction) -> Self {
let (nonce, action, value, gas_price, gas_limit, input) = match txn {
EthereumTransaction::Legacy(t) =>
(t.nonce, t.action, t.value, t.gas_price, t.gas_limit, t.input.clone()),
EthereumTransaction::EIP2930(t) =>
(t.nonce, t.action, t.value, t.gas_price, t.gas_limit, t.input.clone()),
EthereumTransaction::EIP1559(t) =>
(t.nonce, t.action, t.value, t.max_fee_per_gas, t.gas_limit, t.input.clone()),
EthereumTransaction::Legacy(t) => {
(t.nonce, t.action, t.value, t.gas_price, t.gas_limit, t.input.clone())
},
EthereumTransaction::EIP2930(t) => {
(t.nonce, t.action, t.value, t.gas_price, t.gas_limit, t.input.clone())
},
EthereumTransaction::EIP1559(t) => {
(t.nonce, t.action, t.value, t.max_fee_per_gas, t.gas_limit, t.input.clone())
},
};
Self {
hash,
Expand Down
Loading

0 comments on commit 130955c

Please sign in to comment.