diff --git a/daemon/src/maker_cfd.rs b/daemon/src/maker_cfd.rs index 33de35b..c5362e5 100644 --- a/daemon/src/maker_cfd.rs +++ b/daemon/src/maker_cfd.rs @@ -871,7 +871,7 @@ impl Actor { // TODO: code duplication maker/taker if let CfdState::OpenCommitted { .. } = cfd.state { - self.try_cet_publication(cfd).await?; + self.try_cet_publication(&mut cfd).await?; } else if let CfdState::MustRefund { .. } = cfd.state { let signed_refund_tx = cfd.refund_tx()?; let txid = self @@ -892,16 +892,18 @@ impl Actor { ); let mut conn = self.db.acquire().await?; - let cfds = load_cfds_by_oracle_event_id(attestation.id, &mut conn).await?; + let mut cfds = load_cfds_by_oracle_event_id(attestation.id, &mut conn).await?; - for mut cfd in cfds { + for (cfd, dlc) in cfds + .iter_mut() + .filter_map(|cfd| cfd.dlc().map(|dlc| (cfd, dlc))) + { if cfd .handle(CfdStateChangeEvent::OracleAttestation(Attestation::new( attestation.id, attestation.price, attestation.scalars.clone(), - cfd.dlc() - .context("No DLC available when attestation was received")?, + dlc, cfd.role(), )?))? .is_none() @@ -926,7 +928,7 @@ impl Actor { } // TODO: code duplication maker/taker - async fn try_cet_publication(&mut self, mut cfd: Cfd) -> Result<()> { + async fn try_cet_publication(&mut self, cfd: &mut Cfd) -> Result<()> { let mut conn = self.db.acquire().await?; match cfd.cet()? { diff --git a/daemon/src/taker_cfd.rs b/daemon/src/taker_cfd.rs index 928249d..f6d8666 100644 --- a/daemon/src/taker_cfd.rs +++ b/daemon/src/taker_cfd.rs @@ -587,7 +587,7 @@ impl Actor { // TODO: code duplicateion maker/taker if let CfdState::OpenCommitted { .. } = cfd.state { - self.try_cet_publication(cfd).await?; + self.try_cet_publication(&mut cfd).await?; } else if let CfdState::MustRefund { .. } = cfd.state { let signed_refund_tx = cfd.refund_tx()?; let txid = self @@ -633,16 +633,18 @@ impl Actor { ); let mut conn = self.db.acquire().await?; - let cfds = load_cfds_by_oracle_event_id(attestation.id, &mut conn).await?; + let mut cfds = load_cfds_by_oracle_event_id(attestation.id, &mut conn).await?; - for mut cfd in cfds { + for (cfd, dlc) in cfds + .iter_mut() + .filter_map(|cfd| cfd.dlc().map(|dlc| (cfd, dlc))) + { if cfd .handle(CfdStateChangeEvent::OracleAttestation(Attestation::new( attestation.id, attestation.price, attestation.scalars.clone(), - cfd.dlc() - .context("No DLC available when attestation was received")?, + dlc, cfd.role(), )?))? .is_none() @@ -667,7 +669,7 @@ impl Actor { } // TODO: code duplication maker/taker - async fn try_cet_publication(&mut self, mut cfd: Cfd) -> Result<()> { + async fn try_cet_publication(&mut self, cfd: &mut Cfd) -> Result<()> { let mut conn = self.db.acquire().await?; match cfd.cet()? {