Browse Source

Don't repeat name in module and type

fix-bad-api-calls
Thomas Eizinger 3 years ago
parent
commit
0ad9348e32
No known key found for this signature in database GPG Key ID: 651AC83A6C6C8B96
  1. 14
      daemon/src/maker.rs
  2. 36
      daemon/src/maker_cfd_actor.rs
  3. 15
      daemon/src/maker_inc_connections.rs

14
daemon/src/maker.rs

@ -1,5 +1,5 @@
use crate::auth::MAKER_USERNAME;
use crate::maker_inc_connections_actor::in_taker_messages;
use crate::maker_inc_connections::in_taker_messages;
use crate::model::TakerId;
use crate::seed::Seed;
use crate::wallet::Wallet;
@ -25,7 +25,7 @@ mod db;
mod keypair;
mod logger;
mod maker_cfd_actor;
mod maker_inc_connections_actor;
mod maker_inc_connections;
mod model;
mod routes;
mod routes_maker;
@ -171,11 +171,9 @@ async fn main() -> Result<()> {
.spawn_global();
let maker_inc_connections_address =
maker_inc_connections_actor::MakerIncConnectionsActor::new(
cfd_maker_actor_inbox.clone(),
)
.create(None)
.spawn_global();
maker_inc_connections::Actor::new(cfd_maker_actor_inbox.clone())
.create(None)
.spawn_global();
tokio::spawn({
let cfd_maker_actor_inbox = cfd_maker_actor_inbox.clone();
@ -199,7 +197,7 @@ async fn main() -> Result<()> {
tokio::spawn(out_msg_actor);
maker_inc_connections_address
.do_send_async(maker_inc_connections_actor::NewTakerOnline {
.do_send_async(maker_inc_connections::NewTakerOnline {
taker_id,
out_msg_actor_inbox,
})

36
daemon/src/maker_cfd_actor.rs

@ -3,12 +3,12 @@ use crate::db::{
insert_cfd, insert_new_cfd_state_by_order_id, insert_order, load_all_cfds,
load_cfd_by_order_id, load_order_by_id,
};
use crate::maker_inc_connections_actor::{MakerIncConnectionsActor, TakerCommand};
use crate::maker_inc_connections::TakerCommand;
use crate::model::cfd::{Cfd, CfdState, CfdStateCommon, Dlc, Order, OrderId};
use crate::model::{TakerId, Usd, WalletInfo};
use crate::wallet::Wallet;
use crate::wire::SetupMsg;
use crate::{maker_inc_connections_actor, setup_contract_actor};
use crate::{maker_inc_connections, setup_contract_actor};
use anyhow::{Context as AnyhowContext, Result};
use async_trait::async_trait;
use bdk::bitcoin::secp256k1::schnorrsig;
@ -16,7 +16,7 @@ use std::time::SystemTime;
use tokio::sync::{mpsc, watch};
use xtra::prelude::*;
pub struct Initialized(pub Address<MakerIncConnectionsActor>);
pub struct Initialized(pub Address<maker_inc_connections::Actor>);
pub struct TakeOrder {
pub taker_id: TakerId,
@ -54,7 +54,7 @@ pub struct MakerCfdActor {
cfd_feed_actor_inbox: watch::Sender<Vec<Cfd>>,
order_feed_sender: watch::Sender<Option<Order>>,
wallet_feed_sender: watch::Sender<WalletInfo>,
takers: Option<Address<MakerIncConnectionsActor>>,
takers: Option<Address<maker_inc_connections::Actor>>,
current_order_id: Option<OrderId>,
current_contract_setup: Option<mpsc::UnboundedSender<SetupMsg>>,
// TODO: Move the contract setup into a dedicated actor and send messages to that actor that
@ -105,12 +105,12 @@ impl MakerCfdActor {
// 4. Inform connected takers
self.takers()?
.do_send_async(maker_inc_connections_actor::BroadcastOrder(Some(order)))
.do_send_async(maker_inc_connections::BroadcastOrder(Some(order)))
.await?;
Ok(())
}
fn takers(&self) -> Result<&Address<MakerIncConnectionsActor>> {
fn takers(&self) -> Result<&Address<maker_inc_connections::Actor>> {
self.takers
.as_ref()
.context("Maker inc connections actor to be initialised")
@ -125,7 +125,7 @@ impl MakerCfdActor {
};
self.takers()?
.do_send_async(maker_inc_connections_actor::TakerMessage {
.do_send_async(maker_inc_connections::TakerMessage {
taker_id: msg.id,
command: TakerCommand::SendOrder {
order: current_order,
@ -203,7 +203,7 @@ impl MakerCfdActor {
}
_ => {
self.takers()?
.do_send_async(maker_inc_connections_actor::TakerMessage {
.do_send_async(maker_inc_connections::TakerMessage {
taker_id,
command: TakerCommand::NotifyInvalidOrderId { id: order_id },
})
@ -232,7 +232,7 @@ impl MakerCfdActor {
// 3. Remove current order
self.current_order_id = None;
self.takers()?
.do_send_async(maker_inc_connections_actor::BroadcastOrder(None))
.do_send_async(maker_inc_connections::BroadcastOrder(None))
.await?;
self.order_feed_sender.send(None)?;
@ -276,7 +276,7 @@ impl MakerCfdActor {
.unwrap();
self.takers()?
.do_send_async(maker_inc_connections_actor::TakerMessage {
.do_send_async(maker_inc_connections::TakerMessage {
taker_id,
command: TakerCommand::NotifyOrderAccepted { id: msg.order_id },
})
@ -285,7 +285,7 @@ impl MakerCfdActor {
.send(load_all_cfds(&mut conn).await?)?;
self.takers()?
.do_send_async(maker_inc_connections_actor::BroadcastOrder(None))
.do_send_async(maker_inc_connections::BroadcastOrder(None))
.await?;
self.current_order_id = None;
self.order_feed_sender.send(None)?;
@ -305,12 +305,10 @@ impl MakerCfdActor {
{
let inbox = self.takers()?.clone();
move |msg| {
tokio::spawn(
inbox.do_send_async(maker_inc_connections_actor::TakerMessage {
taker_id,
command: TakerCommand::OutProtocolMsg { setup_msg: msg },
}),
);
tokio::spawn(inbox.do_send_async(maker_inc_connections::TakerMessage {
taker_id,
command: TakerCommand::OutProtocolMsg { setup_msg: msg },
}));
}
},
setup_contract_actor::OwnParams::Maker(maker_params),
@ -386,7 +384,7 @@ impl MakerCfdActor {
.unwrap();
self.takers()?
.do_send_async(maker_inc_connections_actor::TakerMessage {
.do_send_async(maker_inc_connections::TakerMessage {
taker_id,
command: TakerCommand::NotifyOrderRejected { id: msg.order_id },
})
@ -397,7 +395,7 @@ impl MakerCfdActor {
// Remove order for all
self.current_order_id = None;
self.takers()?
.do_send_async(maker_inc_connections_actor::BroadcastOrder(None))
.do_send_async(maker_inc_connections::BroadcastOrder(None))
.await?;
self.order_feed_sender.send(None)?;

15
daemon/src/maker_inc_connections_actor.rs → daemon/src/maker_inc_connections.rs

@ -5,13 +5,12 @@ use crate::model::TakerId;
use crate::wire::SetupMsg;
use crate::{maker_cfd_actor, wire};
use anyhow::{Context as AnyhowContext, Result};
use async_trait::async_trait;
use futures::{Future, StreamExt};
use std::collections::HashMap;
use tokio::net::tcp::OwnedReadHalf;
use tokio::sync::mpsc;
use tokio_util::codec::{FramedRead, LengthDelimitedCodec};
use async_trait::async_trait;
use xtra::prelude::*;
type MakerToTakerSender = mpsc::UnboundedSender<wire::MakerToTaker>;
@ -49,14 +48,14 @@ impl Message for NewTakerOnline {
type Result = Result<()>;
}
pub struct MakerIncConnectionsActor {
pub struct Actor {
write_connections: HashMap<TakerId, MakerToTakerSender>,
cfd_maker_actor_address: Address<MakerCfdActor>,
}
impl Actor for MakerIncConnectionsActor {}
impl xtra::Actor for Actor {}
impl MakerIncConnectionsActor {
impl Actor {
pub fn new(cfd_maker_actor_address: Address<MakerCfdActor>) -> Self {
Self {
write_connections: HashMap::<TakerId, MakerToTakerSender>::new(),
@ -122,7 +121,7 @@ macro_rules! log_error {
}
#[async_trait]
impl Handler<BroadcastOrder> for MakerIncConnectionsActor {
impl Handler<BroadcastOrder> for Actor {
async fn handle(&mut self, msg: BroadcastOrder, _ctx: &mut Context<Self>) -> Result<()> {
log_error!(self.handle_broadcast_order(msg));
Ok(())
@ -130,7 +129,7 @@ impl Handler<BroadcastOrder> for MakerIncConnectionsActor {
}
#[async_trait]
impl Handler<TakerMessage> for MakerIncConnectionsActor {
impl Handler<TakerMessage> for Actor {
async fn handle(&mut self, msg: TakerMessage, _ctx: &mut Context<Self>) -> Result<()> {
log_error!(self.handle_taker_message(msg));
Ok(())
@ -138,7 +137,7 @@ impl Handler<TakerMessage> for MakerIncConnectionsActor {
}
#[async_trait]
impl Handler<NewTakerOnline> for MakerIncConnectionsActor {
impl Handler<NewTakerOnline> for Actor {
async fn handle(&mut self, msg: NewTakerOnline, _ctx: &mut Context<Self>) -> Result<()> {
log_error!(self.handle_new_taker_online(msg));
Ok(())
Loading…
Cancel
Save