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
use async_trait::async_trait;
use candid::Nat;
use ex3_blockchain_public_types::{
    BlockHeaderResponse, CandidConsensusReport, CandidSnapshotCursor,
};
#[cfg(feature = "canister")]
use ex3_core_registry_public_types::{
    NodeProviderFullSyncRequest, NodeProviderIncrementalSyncRequest,
};
use ex3_node_types::block::CandidConsensusBlockHeader;
use ex3_node_types::{BlockHash, CandidBlockHeight};

use ex3_canister_client::{ActorResult, CanisterResult};

#[cfg(feature = "canister")]
pub mod canister_impl;
#[cfg(feature = "agent")]
pub mod client_impl;
#[cfg(feature = "mock")]
pub mod mock;

#[async_trait]
pub trait Blockchain: Send + Sync {
    async fn get_current_block_height(&self) -> CanisterResult<Option<CandidBlockHeight>>;
    async fn chain_length(&self) -> CanisterResult<Nat>;
    async fn get_genesis_block_hash(&self) -> CanisterResult<BlockHash>;
    async fn get_block_header_by_height(
        &self,
        height: CandidBlockHeight,
    ) -> CanisterResult<BlockHeaderResponse>;
    async fn get_last_block_header(&self) -> CanisterResult<Option<CandidConsensusBlockHeader>>;
    async fn submit_consensus_report(
        &self,
        consensus_report: CandidConsensusReport,
    ) -> CanisterResult<ActorResult<()>>;
    async fn get_snapshot_vault_cursor_by_height(
        &self,
        height: CandidBlockHeight,
    ) -> CanisterResult<ActorResult<CandidSnapshotCursor>>;

    #[cfg(feature = "canister")]
    async fn sync_node_provider(
        &self,
        full_sync_request: NodeProviderFullSyncRequest,
    ) -> CanisterResult<ActorResult<()>>;

    #[cfg(feature = "canister")]
    async fn accept_node_provider_update(
        &self,
        incremental_sync_request: NodeProviderIncrementalSyncRequest,
    ) -> CanisterResult<ActorResult<()>>;
}