Browse Source

Don't repeat names in module and types

Same refactor as recently on the maker side.
fix-bad-api-calls
Mariusz Klochowicz 3 years ago
parent
commit
4dd27fbd25
No known key found for this signature in database GPG Key ID: 470C865699C8D4D
  1. 6
      daemon/src/routes_taker.rs
  2. 4
      daemon/src/taker.rs
  3. 18
      daemon/src/taker_cfd.rs
  4. 13
      daemon/src/taker_inc_message_actor.rs

6
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 = "<cfd_order_request>")]
pub async fn post_order_request(
cfd_order_request: Json<CfdOrderRequest>,
cfd_actor_inbox: &State<Address<TakerCfdActor>>,
cfd_actor_inbox: &State<Address<taker_cfd::Actor>>,
) {
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,
})

4
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),

18
daemon/src/taker_cfd_actor.rs → 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<SetupMsg>,
}
impl TakerCfdActor {
impl Actor {
pub async fn new(
db: sqlx::SqlitePool,
wallet: Wallet,
@ -240,42 +240,42 @@ impl TakerCfdActor {
}
#[async_trait]
impl Handler<TakeOffer> for TakerCfdActor {
impl Handler<TakeOffer> for Actor {
async fn handle(&mut self, msg: TakeOffer, _ctx: &mut Context<Self>) {
log_error!(self.handle_take_offer(msg.order_id, msg.quantity));
}
}
#[async_trait]
impl Handler<NewOrder> for TakerCfdActor {
impl Handler<NewOrder> for Actor {
async fn handle(&mut self, msg: NewOrder, _ctx: &mut Context<Self>) {
log_error!(self.handle_new_order(msg.0));
}
}
#[async_trait]
impl Handler<OrderAccepted> for TakerCfdActor {
impl Handler<OrderAccepted> for Actor {
async fn handle(&mut self, msg: OrderAccepted, ctx: &mut Context<Self>) {
log_error!(self.handle_order_accepted(msg.0, ctx));
}
}
#[async_trait]
impl Handler<OrderRejected> for TakerCfdActor {
impl Handler<OrderRejected> for Actor {
async fn handle(&mut self, msg: OrderRejected, _ctx: &mut Context<Self>) {
log_error!(self.handle_order_rejected(msg.0));
}
}
#[async_trait]
impl Handler<IncProtocolMsg> for TakerCfdActor {
impl Handler<IncProtocolMsg> for Actor {
async fn handle(&mut self, msg: IncProtocolMsg, _ctx: &mut Context<Self>) {
log_error!(self.handle_inc_protocol_msg(msg.0));
}
}
#[async_trait]
impl Handler<CfdSetupCompleted> for TakerCfdActor {
impl Handler<CfdSetupCompleted> for Actor {
async fn handle(&mut self, msg: CfdSetupCompleted, _ctx: &mut Context<Self>) {
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 {}

13
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<TakerCfdActor>) -> impl Future<Output = ()> {
pub fn new(read: OwnedReadHalf, cfd_actor: Address<taker_cfd::Actor>) -> impl Future<Output = ()> {
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<TakerCfdActor>) -> 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<TakerCfdActor>) -> 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");
}

Loading…
Cancel
Save