diff --git a/daemon/src/db.rs b/daemon/src/db.rs index cf96ac8..7be7918 100644 --- a/daemon/src/db.rs +++ b/daemon/src/db.rs @@ -163,7 +163,7 @@ pub async fn insert_cfd(cfd: Cfd, conn: &mut PoolConnection) -> anyhow:: #[allow(dead_code)] pub async fn insert_new_cfd_state_by_order_id( order_id: OrderId, - new_state: CfdState, + new_state: &CfdState, conn: &mut PoolConnection, ) -> anyhow::Result<()> { let cfd_id = load_cfd_id_by_order_uuid(order_id, conn).await?; @@ -171,7 +171,7 @@ pub async fn insert_new_cfd_state_by_order_id( .await .context("loading latest state failed")?; - if mem::discriminant(&latest_cfd_state_in_db) == mem::discriminant(&new_state) { + if mem::discriminant(&latest_cfd_state_in_db) == mem::discriminant(new_state) { // Since we have states where we add information this happens quite frequently tracing::trace!( "Same state transition for cfd with order_id {}: {}", @@ -180,7 +180,7 @@ pub async fn insert_new_cfd_state_by_order_id( ); } - let cfd_state = serde_json::to_string(&new_state)?; + let cfd_state = serde_json::to_string(new_state)?; sqlx::query!( r#" @@ -637,7 +637,7 @@ mod tests { transition_timestamp: SystemTime::now(), }, }; - insert_new_cfd_state_by_order_id(cfd.order.id, cfd.state.clone(), &mut conn) + insert_new_cfd_state_by_order_id(cfd.order.id, &cfd.state, &mut conn) .await .unwrap(); diff --git a/daemon/src/housekeeping.rs b/daemon/src/housekeeping.rs index 2a4a51c..db43c80 100644 --- a/daemon/src/housekeeping.rs +++ b/daemon/src/housekeeping.rs @@ -14,7 +14,7 @@ pub async fn transition_non_continue_cfds_to_setup_failed( for cfd in cfds.iter().filter(|cfd| Cfd::is_cleanup(cfd)) { insert_new_cfd_state_by_order_id( cfd.order.id, - CfdState::SetupFailed { + &CfdState::SetupFailed { common: CfdStateCommon { transition_timestamp: SystemTime::now(), }, diff --git a/daemon/src/maker_cfd.rs b/daemon/src/maker_cfd.rs index 20aae7f..aa80248 100644 --- a/daemon/src/maker_cfd.rs +++ b/daemon/src/maker_cfd.rs @@ -306,7 +306,7 @@ impl Actor { cfd.handle(CfdStateChangeEvent::ProposalSigned( TimestampedTransaction::new(tx.clone(), dlc.script_pubkey_for(cfd.role())), ))?; - insert_new_cfd_state_by_order_id(cfd.order.id, cfd.state.clone(), &mut conn).await?; + insert_new_cfd_state_by_order_id(cfd.order.id, &cfd.state, &mut conn).await?; let spend_tx = dlc.finalize_spend_transaction((tx, sig_maker), sig_taker)?; @@ -321,7 +321,7 @@ impl Actor { spend_tx, dlc.script_pubkey_for(cfd.role()), )))?; - insert_new_cfd_state_by_order_id(cfd.order.id, cfd.state, &mut conn).await?; + insert_new_cfd_state_by_order_id(cfd.order.id, &cfd.state, &mut conn).await?; self.current_agreed_proposals .remove(&order_id) @@ -421,7 +421,7 @@ impl Actor { insert_new_cfd_state_by_order_id( order_id, - CfdState::PendingOpen { + &CfdState::PendingOpen { common: CfdStateCommon { transition_timestamp: SystemTime::now(), }, @@ -467,7 +467,7 @@ impl Actor { let mut conn = self.db.acquire().await?; insert_new_cfd_state_by_order_id( order_id, - CfdState::Open { + &CfdState::Open { common: CfdStateCommon { transition_timestamp: SystemTime::now(), }, @@ -576,7 +576,7 @@ impl Actor { insert_new_cfd_state_by_order_id( order_id, - CfdState::ContractSetup { + &CfdState::ContractSetup { common: CfdStateCommon { transition_timestamp: SystemTime::now(), }, @@ -660,7 +660,7 @@ impl Actor { // Update order in db insert_new_cfd_state_by_order_id( order_id, - CfdState::Rejected { + &CfdState::Rejected { common: CfdStateCommon { transition_timestamp: SystemTime::now(), }, @@ -703,7 +703,7 @@ impl Actor { tracing::info!("Commit transaction published on chain: {}", txid); if let Some(new_state) = cfd.handle(CfdStateChangeEvent::CommitTxSent)? { - insert_new_cfd_state_by_order_id(cfd.order.id, new_state, &mut conn).await?; + insert_new_cfd_state_by_order_id(cfd.order.id, &new_state, &mut conn).await?; } self.cfd_feed_actor_inbox @@ -876,7 +876,7 @@ impl Actor { return Ok(()); } - insert_new_cfd_state_by_order_id(order_id, cfd.state.clone(), &mut conn).await?; + insert_new_cfd_state_by_order_id(order_id, &cfd.state, &mut conn).await?; self.cfd_feed_actor_inbox .send(load_all_cfds(&mut conn).await?)?; @@ -926,7 +926,7 @@ impl Actor { continue; } - insert_new_cfd_state_by_order_id(cfd.order.id, cfd.state.clone(), &mut conn).await?; + insert_new_cfd_state_by_order_id(cfd.order.id, &cfd.state, &mut conn).await?; self.cfd_feed_actor_inbox .send(load_all_cfds(&mut conn).await?)?; @@ -952,8 +952,7 @@ impl Actor { bail!("If we can get the CET we should be able to transition") } - insert_new_cfd_state_by_order_id(cfd.order.id, cfd.state.clone(), &mut conn) - .await?; + insert_new_cfd_state_by_order_id(cfd.order.id, &cfd.state, &mut conn).await?; self.cfd_feed_actor_inbox .send(load_all_cfds(&mut conn).await?)?; diff --git a/daemon/src/taker_cfd.rs b/daemon/src/taker_cfd.rs index c9a0de1..5870670 100644 --- a/daemon/src/taker_cfd.rs +++ b/daemon/src/taker_cfd.rs @@ -273,7 +273,7 @@ impl Actor { let mut conn = self.db.acquire().await?; insert_new_cfd_state_by_order_id( order_id, - CfdState::ContractSetup { + &CfdState::ContractSetup { common: CfdStateCommon { transition_timestamp: SystemTime::now(), }, @@ -332,7 +332,7 @@ impl Actor { let mut conn = self.db.acquire().await?; insert_new_cfd_state_by_order_id( order_id, - CfdState::Rejected { + &CfdState::Rejected { common: CfdStateCommon { transition_timestamp: SystemTime::now(), }, @@ -372,7 +372,7 @@ impl Actor { cfd.handle(CfdStateChangeEvent::ProposalSigned( TimestampedTransaction::new(tx, dlc.script_pubkey_for(cfd.role())), ))?; - insert_new_cfd_state_by_order_id(cfd.order.id, cfd.state, &mut conn).await?; + insert_new_cfd_state_by_order_id(cfd.order.id, &cfd.state, &mut conn).await?; self.cfd_feed_actor_inbox .send(load_all_cfds(&mut conn).await?)?; @@ -501,7 +501,7 @@ impl Actor { insert_new_cfd_state_by_order_id( order_id, - CfdState::PendingOpen { + &CfdState::PendingOpen { common: CfdStateCommon { transition_timestamp: SystemTime::now(), }, @@ -547,7 +547,7 @@ impl Actor { let mut conn = self.db.acquire().await?; insert_new_cfd_state_by_order_id( order_id, - CfdState::Open { + &CfdState::Open { common: CfdStateCommon { transition_timestamp: SystemTime::now(), }, @@ -586,7 +586,7 @@ impl Actor { return Ok(()); } - insert_new_cfd_state_by_order_id(order_id, cfd.state.clone(), &mut conn).await?; + insert_new_cfd_state_by_order_id(order_id, &cfd.state, &mut conn).await?; self.cfd_feed_actor_inbox .send(load_all_cfds(&mut conn).await?)?; @@ -623,7 +623,7 @@ impl Actor { bail!("If we can get the commit tx we should be able to transition") } - insert_new_cfd_state_by_order_id(cfd.order.id, cfd.state.clone(), &mut conn).await?; + insert_new_cfd_state_by_order_id(cfd.order.id, &cfd.state, &mut conn).await?; self.cfd_feed_actor_inbox .send(load_all_cfds(&mut conn).await?)?; @@ -661,7 +661,7 @@ impl Actor { continue; } - insert_new_cfd_state_by_order_id(cfd.order.id, cfd.state.clone(), &mut conn).await?; + insert_new_cfd_state_by_order_id(cfd.order.id, &cfd.state, &mut conn).await?; self.cfd_feed_actor_inbox .send(load_all_cfds(&mut conn).await?)?; @@ -687,8 +687,7 @@ impl Actor { bail!("If we can get the CET we should be able to transition") } - insert_new_cfd_state_by_order_id(cfd.order.id, cfd.state.clone(), &mut conn) - .await?; + insert_new_cfd_state_by_order_id(cfd.order.id, &cfd.state, &mut conn).await?; self.cfd_feed_actor_inbox .send(load_all_cfds(&mut conn).await?)?;