use std::fmt;
use zksync_dal::{Connection, Core};
use zksync_eth_client::{ContractCallError, EnrichedClientError};
use zksync_types::{web3::Log, H256};
pub(crate) use self::{
decentralized_upgrades::DecentralizedUpgradesEventProcessor,
governance_upgrades::GovernanceUpgradesEventProcessor, priority_ops::PriorityOpsEventProcessor,
};
use crate::client::EthClient;
mod decentralized_upgrades;
mod governance_upgrades;
mod priority_ops;
#[derive(Debug, thiserror::Error)]
pub(super) enum EventProcessorError {
#[error("failed parsing a log into {log_kind}: {source:?}")]
LogParse {
log_kind: &'static str,
#[source]
source: anyhow::Error,
},
#[error("Eth client error: {0}")]
Client(#[from] EnrichedClientError),
#[error("Contract call error: {0}")]
ContractCall(#[from] ContractCallError),
#[error("internal processing error: {0:?}")]
Internal(#[from] anyhow::Error),
}
impl EventProcessorError {
pub fn log_parse(source: impl Into<anyhow::Error>, log_kind: &'static str) -> Self {
Self::LogParse {
log_kind,
source: source.into(),
}
}
}
#[async_trait::async_trait]
pub(super) trait EventProcessor: 'static + fmt::Debug + Send + Sync {
async fn process_events(
&mut self,
storage: &mut Connection<'_, Core>,
client: &dyn EthClient,
events: Vec<Log>,
) -> Result<(), EventProcessorError>;
fn relevant_topic(&self) -> H256;
}