use std::{
fmt::{Debug, Display},
hash::Hash,
};
use datasize::DataSize;
use serde::{de::DeserializeOwned, Serialize};
pub trait NodeIdT: Clone + Display + Debug + Send + Eq + Hash + DataSize + 'static {}
impl<I> NodeIdT for I where I: Clone + Display + Debug + Send + Eq + Hash + DataSize + 'static {}
pub trait ValidatorIdT: Eq + Ord + Clone + Debug + Hash + Send + DataSize + Display {}
impl<VID> ValidatorIdT for VID where VID: Eq + Ord + Clone + Debug + Hash + Send + DataSize + Display
{}
pub trait ConsensusValueT:
Eq + Clone + Debug + Hash + Serialize + DeserializeOwned + Send + DataSize
{
fn needs_validation(&self) -> bool;
}
pub trait HashT:
Eq + Ord + Copy + Clone + DataSize + Debug + Display + Hash + Serialize + DeserializeOwned + Send
{
}
impl<H> HashT for H where
H: Eq
+ Ord
+ Copy
+ Clone
+ DataSize
+ Debug
+ Display
+ Hash
+ Serialize
+ DeserializeOwned
+ Send
{
}
pub trait ValidatorSecret: Send + DataSize {
type Hash: DataSize;
type Signature: Eq + PartialEq + Clone + Debug + Hash + Serialize + DeserializeOwned + DataSize;
fn sign(&self, hash: &Self::Hash) -> Self::Signature;
}
pub trait Context: Clone + DataSize + Debug + Eq + Ord + Hash + Send {
type ConsensusValue: ConsensusValueT;
type ValidatorId: ValidatorIdT;
type ValidatorSecret: ValidatorSecret<Hash = Self::Hash, Signature = Self::Signature>;
type Signature: Copy
+ Clone
+ Debug
+ Eq
+ Hash
+ Serialize
+ DeserializeOwned
+ Send
+ DataSize;
type Hash: HashT;
type InstanceId: HashT;
fn hash(data: &[u8]) -> Self::Hash;
fn verify_signature(
hash: &Self::Hash,
public_key: &Self::ValidatorId,
signature: &<Self::ValidatorSecret as ValidatorSecret>::Signature,
) -> bool;
}