From 05c1674ae3ba43b9779fbb961fd68fe7294ace5a Mon Sep 17 00:00:00 2001 From: Lucas Soriano del Pino Date: Fri, 15 Oct 2021 14:45:26 +1100 Subject: [PATCH] Use MessageChannel in taker's post_cfd_action HTTP handler --- daemon/src/routes_taker.rs | 18 +++++++----------- daemon/src/taker.rs | 4 +++- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/daemon/src/routes_taker.rs b/daemon/src/routes_taker.rs index 556846b..03094e0 100644 --- a/daemon/src/routes_taker.rs +++ b/daemon/src/routes_taker.rs @@ -16,7 +16,6 @@ use std::path::PathBuf; use tokio::select; use tokio::sync::watch; use xtra::prelude::MessageChannel; -use xtra::Address; #[rocket::get("/feed")] pub async fn feed( @@ -119,7 +118,7 @@ pub async fn post_order_request( pub async fn post_cfd_action( id: OrderId, action: CfdAction, - cfd_actor_address: &State>, + cfd_action_channel: &State>>, quote_updates: &State>, ) -> Result, status::BadRequest> { use taker_cfd::CfdAction::*; @@ -133,25 +132,22 @@ pub async fn post_cfd_action( return Err(status::BadRequest(None)); } CfdAction::Commit => { - cfd_actor_address - .do_send_async(Commit { order_id: id }) - .await + cfd_action_channel + .do_send(Commit { order_id: id }) .map_err(|e| status::BadRequest(Some(e.to_string())))?; } CfdAction::Settle => { let current_price = quote_updates.borrow().for_taker(); - cfd_actor_address - .do_send_async(ProposeSettlement { + cfd_action_channel + .do_send(ProposeSettlement { order_id: id, current_price, }) - .await .expect("actor to always be available"); } CfdAction::RollOver => { - cfd_actor_address - .do_send_async(ProposeRollOver { order_id: id }) - .await + cfd_action_channel + .do_send(ProposeRollOver { order_id: id }) .expect("actor to always be available"); } } diff --git a/daemon/src/taker.rs b/daemon/src/taker.rs index 3bbdbe9..967dc79 100644 --- a/daemon/src/taker.rs +++ b/daemon/src/taker.rs @@ -267,9 +267,11 @@ async fn main() -> Result<()> { let take_offer_channel = MessageChannel::::clone_channel(&cfd_actor_inbox); + let cfd_action_channel = + MessageChannel::::clone_channel(&cfd_actor_inbox); Ok(rocket .manage(take_offer_channel) - .manage(cfd_actor_inbox) + .manage(cfd_action_channel) .manage(cfd_feed_receiver)) }, ))