diff --git a/daemon/src/maker_cfd.rs b/daemon/src/maker_cfd.rs index 2a9374e..85dae13 100644 --- a/daemon/src/maker_cfd.rs +++ b/daemon/src/maker_cfd.rs @@ -12,7 +12,7 @@ use crate::model::{TakerId, Usd}; use crate::monitor::MonitorParams; use crate::wallet::Wallet; use crate::{maker_inc_connections, monitor, oracle, setup_contract, wire}; -use anyhow::{Context as _, Result}; +use anyhow::{bail, Context as _, Result}; use async_trait::async_trait; use bdk::bitcoin::secp256k1::schnorrsig; use futures::channel::mpsc; diff --git a/daemon/src/oracle.rs b/daemon/src/oracle.rs index 95e5e15..38fc04a 100644 --- a/daemon/src/oracle.rs +++ b/daemon/src/oracle.rs @@ -208,6 +208,7 @@ pub struct Announcement { pub nonce_pks: Vec, } +#[derive(Debug, Clone)] pub struct Announcements(pub [Announcement; 24]); // TODO: Implement real deserialization once price attestation is diff --git a/daemon/src/taker_cfd.rs b/daemon/src/taker_cfd.rs index ad92ca7..8a056c8 100644 --- a/daemon/src/taker_cfd.rs +++ b/daemon/src/taker_cfd.rs @@ -63,8 +63,8 @@ pub struct Actor { send_to_maker: Address>, monitor_actor: Address>, setup_state: SetupState, - latest_announcement: Option, - _oracle_actor: Address>>, + latest_announcements: Option, + oracle_actor: Address>>, current_settlement_proposals: HashMap, } @@ -91,8 +91,8 @@ impl Actor { send_to_maker, monitor_actor, setup_state: SetupState::None, - latest_announcement: None, - _oracle_actor: oracle_actor, + oracle_actor, + latest_announcements: None, current_settlement_proposals: HashMap::new(), } } @@ -213,18 +213,23 @@ impl Actor { .send(load_all_cfds(&mut conn).await?)?; let cfd = load_cfd_by_order_id(order_id, &mut conn).await?; - // let latest_announcement = self - // .latest_announcement - // .to_owned() - // .context("Unaware of oracle's latest announcement.")?; - - // self.oracle_actor - // .do_send_async(oracle::MonitorEvent { - // event_id: latest_announcement.id, - // }) - // .await?; + let offer_announcements = self + .latest_announcements + .clone() + .context("No oracle announcements available")?; + let offer_announcement = offer_announcements + .0 + .iter() + .find(|announcement| announcement.id == cfd.order.oracle_event_id) + .context("Order's announcement not found in list of current oracle announcements")?; + + self.oracle_actor + .do_send_async(oracle::MonitorEvent { + event_id: offer_announcement.id.clone(), + }) + .await?; - let nonce_pks = Vec::new(); + let nonce_pks = offer_announcement.nonce_pks.clone(); let contract_future = setup_contract::new( self.send_to_maker @@ -392,8 +397,7 @@ impl Actor { &mut self, announcements: oracle::Announcements, ) -> Result<()> { - tracing::debug!("Updating latest oracle announcements"); - self.latest_announcement = Some(announcements.0.last().unwrap().clone()); + self.latest_announcements = Some(announcements); Ok(()) }