From 4dd27fbd25fefabd382fd2bf4e0453f42945bd5c Mon Sep 17 00:00:00 2001 From: Mariusz Klochowicz Date: Fri, 24 Sep 2021 11:47:49 +0930 Subject: [PATCH] Don't repeat names in module and types Same refactor as recently on the maker side. --- daemon/src/routes_taker.rs | 6 +++--- daemon/src/taker.rs | 4 ++-- .../src/{taker_cfd_actor.rs => taker_cfd.rs} | 18 +++++++++--------- daemon/src/taker_inc_message_actor.rs | 13 ++++++------- 4 files changed, 20 insertions(+), 21 deletions(-) rename daemon/src/{taker_cfd_actor.rs => taker_cfd.rs} (95%) diff --git a/daemon/src/routes_taker.rs b/daemon/src/routes_taker.rs index 2c4c28d..6c5db68 100644 --- a/daemon/src/routes_taker.rs +++ b/daemon/src/routes_taker.rs @@ -1,7 +1,7 @@ use crate::model::cfd::{calculate_buy_margin, Cfd, Order, OrderId}; use crate::model::{Leverage, Usd, WalletInfo}; use crate::routes::EmbeddedFileExt; -use crate::taker_cfd_actor::{self, TakerCfdActor}; +use crate::taker_cfd; use crate::to_sse_event::ToSseEvent; use bdk::bitcoin::Amount; use rocket::http::{ContentType, Status}; @@ -65,10 +65,10 @@ pub struct CfdOrderRequest { #[rocket::post("/cfd", data = "")] pub async fn post_order_request( cfd_order_request: Json, - cfd_actor_inbox: &State>, + cfd_actor_inbox: &State>, ) { cfd_actor_inbox - .do_send_async(taker_cfd_actor::TakeOffer { + .do_send_async(taker_cfd::TakeOffer { order_id: cfd_order_request.order_id, quantity: cfd_order_request.quantity, }) diff --git a/daemon/src/taker.rs b/daemon/src/taker.rs index 6e5a9fd..4c851a5 100644 --- a/daemon/src/taker.rs +++ b/daemon/src/taker.rs @@ -28,7 +28,7 @@ mod routes_taker; mod seed; mod send_wire_message_actor; mod setup_contract_actor; -mod taker_cfd_actor; +mod taker_cfd; mod taker_inc_message_actor; mod to_sse_event; mod wallet; @@ -160,7 +160,7 @@ async fn main() -> Result<()> { let (out_maker_messages_actor, out_maker_actor_inbox) = send_wire_message_actor::new(write); - let cfd_actor_inbox = taker_cfd_actor::TakerCfdActor::new( + let cfd_actor_inbox = taker_cfd::Actor::new( db, wallet.clone(), schnorrsig::PublicKey::from_keypair(SECP256K1, &oracle), diff --git a/daemon/src/taker_cfd_actor.rs b/daemon/src/taker_cfd.rs similarity index 95% rename from daemon/src/taker_cfd_actor.rs rename to daemon/src/taker_cfd.rs index a847674..e8c1ef2 100644 --- a/daemon/src/taker_cfd_actor.rs +++ b/daemon/src/taker_cfd.rs @@ -32,7 +32,7 @@ pub struct CfdSetupCompleted { pub dlc: Dlc, } -pub struct TakerCfdActor { +pub struct Actor { db: sqlx::SqlitePool, wallet: Wallet, oracle_pk: schnorrsig::PublicKey, @@ -45,7 +45,7 @@ pub struct TakerCfdActor { contract_setup_message_buffer: Vec, } -impl TakerCfdActor { +impl Actor { pub async fn new( db: sqlx::SqlitePool, wallet: Wallet, @@ -240,42 +240,42 @@ impl TakerCfdActor { } #[async_trait] -impl Handler for TakerCfdActor { +impl Handler for Actor { async fn handle(&mut self, msg: TakeOffer, _ctx: &mut Context) { log_error!(self.handle_take_offer(msg.order_id, msg.quantity)); } } #[async_trait] -impl Handler for TakerCfdActor { +impl Handler for Actor { async fn handle(&mut self, msg: NewOrder, _ctx: &mut Context) { log_error!(self.handle_new_order(msg.0)); } } #[async_trait] -impl Handler for TakerCfdActor { +impl Handler for Actor { async fn handle(&mut self, msg: OrderAccepted, ctx: &mut Context) { log_error!(self.handle_order_accepted(msg.0, ctx)); } } #[async_trait] -impl Handler for TakerCfdActor { +impl Handler for Actor { async fn handle(&mut self, msg: OrderRejected, _ctx: &mut Context) { log_error!(self.handle_order_rejected(msg.0)); } } #[async_trait] -impl Handler for TakerCfdActor { +impl Handler for Actor { async fn handle(&mut self, msg: IncProtocolMsg, _ctx: &mut Context) { log_error!(self.handle_inc_protocol_msg(msg.0)); } } #[async_trait] -impl Handler for TakerCfdActor { +impl Handler for Actor { async fn handle(&mut self, msg: CfdSetupCompleted, _ctx: &mut Context) { log_error!(self.handle_cfd_setup_completed(msg.order_id, msg.dlc)); } @@ -305,4 +305,4 @@ impl Message for CfdSetupCompleted { type Result = (); } -impl xtra::Actor for TakerCfdActor {} +impl xtra::Actor for Actor {} diff --git a/daemon/src/taker_inc_message_actor.rs b/daemon/src/taker_inc_message_actor.rs index f4c0412..75e0a3e 100644 --- a/daemon/src/taker_inc_message_actor.rs +++ b/daemon/src/taker_inc_message_actor.rs @@ -1,12 +1,11 @@ use crate::model::cfd::Origin; -use crate::taker_cfd_actor::TakerCfdActor; -use crate::{taker_cfd_actor, wire}; +use crate::{taker_cfd, wire}; use futures::{Future, StreamExt}; use tokio::net::tcp::OwnedReadHalf; use tokio_util::codec::{FramedRead, LengthDelimitedCodec}; use xtra::prelude::*; -pub fn new(read: OwnedReadHalf, cfd_actor: Address) -> impl Future { +pub fn new(read: OwnedReadHalf, cfd_actor: Address) -> impl Future { let frame_read = FramedRead::new(read, LengthDelimitedCodec::new()); let mut messages = frame_read.map(|result| { @@ -22,20 +21,20 @@ pub fn new(read: OwnedReadHalf, cfd_actor: Address) -> impl Futur order.origin = Origin::Theirs; } cfd_actor - .do_send_async(taker_cfd_actor::NewOrder(order)) + .do_send_async(taker_cfd::NewOrder(order)) .await .expect("actor to be always available"); } Ok(wire::MakerToTaker::ConfirmOrder(order_id)) => { // TODO: This naming is not well aligned. cfd_actor - .do_send_async(taker_cfd_actor::OrderAccepted(order_id)) + .do_send_async(taker_cfd::OrderAccepted(order_id)) .await .expect("actor to be always available"); } Ok(wire::MakerToTaker::RejectOrder(order_id)) => { cfd_actor - .do_send_async(taker_cfd_actor::OrderRejected(order_id)) + .do_send_async(taker_cfd::OrderRejected(order_id)) .await .expect("actor to be always available"); } @@ -44,7 +43,7 @@ pub fn new(read: OwnedReadHalf, cfd_actor: Address) -> impl Futur } Ok(wire::MakerToTaker::Protocol(msg)) => { cfd_actor - .do_send_async(taker_cfd_actor::IncProtocolMsg(msg)) + .do_send_async(taker_cfd::IncProtocolMsg(msg)) .await .expect("actor to be always available"); }