From a2493cfafcfcaea90a588f8bb0fa4470df1cc129 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Tue, 25 Jul 2023 17:33:05 -0400 Subject: [PATCH] Sub-CoordinatorMessage -> CoordinatorMessage via From/Into --- processor/messages/src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/processor/messages/src/lib.rs b/processor/messages/src/lib.rs index b6c25597..ea1cadbd 100644 --- a/processor/messages/src/lib.rs +++ b/processor/messages/src/lib.rs @@ -175,6 +175,16 @@ pub mod substrate { } } +macro_rules! impl_from { + ($from: ident, $to: ident, $via: ident) => { + impl From<$from::$to> for $to { + fn from(msg: $from::$to) -> $to { + $to::$via(msg) + } + } + }; +} + #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] pub enum CoordinatorMessage { KeyGen(key_gen::CoordinatorMessage), @@ -183,6 +193,11 @@ pub enum CoordinatorMessage { Substrate(substrate::CoordinatorMessage), } +impl_from!(key_gen, CoordinatorMessage, KeyGen); +impl_from!(sign, CoordinatorMessage, Sign); +impl_from!(coordinator, CoordinatorMessage, Coordinator); +impl_from!(substrate, CoordinatorMessage, Substrate); + impl CoordinatorMessage { pub fn required_block(&self) -> Option { let required = match self { @@ -209,6 +224,13 @@ pub enum ProcessorMessage { Substrate(substrate::ProcessorMessage), } +impl_from!(key_gen, ProcessorMessage, KeyGen); +impl_from!(sign, ProcessorMessage, Sign); +impl_from!(coordinator, ProcessorMessage, Coordinator); +impl_from!(substrate, ProcessorMessage, Substrate); + +// Intent generation code + const COORDINATOR_UID: u8 = 0; const PROCESSSOR_UID: u8 = 1;