Clean generics in Tendermint with a monolith with associated types

This commit is contained in:
Luke Parker
2022-10-30 03:26:31 -04:00
parent 8d3efd6259
commit 6838d5c922
9 changed files with 218 additions and 269 deletions

View File

@@ -2,41 +2,21 @@ use std::sync::Arc;
use async_trait::async_trait;
use sp_inherents::CreateInherentDataProviders;
use sp_runtime::traits::Block;
use sp_api::TransactionFor;
use sp_consensus::{Error, CacheKeyId, Environment};
use sp_consensus::{Error, CacheKeyId};
use sc_consensus::{BlockImportParams, BlockImport, Verifier};
use sc_client_api::Backend;
use sp_tendermint::TendermintApi;
use crate::{
tendermint::{TendermintClient, TendermintImport},
Announce,
};
use crate::{types::TendermintAuthor, tendermint::TendermintImport};
#[async_trait]
impl<
B: Block,
Be: Backend<B> + 'static,
C: TendermintClient<B, Be>,
CIDP: CreateInherentDataProviders<B, ()> + 'static,
E: Send + Sync + Environment<B> + 'static,
A: Announce<B>,
> Verifier<B> for TendermintImport<B, Be, C, CIDP, E, A>
impl<T: TendermintAuthor> Verifier<T::Block> for TendermintImport<T>
where
TransactionFor<C, B>: Send + Sync + 'static,
Arc<C>: BlockImport<B, Transaction = TransactionFor<C, B>>,
<Arc<C> as BlockImport<B>>::Error: Into<Error>,
C::Api: TendermintApi<B>,
Arc<T::Client>: BlockImport<T::Block, Transaction = T::BackendTransaction>,
<Arc<T::Client> as BlockImport<T::Block>>::Error: Into<Error>,
{
async fn verify(
&mut self,
mut block: BlockImportParams<B, ()>,
) -> Result<(BlockImportParams<B, ()>, Option<Vec<(CacheKeyId, Vec<u8>)>>), String> {
mut block: BlockImportParams<T::Block, ()>,
) -> Result<(BlockImportParams<T::Block, ()>, Option<Vec<(CacheKeyId, Vec<u8>)>>), String> {
self.check(&mut block).await.map_err(|e| format!("{}", e))?;
Ok((block, None))
}