Browse Source

Use MessageChannel in post_cfd_action HTTP handler

refactor/no-log-handler
Lucas Soriano del Pino 3 years ago
parent
commit
1342db80b1
No known key found for this signature in database GPG Key ID: EE611E973A1530E7
  1. 4
      daemon/src/maker.rs
  2. 40
      daemon/src/routes_maker.rs

4
daemon/src/maker.rs

@ -288,10 +288,12 @@ async fn main() -> Result<()> {
tokio::spawn(maker_inc_connections_address.attach_stream(listener_stream));
tokio::spawn(wallet_sync::new(wallet, wallet_feed_sender));
let cfd_action_channel =
MessageChannel::<maker_cfd::CfdAction>::clone_channel(&cfd_maker_actor_inbox);
let new_order_channel =
MessageChannel::<maker_cfd::NewOrder>::clone_channel(&cfd_maker_actor_inbox);
Ok(rocket
.manage(cfd_maker_actor_inbox)
.manage(cfd_action_channel)
.manage(new_order_channel)
.manage(cfd_feed_receiver))
},

40
daemon/src/routes_maker.rs

@ -18,7 +18,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 maker_feed(
@ -144,55 +143,48 @@ pub struct PromptAuthentication {
}
#[rocket::post("/cfd/<id>/<action>")]
pub async fn post_cfd_action(
pub fn post_cfd_action(
id: OrderId,
action: CfdAction,
cfd_actor_address: &State<Address<maker_cfd::Actor>>,
cfd_action_channel: &State<Box<dyn MessageChannel<maker_cfd::CfdAction>>>,
_auth: Authenticated,
) -> Result<status::Accepted<()>, status::BadRequest<String>> {
use maker_cfd::CfdAction::*;
match action {
CfdAction::AcceptOrder => {
cfd_actor_address
.do_send_async(AcceptOrder { order_id: id })
.await
cfd_action_channel
.do_send(AcceptOrder { order_id: id })
.expect("actor to always be available");
}
CfdAction::RejectOrder => {
cfd_actor_address
.do_send_async(RejectOrder { order_id: id })
.await
cfd_action_channel
.do_send(RejectOrder { order_id: id })
.expect("actor to always be available");
}
CfdAction::AcceptSettlement => {
cfd_actor_address
.do_send_async(AcceptSettlement { order_id: id })
.await
cfd_action_channel
.do_send(AcceptSettlement { order_id: id })
.expect("actor to always be available");
}
CfdAction::RejectSettlement => {
cfd_actor_address
.do_send_async(RejectSettlement { order_id: id })
.await
cfd_action_channel
.do_send(RejectSettlement { order_id: id })
.expect("actor to always be available");
}
CfdAction::AcceptRollOver => {
cfd_actor_address
.do_send_async(AcceptRollOver { order_id: id })
.await
cfd_action_channel
.do_send(AcceptRollOver { order_id: id })
.expect("actor to always be available");
}
CfdAction::RejectRollOver => {
cfd_actor_address
.do_send_async(RejectRollOver { order_id: id })
.await
cfd_action_channel
.do_send(RejectRollOver { order_id: id })
.expect("actor to always be available");
}
CfdAction::Commit => {
cfd_actor_address
.do_send_async(Commit { order_id: id })
.await
cfd_action_channel
.do_send(Commit { order_id: id })
.expect("actor to always be available");
}
CfdAction::Settle => {

Loading…
Cancel
Save