Browse Source

Maker uses latest announcements from oracle in contract setup

upload-correct-windows-binary
Daniel Karzel 3 years ago
parent
commit
5842ff37a8
No known key found for this signature in database GPG Key ID: 30C3FC2E438ADB6E
  1. 52
      daemon/src/maker_cfd.rs

52
daemon/src/maker_cfd.rs

@ -74,8 +74,8 @@ pub struct Actor {
current_order_id: Option<OrderId>, current_order_id: Option<OrderId>,
monitor_actor: Address<monitor::Actor<Actor>>, monitor_actor: Address<monitor::Actor<Actor>>,
setup_state: SetupState, setup_state: SetupState,
latest_announcement: Option<oracle::Announcement>, latest_announcements: Option<oracle::Announcements>,
_oracle_actor: Address<oracle::Actor<Actor, monitor::Actor<Actor>>>, oracle_actor: Address<oracle::Actor<Actor, monitor::Actor<Actor>>>,
current_settlement_proposals: HashMap<OrderId, SettlementProposal>, current_settlement_proposals: HashMap<OrderId, SettlementProposal>,
} }
@ -111,8 +111,8 @@ impl Actor {
current_order_id: None, current_order_id: None,
monitor_actor, monitor_actor,
setup_state: SetupState::None, setup_state: SetupState::None,
latest_announcement: None, latest_announcements: None,
_oracle_actor: oracle_actor, oracle_actor,
current_settlement_proposals: HashMap::new(), current_settlement_proposals: HashMap::new(),
} }
} }
@ -131,11 +131,16 @@ impl Actor {
min_quantity: Usd, min_quantity: Usd,
max_quantity: Usd, max_quantity: Usd,
) -> Result<()> { ) -> Result<()> {
let oracle_event_id = if let Some(latest_announcement) = self.latest_announcement.clone() { let oracle_event_id = self
latest_announcement.id .latest_announcements
} else { .clone()
bail!("Cannot create order because no announcement from oracle") .context("Cannot create order because no announcement from oracle")?
}; .0
.iter()
.last()
.context("Empty list of announcements")?
.clone()
.id;
let order = Order::new( let order = Order::new(
price, price,
@ -363,18 +368,23 @@ impl Actor {
self.cfd_feed_actor_inbox self.cfd_feed_actor_inbox
.send(load_all_cfds(&mut conn).await?)?; .send(load_all_cfds(&mut conn).await?)?;
// let latest_announcement = self let offer_announcements = self
// .latest_announcement .latest_announcements
// .to_owned() .clone()
// .context("Unaware of oracle's latest announcement.")?; .context("No oracle announcements available")?;
let offer_announcement = offer_announcements
// self.oracle_actor .0
// .do_send_async(oracle::MonitorEvent { .iter()
// event_id: latest_announcement.id, .find(|announcement| announcement.id == cfd.order.oracle_event_id)
// }) .context("Order's announcement not found in list of current oracle announcements")?;
// .await?;
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( let contract_future = setup_contract::new(
self.takers.clone().into_sink().with(move |msg| { self.takers.clone().into_sink().with(move |msg| {
@ -533,7 +543,7 @@ impl Actor {
announcements: oracle::Announcements, announcements: oracle::Announcements,
) -> Result<()> { ) -> Result<()> {
tracing::debug!("Updating latest oracle announcements"); tracing::debug!("Updating latest oracle announcements");
self.latest_announcement = Some(announcements.0.last().unwrap().clone()); self.latest_announcements = Some(announcements);
Ok(()) Ok(())
} }

Loading…
Cancel
Save