use std::fmt::{self, Display};
use async_trait::async_trait;
use serde::de::DeserializeOwned;
use serde::Serialize;
use crate::da::{BlockHeaderTrait, DaSpec, DaVerifier};
use crate::zk::ValidityCondition;
#[async_trait]
pub trait DaService: Send + Sync + 'static {
type Spec: DaSpec;
type Verifier: DaVerifier<Spec = Self::Spec>;
type FilteredBlock: SlotData<
BlockHeader = <Self::Spec as DaSpec>::BlockHeader,
Cond = <Self::Spec as DaSpec>::ValidityCondition,
>;
type Error: fmt::Debug + Send + Sync + Display;
async fn get_finalized_at(&self, height: u64) -> Result<Self::FilteredBlock, Self::Error>;
async fn get_block_at(&self, height: u64) -> Result<Self::FilteredBlock, Self::Error>;
fn extract_relevant_blobs(
&self,
block: &Self::FilteredBlock,
) -> Vec<<Self::Spec as DaSpec>::BlobTransaction>;
async fn get_extraction_proof(
&self,
block: &Self::FilteredBlock,
blobs: &[<Self::Spec as DaSpec>::BlobTransaction],
) -> (
<Self::Spec as DaSpec>::InclusionMultiProof,
<Self::Spec as DaSpec>::CompletenessProof,
);
#[allow(clippy::type_complexity)]
async fn extract_relevant_blobs_with_proof(
&self,
block: &Self::FilteredBlock,
) -> (
Vec<<Self::Spec as DaSpec>::BlobTransaction>,
<Self::Spec as DaSpec>::InclusionMultiProof,
<Self::Spec as DaSpec>::CompletenessProof,
) {
let relevant_txs = self.extract_relevant_blobs(block);
let (etx_proofs, rollup_row_proofs) = self
.get_extraction_proof(block, relevant_txs.as_slice())
.await;
(relevant_txs, etx_proofs, rollup_row_proofs)
}
async fn send_transaction(&self, blob: &[u8]) -> Result<(), Self::Error>;
}
pub trait SlotData:
Serialize + DeserializeOwned + PartialEq + core::fmt::Debug + Clone + Send + Sync
{
type BlockHeader: BlockHeaderTrait;
type Cond: ValidityCondition;
fn hash(&self) -> [u8; 32];
fn header(&self) -> &Self::BlockHeader;
fn validity_condition(&self) -> Self::Cond;
}