diff --git a/daemon/src/maker_cfd.rs b/daemon/src/maker_cfd.rs index 96ddbae..7250814 100644 --- a/daemon/src/maker_cfd.rs +++ b/daemon/src/maker_cfd.rs @@ -411,7 +411,7 @@ impl Actor { async fn handle_commit(&mut self, order_id: OrderId) -> Result<()> { let mut conn = self.db.acquire().await?; - let cfd = load_cfd_by_order_id(order_id, &mut conn).await?; + let mut cfd = load_cfd_by_order_id(order_id, &mut conn).await?; let signed_commit_tx = cfd.commit_tx()?; @@ -435,12 +435,10 @@ impl Actor { let order_id = event.order_id(); let mut conn = self.db.acquire().await?; - let cfd = load_cfd_by_order_id(order_id, &mut conn).await?; + let mut cfd = load_cfd_by_order_id(order_id, &mut conn).await?; let new_state = cfd.handle(CfdStateChangeEvent::Monitor(event))?; - insert_new_cfd_state_by_order_id(order_id, new_state.clone(), &mut conn).await?; - self.cfd_feed_actor_inbox .send(load_all_cfds(&mut conn).await?)?; diff --git a/daemon/src/model/cfd.rs b/daemon/src/model/cfd.rs index 8d1bc0e..2853bfa 100644 --- a/daemon/src/model/cfd.rs +++ b/daemon/src/model/cfd.rs @@ -449,7 +449,7 @@ impl Cfd { #[allow(dead_code)] pub const CET_TIMELOCK: u32 = 12; - pub fn handle(&self, event: CfdStateChangeEvent) -> Result { + pub fn handle(&mut self, event: CfdStateChangeEvent) -> Result { use CfdState::*; // TODO: Display impl @@ -591,6 +591,8 @@ impl Cfd { } }; + self.state = new_state.clone(); + Ok(new_state) } diff --git a/daemon/src/taker_cfd.rs b/daemon/src/taker_cfd.rs index 78e83cc..f132c03 100644 --- a/daemon/src/taker_cfd.rs +++ b/daemon/src/taker_cfd.rs @@ -311,7 +311,7 @@ impl Actor { let order_id = event.order_id(); let mut conn = self.db.acquire().await?; - let cfd = load_cfd_by_order_id(order_id, &mut conn).await?; + let mut cfd = load_cfd_by_order_id(order_id, &mut conn).await?; let new_state = cfd.handle(CfdStateChangeEvent::Monitor(event))?; @@ -339,7 +339,7 @@ impl Actor { // TODO: Duplicated with maker async fn handle_commit(&mut self, order_id: OrderId) -> Result<()> { let mut conn = self.db.acquire().await?; - let cfd = load_cfd_by_order_id(order_id, &mut conn).await?; + let mut cfd = load_cfd_by_order_id(order_id, &mut conn).await?; let signed_commit_tx = cfd.commit_tx()?;