Skip to content

Commit

Permalink
dev(better_theoros): Simpler struct
Browse files Browse the repository at this point in the history
  • Loading branch information
akhercha committed Nov 1, 2024
1 parent ac4907d commit 733e8df
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions rust/theoros/src/storage/updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@ use crate::types::hyperlane::DispatchUpdateInfos;

/// Contains a mapping between feed ids and their latest dispatch update.
#[derive(Debug, Default)]
pub struct LatestUpdatePerFeedStorage {
events: RwLock<HashMap<U256, DispatchUpdateInfos>>,
}
pub struct LatestUpdatePerFeedStorage(RwLock<HashMap<U256, DispatchUpdateInfos>>);

impl LatestUpdatePerFeedStorage {
/// Insert the latest [`DispatchUpdateInfos`] for a feed id.
pub async fn add(&self, feed_id: U256, event: DispatchUpdateInfos) -> Result<()> {
let mut events = self.events.write().await;
let mut events = self.0.write().await;
events.insert(feed_id, event);
Ok(())
}

/// Retrieves the latest [`DispatchUpdateInfos`] for a feed id.
pub async fn get(&self, feed_id: &U256) -> Result<Option<DispatchUpdateInfos>> {
let events = self.events.read().await;
let events = self.0.read().await;
Ok(events.get(feed_id).cloned())
}
}

0 comments on commit 733e8df

Please sign in to comment.