use hashgraph_like_consensus::storage::ConsensusStorage;
use crate::core::{ConsensusPlugin, PluginConsensus};
pub struct ConsensusContext<P: ConsensusPlugin> {
storage: P::ConsensusStorage,
signer: P::Signer,
}
impl<P: ConsensusPlugin> ConsensusContext<P> {
pub fn new(signer: P::Signer) -> Self {
Self {
storage: P::new_storage(),
signer,
}
}
pub fn build_service(&self) -> PluginConsensus<P> {
PluginConsensus::<P>::new_with_components(
self.storage.clone(),
P::new_event_bus(),
self.signer.clone(),
10,
)
}
pub async fn delete_scope(
&self,
scope: &P::Scope,
) -> Result<(), hashgraph_like_consensus::error::ConsensusError> {
self.storage.delete_scope(scope).await
}
}
impl<P: ConsensusPlugin> Clone for ConsensusContext<P> {
fn clone(&self) -> Self {
Self {
storage: self.storage.clone(),
signer: self.signer.clone(),
}
}
}