Browse Source

Merge #281

281: Monitor CETs based on a script pubkey in the transaction r=luckysori a=luckysori

Fixes #238.

Instead of passing in a script which may or may not be part of a CET (because some CETs only pay to one party), we take the script pubkey from an output of the transaction itself.

Co-authored-by: Lucas Soriano del Pino <l.soriano.del.pino@gmail.com>
refactor/no-log-handler
bors[bot] 3 years ago
committed by GitHub
parent
commit
c7a21b9884
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 51
      daemon/src/monitor.rs

51
daemon/src/monitor.rs

@ -23,14 +23,6 @@ pub struct StartMonitoring {
pub params: MonitorParams,
}
#[derive(Clone)]
pub struct Cet {
txid: Txid,
script: Script,
range: RangeInclusive<u64>,
n_bits: usize,
}
#[derive(Clone)]
pub struct MonitorParams {
lock: (Txid, Descriptor<PublicKey>),
@ -111,7 +103,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.into(), cfd.order.id)?;
actor.monitor_cet_finality(map_cets(dlc.cets), 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 +113,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.into(), cfd.order.id)?;
actor.monitor_cet_finality(map_cets(dlc.cets), attestation.into(), cfd.order.id)?;
actor.monitor_commit_refund_timelock(&params, cfd.order.id);
actor.monitor_refund_finality(&params,cfd.order.id);
}
@ -547,7 +539,7 @@ impl MonitorParams {
MonitorParams {
lock: (dlc.lock.0.txid(), dlc.lock.1),
commit: (dlc.commit.0.txid(), dlc.commit.2),
cets: map_cets(dlc.cets, script_pubkey.clone()),
cets: map_cets(dlc.cets),
refund: (
dlc.refund.0.txid(),
script_pubkey,
@ -562,26 +554,33 @@ impl MonitorParams {
}
}
#[derive(Clone)]
struct Cet {
txid: Txid,
script: Script,
range: RangeInclusive<u64>,
n_bits: usize,
}
impl From<model::cfd::Cet> for Cet {
fn from(cet: model::cfd::Cet) -> Self {
Cet {
txid: cet.tx.txid(),
script: cet.tx.output[0].script_pubkey.clone(),
range: cet.range.clone(),
n_bits: cet.n_bits,
}
}
}
fn map_cets(
cets: HashMap<OracleEventId, Vec<model::cfd::Cet>>,
script_pubkey: Script,
) -> HashMap<OracleEventId, Vec<Cet>> {
cets.iter()
cets.into_iter()
.map(|(event_id, cets)| {
(
event_id.clone(),
cets.iter()
.map(
|model::cfd::Cet {
tx, range, n_bits, ..
}| Cet {
txid: tx.txid(),
script: script_pubkey.clone(),
range: range.clone(),
n_bits: *n_bits,
},
)
.collect::<Vec<_>>(),
event_id,
cets.into_iter().map(Cet::from).collect::<Vec<_>>(),
)
})
.collect()

Loading…
Cancel
Save