//! Contains the [PlasmaDataSource], which is a concrete implementation of the //! [DataAvailabilityProvider] trait for the Plasma source. Used as an adapter to the //! [kona_derive] crate's derivation pipeline construction. use crate::{source::PlasmaSource, traits::PlasmaInputFetcher}; use alloc::{boxed::Box, fmt::Debug}; use alloy_primitives::Bytes; use anyhow::Result; use async_trait::async_trait; use kona_derive::traits::{ChainProvider, DataAvailabilityProvider}; use kona_primitives::BlockInfo; /// The plasma data source implements the [DataAvailabilityProvider] trait for the Plasma source. #[derive(Debug, Clone, Copy)] pub struct PlasmaDataSource where C: ChainProvider + Send + Clone, F: PlasmaInputFetcher + Clone, I: Iterator + Send + Clone, { /// The chain provider. pub chain_provider: C, /// The plasma input fetcher. pub plasma_input_fetcher: F, /// The plasma iterator. pub plasma_source: I, } impl PlasmaDataSource where C: ChainProvider + Send + Clone + Debug, F: PlasmaInputFetcher + Clone, I: Iterator + Send + Clone, { /// Creates a new [PlasmaDataSource] from the given providers. pub fn new(chain_provider: C, plasma_input_fetcher: F, plasma_source: I) -> Self { Self { chain_provider, plasma_input_fetcher, plasma_source } } } #[async_trait] impl DataAvailabilityProvider for PlasmaDataSource where C: ChainProvider + Send + Clone + Debug + Sync, F: PlasmaInputFetcher + Clone + Debug + Send + Sync, I: Iterator + Send + Clone + Debug + Sync, { type Item = Bytes; type DataIter = PlasmaSource; async fn open_data(&self, block_ref: &BlockInfo) -> Result { Ok(PlasmaSource::new( self.chain_provider.clone(), self.plasma_input_fetcher.clone(), self.plasma_source.clone(), block_ref.id(), )) } }