Browse Source

Separate `Attestation` struct in model

The `Attestation` in the `oracle` module has `Desiarialization` rules that conflict with loading it from the db.
We should not reuse domain structs between modules anyway, so this was cleaned up by introducing a dedicated `model::Attestation` and mapping to `oracle::Attestation`.
temporary-fast-timelocks
Daniel Karzel 3 years ago
parent
commit
ad7a024c02
No known key found for this signature in database GPG Key ID: 30C3FC2E438ADB6E
  1. 4
      daemon/src/maker_cfd.rs
  2. 30
      daemon/src/model/cfd.rs
  3. 4
      daemon/src/monitor.rs
  4. 4
      daemon/src/oracle.rs
  5. 4
      daemon/src/taker_cfd.rs

4
daemon/src/maker_cfd.rs

@ -816,7 +816,9 @@ impl Actor {
let cfds = load_cfds_by_oracle_event_id(attestation.id.clone(), &mut conn).await?;
for mut cfd in cfds {
cfd.handle(CfdStateChangeEvent::OracleAttestation(attestation.clone()))?;
cfd.handle(CfdStateChangeEvent::OracleAttestation(
attestation.clone().into(),
))?;
insert_new_cfd_state_by_order_id(cfd.order.id, cfd.state.clone(), &mut conn).await?;
self.try_cet_publication(cfd).await?;

30
daemon/src/model/cfd.rs

@ -1,6 +1,5 @@
use crate::model::{Leverage, OracleEventId, Percent, Position, TakerId, TradingPair, Usd};
use crate::monitor;
use crate::oracle::Attestation;
use crate::{monitor, oracle};
use anyhow::{bail, Context, Result};
use bdk::bitcoin::secp256k1::{SecretKey, Signature};
use bdk::bitcoin::{Address, Amount, PublicKey, Script, SignedAmount, Transaction, Txid};
@ -282,6 +281,33 @@ pub enum CfdState {
},
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Attestation {
pub id: OracleEventId,
pub price: u64,
pub scalars: Vec<SecretKey>,
}
impl From<oracle::Attestation> for Attestation {
fn from(attestation: oracle::Attestation) -> Self {
Attestation {
id: attestation.id,
price: attestation.price,
scalars: attestation.scalars,
}
}
}
impl From<Attestation> for oracle::Attestation {
fn from(attestation: Attestation) -> oracle::Attestation {
oracle::Attestation {
id: attestation.id,
price: attestation.price,
scalars: attestation.scalars,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type", content = "payload")]
pub enum CetStatus {

4
daemon/src/monitor.rs

@ -111,7 +111,7 @@ where
actor.monitor_refund_finality(&params,cfd.order.id);
}
CetStatus::OracleSigned(attestation) => {
actor.monitor_cet_finality(map_cets(dlc.cets, dlc.maker_address.script_pubkey()), attestation, cfd.order.id)?;
actor.monitor_cet_finality(map_cets(dlc.cets, dlc.maker_address.script_pubkey()), attestation.into(), cfd.order.id)?;
actor.monitor_commit_cet_timelock(&params, cfd.order.id);
actor.monitor_commit_refund_timelock(&params, cfd.order.id);
actor.monitor_refund_finality(&params,cfd.order.id);
@ -121,7 +121,7 @@ where
actor.monitor_refund_finality(&params,cfd.order.id);
}
CetStatus::Ready(attestation) => {
actor.monitor_cet_finality(map_cets(dlc.cets, dlc.maker_address.script_pubkey()), attestation, cfd.order.id)?;
actor.monitor_cet_finality(map_cets(dlc.cets, dlc.maker_address.script_pubkey()), attestation.into(), cfd.order.id)?;
actor.monitor_commit_refund_timelock(&params, cfd.order.id);
actor.monitor_refund_finality(&params,cfd.order.id);
}

4
daemon/src/oracle.rs

@ -10,7 +10,7 @@ use reqwest::StatusCode;
use rocket::time::format_description::FormatItem;
use rocket::time::macros::format_description;
use rocket::time::{Duration, OffsetDateTime, Time};
use serde::{Deserialize, Serialize};
use serde::Deserialize;
use std::collections::{HashMap, HashSet};
const OLIVIA_EVENT_TIME_FORMAT: &[FormatItem] =
@ -277,7 +277,7 @@ impl From<Announcement> for cfd_protocol::Announcement {
// TODO: Implement real deserialization once price attestation is
// implemented in `olivia`
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[derive(Debug, Clone, Deserialize, PartialEq)]
#[serde(try_from = "olivia_api::Response")]
pub struct Attestation {
pub id: OracleEventId,

4
daemon/src/taker_cfd.rs

@ -597,7 +597,9 @@ impl Actor {
let cfds = load_cfds_by_oracle_event_id(attestation.id.clone(), &mut conn).await?;
for mut cfd in cfds {
cfd.handle(CfdStateChangeEvent::OracleAttestation(attestation.clone()))?;
cfd.handle(CfdStateChangeEvent::OracleAttestation(
attestation.clone().into(),
))?;
insert_new_cfd_state_by_order_id(cfd.order.id, cfd.state.clone(), &mut conn).await?;
self.try_cet_publication(cfd).await?;

Loading…
Cancel
Save