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] 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()