Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: decouple Logger and Provider generics #599

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions crates/edr_napi/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ impl Logger {
impl edr_provider::Logger<L1ChainSpec> for Logger {
type BlockchainError = BlockchainError<L1ChainSpec>;

type LoggerError = LoggerError;

fn is_enabled(&self) -> bool {
self.collector.is_enabled
}
Expand All @@ -143,7 +141,7 @@ impl edr_provider::Logger<L1ChainSpec> for Logger {
spec_id: edr_eth::SpecId,
transaction: &transaction::Signed,
result: &edr_provider::CallResult,
) -> Result<(), Self::LoggerError> {
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
self.collector.log_call(spec_id, transaction, result);

Ok(())
Expand All @@ -154,7 +152,7 @@ impl edr_provider::Logger<L1ChainSpec> for Logger {
spec_id: edr_eth::SpecId,
transaction: &transaction::Signed,
failure: &edr_provider::EstimateGasFailure,
) -> Result<(), Self::LoggerError> {
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
self.collector
.log_estimate_gas(spec_id, transaction, failure);

Expand All @@ -165,15 +163,19 @@ impl edr_provider::Logger<L1ChainSpec> for Logger {
&mut self,
spec_id: edr_eth::SpecId,
mining_result: &edr_provider::DebugMineBlockResult<L1ChainSpec, Self::BlockchainError>,
) -> Result<(), Self::LoggerError> {
self.collector.log_interval_mined(spec_id, mining_result)
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
self.collector
.log_interval_mined(spec_id, mining_result)
.map_err(Box::new)?;

Ok(())
}

fn log_mined_block(
&mut self,
spec_id: edr_eth::SpecId,
mining_results: &[edr_provider::DebugMineBlockResult<L1ChainSpec, Self::BlockchainError>],
) -> Result<(), Self::LoggerError> {
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
self.collector.log_mined_blocks(spec_id, mining_results);

Ok(())
Expand All @@ -184,7 +186,7 @@ impl edr_provider::Logger<L1ChainSpec> for Logger {
spec_id: edr_eth::SpecId,
transaction: &edr_evm::transaction::Signed,
mining_results: &[edr_provider::DebugMineBlockResult<L1ChainSpec, Self::BlockchainError>],
) -> Result<(), Self::LoggerError> {
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
self.collector
.log_send_transaction(spec_id, transaction, mining_results);

Expand All @@ -194,8 +196,8 @@ impl edr_provider::Logger<L1ChainSpec> for Logger {
fn print_method_logs(
&mut self,
method: &str,
error: Option<&ProviderError<LoggerError>>,
) -> Result<(), Self::LoggerError> {
error: Option<&ProviderError>,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
if let Some(error) = error {
self.collector.state = LoggingState::Empty;

Expand Down
4 changes: 2 additions & 2 deletions crates/edr_napi/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ use self::config::ProviderConfig;
use crate::{
call_override::CallOverrideCallback,
context::EdrContext,
logger::{Logger, LoggerConfig, LoggerError},
logger::{Logger, LoggerConfig},
subscribe::SubscriberCallback,
trace::RawTrace,
};

/// A JSON-RPC provider for Ethereum.
#[napi]
pub struct Provider {
provider: Arc<edr_provider::Provider<LoggerError>>,
provider: Arc<edr_provider::Provider>,
runtime: runtime::Handle,
#[cfg(feature = "scenarios")]
scenario_file: Option<napi::tokio::sync::Mutex<napi::tokio::fs::File>>,
Expand Down
8 changes: 2 additions & 6 deletions crates/edr_provider/src/console_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ impl ConsoleLogCollector {

#[cfg(test)]
pub(crate) mod tests {
use core::fmt::Debug;

use anyhow::Context;
use edr_eth::{
Expand All @@ -65,11 +64,8 @@ pub(crate) mod tests {
pub expected_call_data: Bytes,
}

pub fn deploy_console_log_contract<
LoggerErrorT: Debug + Send + Sync + 'static,
TimerT: Clone + TimeSinceEpoch,
>(
provider_data: &mut ProviderData<LoggerErrorT, TimerT>,
pub fn deploy_console_log_contract<TimerT: Clone + TimeSinceEpoch>(
provider_data: &mut ProviderData<TimerT>,
) -> anyhow::Result<ConsoleLogTransaction> {
// Compiled with solc 0.8.17, without optimizations
/*
Expand Down
Loading
Loading