Browse Source

Taker uses latest announcements from oracle to start contract setup

Opted not to implement an additional message to fetch a specific announcement from the Oracle actor because it would have made the oracle actor unnecessarily complex (We would have to split it into different functionality by trait).
The taker cfd actor holds a sliding window of all the announcements received from the oracle actor.
upload-correct-windows-binary
Daniel Karzel 3 years ago
parent
commit
61d62e7263
No known key found for this signature in database GPG Key ID: 30C3FC2E438ADB6E
  1. 2
      daemon/src/maker_cfd.rs
  2. 1
      daemon/src/oracle.rs
  3. 38
      daemon/src/taker_cfd.rs

2
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;

1
daemon/src/oracle.rs

@ -208,6 +208,7 @@ pub struct Announcement {
pub nonce_pks: Vec<schnorrsig::PublicKey>,
}
#[derive(Debug, Clone)]
pub struct Announcements(pub [Announcement; 24]);
// TODO: Implement real deserialization once price attestation is

38
daemon/src/taker_cfd.rs

@ -63,8 +63,8 @@ pub struct Actor {
send_to_maker: Address<send_to_socket::Actor<wire::TakerToMaker>>,
monitor_actor: Address<monitor::Actor<Actor>>,
setup_state: SetupState,
latest_announcement: Option<oracle::Announcement>,
_oracle_actor: Address<oracle::Actor<Actor, monitor::Actor<Actor>>>,
latest_announcements: Option<oracle::Announcements>,
oracle_actor: Address<oracle::Actor<Actor, monitor::Actor<Actor>>>,
current_settlement_proposals: HashMap<OrderId, SettlementProposal>,
}
@ -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(())
}

Loading…
Cancel
Save