Skip to content

Commit

Permalink
fix: clippy and doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodann committed Sep 17, 2024
1 parent 6f4f031 commit f233377
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 38 deletions.
15 changes: 8 additions & 7 deletions crates/edr_provider/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use edr_eth::{
calculate_next_base_fee_per_blob_gas, calculate_next_base_fee_per_gas, miner_reward,
BlockOptions,
},
chain_spec::HaltReasonTrait,
chain_spec::{ChainSpec, HaltReasonTrait},
db::StateRef,
env::CfgEnv,
fee_history::FeeHistoryResult,
Expand Down Expand Up @@ -112,14 +112,15 @@ pub struct SendTransactionResult<ChainSpecT: EvmSpec> {
pub mining_results: Vec<DebugMineBlockResult<ChainSpecT, BlockchainError<ChainSpecT>>>,
}

/// The result of executing a transaction.
pub type ExecutionResultAndTrace<'provider, ChainSpecT> = (
&'provider ExecutionResult<<ChainSpecT as ChainSpec>::HaltReason>,
&'provider Trace<<ChainSpecT as ChainSpec>::HaltReason>,
);

impl<ChainSpecT: EvmSpec> SendTransactionResult<ChainSpecT> {
/// Present if the transaction was auto-mined.
pub fn transaction_result_and_trace(
&self,
) -> Option<(
&ExecutionResult<ChainSpecT::HaltReason>,
&Trace<ChainSpecT::HaltReason>,
)> {
pub fn transaction_result_and_trace(&self) -> Option<ExecutionResultAndTrace<'_, ChainSpecT>> {
self.mining_results.iter().find_map(|result| {
izip!(
result.block.transactions().iter(),
Expand Down
8 changes: 7 additions & 1 deletion crates/edr_provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ pub mod time;

use core::fmt::Debug;

use edr_eth::{chain_spec::HaltReasonTrait, HashSet};
use edr_eth::{
chain_spec::{ChainSpec, HaltReasonTrait},
HashSet,
};
// Re-export parts of `edr_evm`
pub use edr_evm::hardfork;
use edr_evm::{chain_spec::EvmSpec, trace::Trace};
Expand Down Expand Up @@ -57,6 +60,9 @@ lazy_static! {
};
}

pub type ProviderResultWithTraces<T, ChainSpecT> =
Result<(T, Vec<Trace<<ChainSpecT as ChainSpec>::HaltReason>>), ProviderError<ChainSpecT>>;

#[derive(Clone, Debug)]
pub struct ResponseWithTraces<HaltReasonT: HaltReasonTrait> {
pub result: serde_json::Value,
Expand Down
8 changes: 4 additions & 4 deletions crates/edr_provider/src/requests/debug.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use edr_eth::{result::InvalidTransaction, transaction::TransactionValidation, BlockSpec, B256};
use edr_evm::{state::StateOverrides, trace::Trace, DebugTraceResult, DebugTraceResultWithTraces};
use edr_evm::{state::StateOverrides, DebugTraceResult, DebugTraceResultWithTraces};
use serde::{Deserialize, Deserializer};

use crate::{
data::ProviderData,
requests::eth::{resolve_block_spec_for_call_request, resolve_call_request},
spec::SyncProviderSpec,
time::TimeSinceEpoch,
ProviderError,
ProviderError, ProviderResultWithTraces,
};

pub fn handle_debug_trace_transaction<
Expand All @@ -24,7 +24,7 @@ pub fn handle_debug_trace_transaction<
data: &mut ProviderData<ChainSpecT, TimerT>,
transaction_hash: B256,
config: Option<DebugTraceConfig>,
) -> Result<(DebugTraceResult, Vec<Trace<ChainSpecT::HaltReason>>), ProviderError<ChainSpecT>> {
) -> ProviderResultWithTraces<DebugTraceResult, ChainSpecT> {
let DebugTraceResultWithTraces { result, traces } = data
.debug_trace_transaction(
&transaction_hash,
Expand All @@ -45,7 +45,7 @@ pub fn handle_debug_trace_call<ChainSpecT, TimerT>(
call_request: ChainSpecT::RpcCallRequest,
block_spec: Option<BlockSpec>,
config: Option<DebugTraceConfig>,
) -> Result<(DebugTraceResult, Vec<Trace<ChainSpecT::HaltReason>>), ProviderError<ChainSpecT>>
) -> ProviderResultWithTraces<DebugTraceResult, ChainSpecT>
where
ChainSpecT: SyncProviderSpec<
TimerT,
Expand Down
5 changes: 2 additions & 3 deletions crates/edr_provider/src/requests/eth/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ use std::num::NonZeroU64;
use edr_eth::{
block::BlockOptions, result::InvalidTransaction, transaction::TransactionValidation, U64,
};
use edr_evm::trace::Trace;

use crate::{
data::ProviderData,
spec::{ProviderSpec, SyncProviderSpec},
time::TimeSinceEpoch,
ProviderError, Timestamp,
ProviderError, ProviderResultWithTraces, Timestamp,
};

pub fn handle_increase_time_request<
Expand Down Expand Up @@ -38,7 +37,7 @@ pub fn handle_mine_request<
>(
data: &mut ProviderData<ChainSpecT, TimerT>,
timestamp: Option<Timestamp>,
) -> Result<(String, Vec<Trace<ChainSpecT::HaltReason>>), ProviderError<ChainSpecT>> {
) -> ProviderResultWithTraces<String, ChainSpecT> {
let mine_block_result = data.mine_and_commit_block(BlockOptions {
timestamp: timestamp.map(Into::into),
..BlockOptions::default()
Expand Down
6 changes: 3 additions & 3 deletions crates/edr_provider/src/requests/eth/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use edr_eth::{
transaction::{signed::FakeSign as _, TransactionMut, TransactionValidation},
BlockSpec, SpecId, U256, U64,
};
use edr_evm::{state::StateOverrides, trace::Trace, transaction};
use edr_evm::{state::StateOverrides, transaction};

use crate::{
data::ProviderData,
requests::validation::validate_post_merge_block_tags,
spec::{CallContext, FromRpcType as _, MaybeSender as _, SyncProviderSpec},
time::TimeSinceEpoch,
ProviderError,
ProviderError, ProviderResultWithTraces,
};

pub fn handle_estimate_gas<
Expand All @@ -30,7 +30,7 @@ pub fn handle_estimate_gas<
data: &mut ProviderData<ChainSpecT, TimerT>,
request: ChainSpecT::RpcCallRequest,
block_spec: Option<BlockSpec>,
) -> Result<(U64, Vec<Trace<ChainSpecT::HaltReason>>), ProviderError<ChainSpecT>> {
) -> ProviderResultWithTraces<U64, ChainSpecT> {
// Matching Hardhat behavior in defaulting to "pending" instead of "latest" for
// estimate gas.
let block_spec = block_spec.unwrap_or_else(BlockSpec::pending);
Expand Down
9 changes: 4 additions & 5 deletions crates/edr_provider/src/requests/eth/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use edr_evm::{
block::transaction::{BlockDataForTransaction, TransactionAndBlock},
blockchain::BlockchainError,
chain_spec::EvmSpec,
trace::Trace,
transaction, SyncBlock,
};
use edr_rpc_eth::RpcTypeFrom as _;
Expand All @@ -28,7 +27,7 @@ use crate::{
},
spec::{FromRpcType, Sender as _, SyncProviderSpec, TransactionContext},
time::TimeSinceEpoch,
ProviderError, TransactionFailure,
ProviderError, ProviderResultWithTraces, TransactionFailure,
};

pub fn handle_get_transaction_by_block_hash_and_index<
Expand Down Expand Up @@ -180,7 +179,7 @@ pub fn handle_send_transaction_request<
>(
data: &mut ProviderData<ChainSpecT, TimerT>,
request: ChainSpecT::RpcTransactionRequest,
) -> Result<(B256, Vec<Trace<ChainSpecT::HaltReason>>), ProviderError<ChainSpecT>> {
) -> ProviderResultWithTraces<B256, ChainSpecT> {
let sender = *request.sender();

let context = TransactionContext { data };
Expand All @@ -207,7 +206,7 @@ pub fn handle_send_raw_transaction_request<
>(
data: &mut ProviderData<ChainSpecT, TimerT>,
raw_transaction: Bytes,
) -> Result<(B256, Vec<Trace<ChainSpecT::HaltReason>>), ProviderError<ChainSpecT>> {
) -> ProviderResultWithTraces<B256, ChainSpecT> {
let mut raw_transaction: &[u8] = raw_transaction.as_ref();
let pooled_transaction =
ChainSpecT::PooledTransaction::decode(&mut raw_transaction).map_err(|err| match err {
Expand Down Expand Up @@ -241,7 +240,7 @@ fn send_raw_transaction_and_log<
>(
data: &mut ProviderData<ChainSpecT, TimerT>,
signed_transaction: ChainSpecT::Transaction,
) -> Result<(B256, Vec<Trace<ChainSpecT::HaltReason>>), ProviderError<ChainSpecT>> {
) -> ProviderResultWithTraces<B256, ChainSpecT> {
let result = data.send_transaction(signed_transaction.clone())?;

let hardfork = data.hardfork();
Expand Down
8 changes: 5 additions & 3 deletions crates/edr_provider/src/requests/hardhat/miner.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use edr_eth::{result::InvalidTransaction, transaction::TransactionValidation};
use edr_evm::trace::Trace;

use crate::{data::ProviderData, spec::SyncProviderSpec, time::TimeSinceEpoch, ProviderError};
use crate::{
data::ProviderData, spec::SyncProviderSpec, time::TimeSinceEpoch, ProviderError,
ProviderResultWithTraces,
};

pub fn handle_interval_mine_request<
ChainSpecT: SyncProviderSpec<
Expand Down Expand Up @@ -33,7 +35,7 @@ pub fn handle_mine<
data: &mut ProviderData<ChainSpecT, TimerT>,
number_of_blocks: Option<u64>,
interval: Option<u64>,
) -> Result<(bool, Vec<Trace<ChainSpecT::HaltReason>>), ProviderError<ChainSpecT>> {
) -> ProviderResultWithTraces<bool, ChainSpecT> {
let number_of_blocks = number_of_blocks.unwrap_or(1);
let interval = interval.unwrap_or(1);

Expand Down
10 changes: 6 additions & 4 deletions crates/edr_provider/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ use edr_eth::{
signature::secret_key_from_str, transaction::TransactionValidation, trie::KECCAK_NULL_RLP,
Address, Bytes, HashMap, B256, U160, U256,
};
use edr_evm::Block;
use edr_evm::{chain_spec::EvmSpec, Block};
use edr_rpc_eth::TransactionRequest;
use time::TimeSinceEpoch;

use super::*;
use crate::{config::MiningConfig, requests::hardhat::rpc_types::ForkConfig};
use crate::{
config::MiningConfig, requests::hardhat::rpc_types::ForkConfig, time::TimeSinceEpoch,
AccountConfig, MethodInvocation, Provider, ProviderConfig, ProviderData, ProviderError,
ProviderRequest, SyncProviderSpec,
};

pub const TEST_SECRET_KEY: &str =
"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
Expand Down
16 changes: 8 additions & 8 deletions crates/edr_solidity/src/contracts_identifier/radix_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ impl RadixNode {
}
}

/**
* Returns a tuple containing:
* - a boolean indicating if the word was matched exactly
* - the number of bytes matched
* - the node that matched the word
* If the word is not matched exactly, the node will be the one that
* matched the longest prefix.
*/
/// Returns a tuple containing:
///
/// - a boolean indicating if the word was matched exactly
/// - the number of bytes matched
/// - the node that matched the word
///
/// If the word is not matched exactly, the node will be the one that
/// matched the longest prefix.
pub fn longest_match(&self, word: &[u8]) -> (bool, usize, &RadixNode) {
let prefix_length = longest_prefix_length(word, &self.content);

Expand Down

0 comments on commit f233377

Please sign in to comment.