1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::{
    database::Database,
    service::{
        adapters::{
            MaybeRelayerAdapter,
            VerifierAdapter,
        },
        Config,
    },
};
use fuel_core_consensus_module::block_verifier::{
    config::Config as VerifierConfig,
    Verifier,
};
use fuel_core_producer::ports::BlockProducerDatabase;
use fuel_core_storage::{
    tables::FuelBlocks,
    Result as StorageResult,
    StorageAsRef,
};
use fuel_core_types::{
    blockchain::{
        header::BlockHeader,
        primitives::BlockHeight,
    },
    fuel_tx::Bytes32,
};
use std::sync::Arc;

pub mod poa;

impl VerifierAdapter {
    pub fn new(
        config: &Config,
        database: Database,
        relayer: MaybeRelayerAdapter,
    ) -> Self {
        let config = VerifierConfig::new(
            config.chain_conf.clone(),
            config.manual_blocks_enabled,
            config.verifier.clone(),
        );
        Self {
            block_verifier: Arc::new(Verifier::new(config, database, relayer)),
        }
    }
}

impl fuel_core_poa::ports::Database for Database {
    fn block_header(&self, height: &BlockHeight) -> StorageResult<BlockHeader> {
        Ok(self.get_block(height)?.header().clone())
    }

    fn block_header_merkle_root(&self, height: &BlockHeight) -> StorageResult<Bytes32> {
        self.storage::<FuelBlocks>().root(height).map(Into::into)
    }
}