diff --git a/daemon/src/db.rs b/daemon/src/db.rs index 6510938..ffa6659 100644 --- a/daemon/src/db.rs +++ b/daemon/src/db.rs @@ -592,9 +592,7 @@ mod tests { let mut cfd_1 = Cfd::dummy().insert(&mut conn).await; cfd_1.state = CfdState::Accepted { - common: CfdStateCommon { - transition_timestamp: SystemTime::now(), - }, + common: CfdStateCommon::default(), }; append_cfd_state(&cfd_1, &mut conn).await.unwrap(); @@ -607,9 +605,7 @@ mod tests { assert_eq!(vec![cfd_1.clone(), cfd_2.clone()], cfds_from_db); cfd_2.state = CfdState::Rejected { - common: CfdStateCommon { - transition_timestamp: SystemTime::now(), - }, + common: CfdStateCommon::default(), }; append_cfd_state(&cfd_2, &mut conn).await.unwrap(); diff --git a/daemon/src/housekeeping.rs b/daemon/src/housekeeping.rs index 8291e3d..cca0d32 100644 --- a/daemon/src/housekeeping.rs +++ b/daemon/src/housekeeping.rs @@ -4,7 +4,6 @@ use crate::wallet::Wallet; use anyhow::Result; use sqlx::pool::PoolConnection; use sqlx::Sqlite; -use std::time::SystemTime; pub async fn transition_non_continue_cfds_to_setup_failed( conn: &mut PoolConnection, @@ -13,9 +12,7 @@ pub async fn transition_non_continue_cfds_to_setup_failed( for cfd in cfds.iter_mut().filter(|cfd| Cfd::is_cleanup(cfd)) { cfd.state = CfdState::SetupFailed { - common: CfdStateCommon { - transition_timestamp: SystemTime::now(), - }, + common: CfdStateCommon::default(), info: format!("Was in state {} which cannot be continued.", cfd.state), }; diff --git a/daemon/src/maker_cfd.rs b/daemon/src/maker_cfd.rs index 3e1aa91..83b2300 100644 --- a/daemon/src/maker_cfd.rs +++ b/daemon/src/maker_cfd.rs @@ -401,9 +401,7 @@ impl Actor { let mut cfd = load_cfd_by_order_id(order_id, &mut conn).await?; cfd.state = CfdState::PendingOpen { - common: CfdStateCommon { - transition_timestamp: SystemTime::now(), - }, + common: CfdStateCommon::default(), dlc: dlc.clone(), attestation: None, }; @@ -444,9 +442,7 @@ impl Actor { let mut conn = self.db.acquire().await?; let mut cfd = load_cfd_by_order_id(order_id, &mut conn).await?; cfd.state = CfdState::Open { - common: CfdStateCommon { - transition_timestamp: SystemTime::now(), - }, + common: CfdStateCommon::default(), dlc: dlc.clone(), attestation: None, collaborative_close: None, @@ -568,9 +564,7 @@ impl Actor { // 3. Insert that we are in contract setup and refresh our own feed cfd.state = CfdState::ContractSetup { - common: CfdStateCommon { - transition_timestamp: SystemTime::now(), - }, + common: CfdStateCommon::default(), }; append_cfd_state(&cfd, &mut conn, &self.cfd_feed_actor_inbox).await?; @@ -656,9 +650,7 @@ impl Actor { ) -> Result<()> { // Update order in db cfd.state = CfdState::Rejected { - common: CfdStateCommon { - transition_timestamp: SystemTime::now(), - }, + common: CfdStateCommon::default(), }; append_cfd_state(&cfd, &mut conn, &self.cfd_feed_actor_inbox).await?; diff --git a/daemon/src/model/cfd.rs b/daemon/src/model/cfd.rs index 7025d63..47e9a1d 100644 --- a/daemon/src/model/cfd.rs +++ b/daemon/src/model/cfd.rs @@ -168,6 +168,14 @@ pub struct CfdStateCommon { pub transition_timestamp: SystemTime, } +impl Default for CfdStateCommon { + fn default() -> Self { + Self { + transition_timestamp: SystemTime::now(), + } + } +} + // Note: De-/Serialize with type tag to make handling on UI easier #[allow(clippy::large_enum_variant)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] diff --git a/daemon/src/taker_cfd.rs b/daemon/src/taker_cfd.rs index 49f7d1a..efd4814 100644 --- a/daemon/src/taker_cfd.rs +++ b/daemon/src/taker_cfd.rs @@ -270,9 +270,7 @@ impl Actor { let mut conn = self.db.acquire().await?; let mut cfd = load_cfd_by_order_id(order_id, &mut conn).await?; cfd.state = CfdState::ContractSetup { - common: CfdStateCommon { - transition_timestamp: SystemTime::now(), - }, + common: CfdStateCommon::default(), }; append_cfd_state(&cfd, &mut conn, &self.cfd_feed_actor_inbox).await?; @@ -323,9 +321,7 @@ impl Actor { let mut conn = self.db.acquire().await?; let mut cfd = load_cfd_by_order_id(order_id, &mut conn).await?; cfd.state = CfdState::Rejected { - common: CfdStateCommon { - transition_timestamp: SystemTime::now(), - }, + common: CfdStateCommon::default(), }; append_cfd_state(&cfd, &mut conn, &self.cfd_feed_actor_inbox).await?; @@ -477,9 +473,7 @@ impl Actor { let mut conn = self.db.acquire().await?; let mut cfd = load_cfd_by_order_id(order_id, &mut conn).await?; cfd.state = CfdState::PendingOpen { - common: CfdStateCommon { - transition_timestamp: SystemTime::now(), - }, + common: CfdStateCommon::default(), dlc: dlc.clone(), attestation: None, }; @@ -520,9 +514,7 @@ impl Actor { let mut conn = self.db.acquire().await?; let mut cfd = load_cfd_by_order_id(order_id, &mut conn).await?; cfd.state = CfdState::Open { - common: CfdStateCommon { - transition_timestamp: SystemTime::now(), - }, + common: CfdStateCommon::default(), dlc: dlc.clone(), attestation: None, collaborative_close: None,