From c0a1c9c82bd329be80ad890de44f1627879ec94a Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 12 Oct 2021 10:20:41 +1100 Subject: [PATCH] Re-organize oracle module a bit --- daemon/src/oracle.rs | 74 +++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/daemon/src/oracle.rs b/daemon/src/oracle.rs index 299a567..4513f20 100644 --- a/daemon/src/oracle.rs +++ b/daemon/src/oracle.rs @@ -25,6 +25,24 @@ pub struct Actor { monitor_actor_address: xtra::Address, } +pub struct Sync; + +pub struct MonitorEvent { + pub event_id: OracleEventId, +} + +#[derive(Debug, Clone)] +pub struct GetAnnouncement(pub OracleEventId); + +// TODO: Split xtra::Message and API object +#[derive(Debug, Clone, Deserialize, PartialEq)] +#[serde(try_from = "olivia_api::Response")] +pub struct Attestation { + pub id: OracleEventId, + pub price: u64, + pub scalars: Vec, +} + impl Actor { pub fn new( cfd_actor_address: xtra::Address, @@ -154,33 +172,6 @@ where } } -impl xtra::Actor for Actor {} - -pub struct Sync; - -impl xtra::Message for Sync { - type Result = (); -} - -#[async_trait] -impl xtra::Handler for Actor -where - CFD: xtra::Handler, - M: xtra::Handler, -{ - async fn handle(&mut self, _: Sync, _ctx: &mut xtra::Context) { - log_error!(self.update_state()) - } -} - -pub struct MonitorEvent { - pub event_id: OracleEventId, -} - -impl xtra::Message for MonitorEvent { - type Result = (); -} - #[async_trait] impl xtra::Handler for Actor { async fn handle(&mut self, msg: MonitorEvent, _ctx: &mut xtra::Context) { @@ -190,9 +181,6 @@ impl xtra::Handler for Actor { } } -#[derive(Debug, Clone)] -pub struct GetAnnouncement(pub OracleEventId); - #[async_trait] impl xtra::Handler for Actor { async fn handle( @@ -269,14 +257,24 @@ impl From for cfd_protocol::Announcement { } } -// TODO: Implement real deserialization once price attestation is -// implemented in `olivia` -#[derive(Debug, Clone, Deserialize, PartialEq)] -#[serde(try_from = "olivia_api::Response")] -pub struct Attestation { - pub id: OracleEventId, - pub price: u64, - pub scalars: Vec, +impl xtra::Actor for Actor {} + +#[async_trait] +impl xtra::Handler for Actor +where + CFD: xtra::Handler, + M: xtra::Handler, +{ + async fn handle(&mut self, _: Sync, _ctx: &mut xtra::Context) { + log_error!(self.update_state()) + } +} + +impl xtra::Message for Sync { + type Result = (); +} +impl xtra::Message for MonitorEvent { + type Result = (); } impl xtra::Message for GetAnnouncement {