Skip to content

Commit f0ebfd0

Browse files
authored
refactor: decouple Logger and Provider generics (#599)
1 parent 0167f7f commit f0ebfd0

36 files changed

+420
-599
lines changed

crates/edr_napi/src/logger.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ impl Logger {
128128
impl edr_provider::Logger<L1ChainSpec> for Logger {
129129
type BlockchainError = BlockchainError<L1ChainSpec>;
130130

131-
type LoggerError = LoggerError;
132-
133131
fn is_enabled(&self) -> bool {
134132
self.collector.is_enabled
135133
}
@@ -143,7 +141,7 @@ impl edr_provider::Logger<L1ChainSpec> for Logger {
143141
spec_id: edr_eth::SpecId,
144142
transaction: &transaction::Signed,
145143
result: &edr_provider::CallResult,
146-
) -> Result<(), Self::LoggerError> {
144+
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
147145
self.collector.log_call(spec_id, transaction, result);
148146

149147
Ok(())
@@ -154,7 +152,7 @@ impl edr_provider::Logger<L1ChainSpec> for Logger {
154152
spec_id: edr_eth::SpecId,
155153
transaction: &transaction::Signed,
156154
failure: &edr_provider::EstimateGasFailure,
157-
) -> Result<(), Self::LoggerError> {
155+
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
158156
self.collector
159157
.log_estimate_gas(spec_id, transaction, failure);
160158

@@ -165,15 +163,19 @@ impl edr_provider::Logger<L1ChainSpec> for Logger {
165163
&mut self,
166164
spec_id: edr_eth::SpecId,
167165
mining_result: &edr_provider::DebugMineBlockResult<L1ChainSpec, Self::BlockchainError>,
168-
) -> Result<(), Self::LoggerError> {
169-
self.collector.log_interval_mined(spec_id, mining_result)
166+
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
167+
self.collector
168+
.log_interval_mined(spec_id, mining_result)
169+
.map_err(Box::new)?;
170+
171+
Ok(())
170172
}
171173

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

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

@@ -194,8 +196,8 @@ impl edr_provider::Logger<L1ChainSpec> for Logger {
194196
fn print_method_logs(
195197
&mut self,
196198
method: &str,
197-
error: Option<&ProviderError<LoggerError>>,
198-
) -> Result<(), Self::LoggerError> {
199+
error: Option<&ProviderError>,
200+
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
199201
if let Some(error) = error {
200202
self.collector.state = LoggingState::Empty;
201203

crates/edr_napi/src/provider.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ use self::config::ProviderConfig;
1212
use crate::{
1313
call_override::CallOverrideCallback,
1414
context::EdrContext,
15-
logger::{Logger, LoggerConfig, LoggerError},
15+
logger::{Logger, LoggerConfig},
1616
subscribe::SubscriberCallback,
1717
trace::RawTrace,
1818
};
1919

2020
/// A JSON-RPC provider for Ethereum.
2121
#[napi]
2222
pub struct Provider {
23-
provider: Arc<edr_provider::Provider<LoggerError>>,
23+
provider: Arc<edr_provider::Provider>,
2424
runtime: runtime::Handle,
2525
#[cfg(feature = "scenarios")]
2626
scenario_file: Option<napi::tokio::sync::Mutex<napi::tokio::fs::File>>,

crates/edr_provider/src/console_log.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ impl ConsoleLogCollector {
4949

5050
#[cfg(test)]
5151
pub(crate) mod tests {
52-
use core::fmt::Debug;
5352

5453
use anyhow::Context;
5554
use edr_eth::{
@@ -65,11 +64,8 @@ pub(crate) mod tests {
6564
pub expected_call_data: Bytes,
6665
}
6766

68-
pub fn deploy_console_log_contract<
69-
LoggerErrorT: Debug + Send + Sync + 'static,
70-
TimerT: Clone + TimeSinceEpoch,
71-
>(
72-
provider_data: &mut ProviderData<LoggerErrorT, TimerT>,
67+
pub fn deploy_console_log_contract<TimerT: Clone + TimeSinceEpoch>(
68+
provider_data: &mut ProviderData<TimerT>,
7369
) -> anyhow::Result<ConsoleLogTransaction> {
7470
// Compiled with solc 0.8.17, without optimizations
7571
/*

0 commit comments

Comments
 (0)