use crate::{Block, Reporter}; use std::{ collections::BTreeMap, sync::{Arc, Mutex}, }; /// A mock application that stores finalized blocks. #[derive(Clone)] pub struct Application { blocks: Arc>>, } impl Default for Application { fn default() -> Self { Self { blocks: Default::default(), } } } impl Application { /// Returns the finalized blocks. pub fn blocks(&self) -> BTreeMap { self.blocks.lock().unwrap().clone() } } impl Reporter for Application { type Activity = B; async fn report(&mut self, activity: Self::Activity) { self.blocks .lock() .unwrap() .insert(activity.height(), activity); } }