use super::{BlsShareAuth, NodeAuth, ServiceAuth, SrcLocation};
use serde::{Deserialize, Serialize};
#[allow(clippy::large_enum_variant)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub enum MsgKind {
ServiceMsg(ServiceAuth),
NodeAuthMsg(NodeAuth),
NodeBlsShareAuthMsg(BlsShareAuth),
}
impl MsgKind {
pub fn priority(&self) -> i32 {
match self {
Self::NodeBlsShareAuthMsg(_) => 1,
Self::NodeAuthMsg(_) => 0,
Self::ServiceMsg(_) => -2,
}
}
pub fn src(&self) -> SrcLocation {
match self {
Self::NodeBlsShareAuthMsg(auth) => SrcLocation::Node {
name: auth.src_name,
section_pk: auth.sig_share.public_key_set.public_key(),
},
Self::NodeAuthMsg(auth) => SrcLocation::Node {
name: crate::types::PublicKey::Ed25519(auth.public_key).into(),
section_pk: auth.section_pk,
},
Self::ServiceMsg(auth) => SrcLocation::EndUser(super::EndUser(auth.public_key.into())),
}
}
}