espresso_node/api/
update.rs1use std::{fmt::Debug, sync::Arc};
4
5use anyhow::bail;
6use async_trait::async_trait;
7use derivative::Derivative;
8use derive_more::From;
9use espresso_types::{PubKey, v0::traits::SequencerPersistence};
10use hotshot_query_service::data_source::UpdateDataSource;
11use hotshot_types::{new_protocol::CoordinatorEvent, traits::network::ConnectedNetwork};
12
13use super::{StorageState, data_source::SequencerDataSource};
14use crate::{EventConsumer, SeqTypes};
15
16#[derive(Derivative, From)]
17#[derivative(Clone(bound = ""), Debug(bound = "D: Debug"))]
18pub(crate) struct ApiEventConsumer<N, P, D>
19where
20 N: ConnectedNetwork<PubKey>,
21 P: SequencerPersistence,
22{
23 inner: Arc<StorageState<N, P, D>>,
24}
25
26#[async_trait]
27impl<N, P, D> EventConsumer for ApiEventConsumer<N, P, D>
28where
29 N: ConnectedNetwork<PubKey>,
30 P: SequencerPersistence,
31 D: SequencerDataSource + Debug + Send + Sync + 'static,
32{
33 async fn handle_event(&self, event: &CoordinatorEvent<SeqTypes>) -> anyhow::Result<()> {
34 if let Err(height) = self.inner.update(event).await {
35 bail!("failed to update API state after {height}: {event:?}",);
36 }
37 Ok(())
38 }
39}