//! Consensus configuration, including specific consensus types like PoA use crate::{ blockchain::primitives::BlockId, fuel_tx::Input, fuel_types::{ Address, Bytes32, }, }; // Different types of consensus are represented as separate modules pub mod poa; use poa::PoAConsensus; #[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[non_exhaustive] /// The consensus related data that doesn't live on the /// header. pub enum Consensus { /// The genesis block defines the consensus rules for future blocks. Genesis(Genesis), /// Proof of authority consensus PoA(PoAConsensus), } impl Consensus { /// Retrieve the block producer address from the consensus data pub fn block_producer(&self, block_id: &BlockId) -> anyhow::Result
{ match &self { Consensus::Genesis(_) => Ok(Address::zeroed()), Consensus::PoA(poa_data) => { let public_key = poa_data .signature .recover(block_id.as_message()) .map_err(|e| anyhow::anyhow!("Can't recover public key: {:?}", e))?; let address = Input::owner(&public_key); Ok(address) } } } } impl Default for Consensus { fn default() -> Self { Consensus::PoA(Default::default()) } } /// Consensus type that a block is using #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum ConsensusType { /// Proof of authority PoA, } /// A sealed entity with consensus info. #[derive(Default, Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Sealed