Sub-CoordinatorMessage -> CoordinatorMessage via From/Into

This commit is contained in:
Luke Parker 2023-07-25 17:33:05 -04:00
parent e3de64d5ff
commit a2493cfafc
No known key found for this signature in database

View file

@ -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<BlockHash> {
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;