use super::{plain_message::PlainMessage, section::NodeState, signed::Signed};
use crate::{MessageId, SectionAuthorityProvider};
use ed25519_dalek::{PublicKey, Signature};
use hex_fmt::HexFmt;
use secured_linked_list::SecuredLinkedList;
use serde::{Deserialize, Serialize};
use std::{
borrow::Borrow,
collections::BTreeSet,
fmt::{self, Debug, Formatter},
};
use threshold_crypto::PublicKey as BlsPublicKey;
use xor_name::{Prefix, XorName};
pub type Digest256 = [u8; 32];
#[derive(Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct DkgKey {
pub hash: Digest256,
pub generation: u64,
}
impl Debug for DkgKey {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "DkgKey({:10}/{})", HexFmt(&self.hash), self.generation)
}
}
#[derive(Copy, Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
pub struct DkgFailureSigned {
pub public_key: PublicKey,
pub signature: Signature,
}
#[derive(Default, Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
pub struct DkgFailureSignedSet {
pub signeds: Vec<DkgFailureSigned>,
pub non_participants: BTreeSet<XorName>,
}
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize, Deserialize)]
pub struct SectionSigned<T: Serialize> {
pub value: T,
pub signed: Signed,
}
impl<T> Borrow<Prefix> for SectionSigned<T>
where
T: Borrow<Prefix> + Serialize,
{
fn borrow(&self) -> &Prefix {
self.value.borrow()
}
}
#[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
#[allow(clippy::large_enum_variant)]
pub enum Proposal {
Online {
node_state: NodeState,
previous_name: Option<XorName>,
destination_key: Option<BlsPublicKey>,
},
Offline(NodeState),
SectionInfo(SectionAuthorityProvider),
OurElders(SectionSigned<SectionAuthorityProvider>),
AccumulateAtSrc {
message: Box<PlainMessage>,
proof_chain: SecuredLinkedList,
},
JoinsAllowed((MessageId, bool)),
}