From 232d80397902156f7863bbb28b2ce56c15776b26 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 8 Oct 2021 12:08:04 +1100 Subject: [PATCH] Simplify trait bounds on oracle::Actor --- daemon/src/oracle.rs | 57 ++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/daemon/src/oracle.rs b/daemon/src/oracle.rs index bf352a0..bda7e69 100644 --- a/daemon/src/oracle.rs +++ b/daemon/src/oracle.rs @@ -16,22 +16,14 @@ use std::collections::{HashMap, HashSet}; const OLIVIA_EVENT_TIME_FORMAT: &[FormatItem] = format_description!("[year]-[month]-[day]T[hour]:[minute]:[second]"); -pub struct Actor -where - CFD: xtra::Handler, - M: xtra::Handler, -{ +pub struct Actor { latest_announcements: HashMap, pending_attestations: HashSet, cfd_actor_address: xtra::Address, monitor_actor_address: xtra::Address, } -impl Actor -where - CFD: xtra::Handler, - M: xtra::Handler, -{ +impl Actor { pub fn new( cfd_actor_address: xtra::Address, monitor_actor_address: xtra::Address, @@ -72,6 +64,22 @@ where } } + fn monitor_event(&mut self, event_id: OracleEventId) { + if !self.pending_attestations.insert(event_id.clone()) { + tracing::trace!("Event {} already being monitored", event_id); + } + } + + fn handle_get_announcement(&self, event_id: OracleEventId) -> Option { + self.latest_announcements.get(&event_id).cloned() + } +} + +impl Actor +where + CFD: xtra::Handler, + M: xtra::Handler, +{ async fn update_state(&mut self) -> Result<()> { self.update_latest_announcements() .await @@ -148,24 +156,9 @@ where Ok(()) } - - fn monitor_event(&mut self, event_id: OracleEventId) { - if !self.pending_attestations.insert(event_id.clone()) { - tracing::trace!("Event {} already being monitored", event_id); - } - } - - pub fn handle_get_announcement(&self, event_id: OracleEventId) -> Option { - self.latest_announcements.get(&event_id).cloned() - } } -impl xtra::Actor for Actor -where - CFD: xtra::Handler, - M: xtra::Handler, -{ -} +impl xtra::Actor for Actor {} pub struct Sync; @@ -193,11 +186,7 @@ impl xtra::Message for MonitorEvent { } #[async_trait] -impl xtra::Handler for Actor -where - CFD: xtra::Handler, - M: xtra::Handler, -{ +impl xtra::Handler for Actor { async fn handle(&mut self, msg: MonitorEvent, _ctx: &mut xtra::Context) { self.monitor_event(msg.event_id) } @@ -207,11 +196,7 @@ where pub struct GetAnnouncement(pub OracleEventId); #[async_trait] -impl xtra::Handler for Actor -where - CFD: xtra::Handler, - M: xtra::Handler, -{ +impl xtra::Handler for Actor { async fn handle( &mut self, msg: GetAnnouncement,