From 6a9144f7a1c8076f7643d4c3ea3b853bba27f91d Mon Sep 17 00:00:00 2001 From: Lucas Soriano del Pino Date: Tue, 12 Oct 2021 13:52:24 +1100 Subject: [PATCH 1/3] Make monitor::Cet private It is only needed internally and it was giving the wrong impression when it was declared as public. --- daemon/src/monitor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon/src/monitor.rs b/daemon/src/monitor.rs index 24e6670..9417e9e 100644 --- a/daemon/src/monitor.rs +++ b/daemon/src/monitor.rs @@ -24,7 +24,7 @@ pub struct StartMonitoring { } #[derive(Clone)] -pub struct Cet { +struct Cet { txid: Txid, script: Script, range: RangeInclusive, From 380740e3127f6bd7b41a09de7c8cffdf7c7af1bf Mon Sep 17 00:00:00 2001 From: Lucas Soriano del Pino Date: Tue, 12 Oct 2021 14:02:34 +1100 Subject: [PATCH 2/3] Monitor CETs based on a script pubkey in the transaction 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. --- daemon/src/monitor.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/daemon/src/monitor.rs b/daemon/src/monitor.rs index 9417e9e..87d7115 100644 --- a/daemon/src/monitor.rs +++ b/daemon/src/monitor.rs @@ -111,7 +111,7 @@ where actor.monitor_refund_finality(¶ms,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(¶ms, cfd.order.id); actor.monitor_commit_refund_timelock(¶ms, cfd.order.id); actor.monitor_refund_finality(¶ms,cfd.order.id); @@ -121,7 +121,7 @@ where actor.monitor_refund_finality(¶ms,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(¶ms, cfd.order.id); actor.monitor_refund_finality(¶ms,cfd.order.id); } @@ -547,7 +547,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, @@ -564,7 +564,6 @@ impl MonitorParams { fn map_cets( cets: HashMap>, - script_pubkey: Script, ) -> HashMap> { cets.iter() .map(|(event_id, cets)| { @@ -576,7 +575,7 @@ fn map_cets( tx, range, n_bits, .. }| Cet { txid: tx.txid(), - script: script_pubkey.clone(), + script: tx.output[0].script_pubkey.clone(), range: range.clone(), n_bits: *n_bits, }, From 70107f4d8131663a665b7fcc01f8bf74a44f4383 Mon Sep 17 00:00:00 2001 From: Lucas Soriano del Pino Date: Tue, 12 Oct 2021 16:52:56 +1100 Subject: [PATCH 3/3] Implement From for monitor::Cet --- daemon/src/monitor.rs | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/daemon/src/monitor.rs b/daemon/src/monitor.rs index 87d7115..ce7cbb4 100644 --- a/daemon/src/monitor.rs +++ b/daemon/src/monitor.rs @@ -23,14 +23,6 @@ pub struct StartMonitoring { pub params: MonitorParams, } -#[derive(Clone)] -struct Cet { - txid: Txid, - script: Script, - range: RangeInclusive, - n_bits: usize, -} - #[derive(Clone)] pub struct MonitorParams { lock: (Txid, Descriptor), @@ -562,25 +554,33 @@ impl MonitorParams { } } +#[derive(Clone)] +struct Cet { + txid: Txid, + script: Script, + range: RangeInclusive, + n_bits: usize, +} + +impl From 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>, ) -> HashMap> { - 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: tx.output[0].script_pubkey.clone(), - range: range.clone(), - n_bits: *n_bits, - }, - ) - .collect::>(), + event_id, + cets.into_iter().map(Cet::from).collect::>(), ) }) .collect()