chaincraft_rust/
consensus.rs1use crate::error::Result;
4
5pub trait Consensus: Send + Sync {
7 fn initialize(&self) -> Result<()>;
9
10 fn has_consensus(&self) -> Result<bool>;
12}
13
14pub struct ProofOfWorkConsensus {
16 difficulty: u32,
17}
18
19impl ProofOfWorkConsensus {
20 pub fn new(difficulty: u32) -> Self {
22 Self { difficulty }
23 }
24}
25
26impl Consensus for ProofOfWorkConsensus {
27 fn initialize(&self) -> Result<()> {
28 Ok(())
30 }
31
32 fn has_consensus(&self) -> Result<bool> {
33 Ok(true)
35 }
36}