Skip to content

Commit

Permalink
Make Trade Complete Access not self consuming
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu-maeda committed Dec 12, 2023
1 parent 4979eed commit 3a77a47
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/machine/maker/maker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::{
trade_rsp::{TradeResponse, TradeResponseBuilder, TradeResponseStatus},
};

#[derive(Clone)]
pub struct MakerAccess {
tx: mpsc::Sender<MakerRequest>,
}
Expand Down Expand Up @@ -77,7 +78,7 @@ impl MakerAccess {
rsp_rx.await.unwrap()
}

pub async fn trade_complete(self) -> Result<(), N3xbError> {
pub async fn trade_complete(&self) -> Result<(), N3xbError> {
let (rsp_tx, rsp_rx) = oneshot::channel::<Result<(), N3xbError>>();
let request = MakerRequest::TradeComplete { rsp_tx };
self.tx.send(request).await.unwrap();
Expand Down Expand Up @@ -127,7 +128,7 @@ impl MakerAccess {

pub(crate) struct Maker {
tx: mpsc::Sender<MakerRequest>,
pub task_handle: tokio::task::JoinHandle<()>,
pub(crate) task_handle: tokio::task::JoinHandle<()>,
}

impl Maker {
Expand Down
5 changes: 3 additions & 2 deletions src/machine/taker/taker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
trade_rsp::{TradeResponse, TradeResponseEnvelope},
};

#[derive(Clone)]
pub struct TakerAccess {
tx: mpsc::Sender<TakerRequest>,
}
Expand Down Expand Up @@ -47,7 +48,7 @@ impl TakerAccess {
rsp_rx.await.unwrap()
}

pub async fn trade_complete(self) -> Result<(), N3xbError> {
pub async fn trade_complete(&self) -> Result<(), N3xbError> {
let (rsp_tx, rsp_rx) = oneshot::channel::<Result<(), N3xbError>>();
let request = TakerRequest::TradeComplete { rsp_tx };
self.tx.send(request).await.unwrap();
Expand Down Expand Up @@ -91,7 +92,7 @@ impl TakerAccess {

pub(crate) struct Taker {
tx: mpsc::Sender<TakerRequest>,
pub task_handle: tokio::task::JoinHandle<()>,
pub(crate) task_handle: tokio::task::JoinHandle<()>,
}

impl Taker {
Expand Down
6 changes: 2 additions & 4 deletions src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Manager {
}

// Order Management
pub async fn new_maker(&self, order: Order) -> Result<MakerAccess, N3xbError> {
pub async fn new_maker(&self, order: Order) -> MakerAccess {
let trade_uuid = order.trade_uuid;
let maker = Maker::new(self.communicator.new_accessor(), order).await;
let maker_my_accessor = maker.new_accessor().await;
Expand All @@ -104,7 +104,7 @@ impl Manager {
let mut maker_accessors = self.maker_accessors.write().await;
maker_accessors.insert(trade_uuid, maker_my_accessor);

Ok(maker_returned_accessor)
maker_returned_accessor
}

pub async fn query_orders(
Expand Down Expand Up @@ -183,6 +183,4 @@ impl Manager {
}
Ok(())
}

// Private Functions
}
2 changes: 1 addition & 1 deletion tests/common/maker_testers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl MakerTesterActor {
async fn run(self) {
// Create and setup a Maker for a new Order
let order = self.order.clone();
let maker = self.manager.new_maker(order).await.unwrap();
let maker = self.manager.new_maker(order).await;

// Register Maker for Offer notificaitons
let (offer_notif_tx, mut offer_notif_rx) =
Expand Down

0 comments on commit 3a77a47

Please sign in to comment.