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
use async_trait::async_trait;
use candid::{Nat, Principal};

use ex3_blockchain_public_types::{BlockHeaderResponse, BlockHeaderWithHeight, CandidBlockHeader};
use ex3_canister_client::{ActorResult, CanisterResult};
use ex3_canister_types::{BlockHash, BlockHeight};

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

#[async_trait]
pub trait Blockchain: Send + Sync {
    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: &BlockHeight,
    ) -> CanisterResult<BlockHeaderResponse>;
    async fn get_last_block_header(&self) -> CanisterResult<Option<BlockHeaderWithHeight>>;
    async fn submit_block_header(
        &self,
        block_header: &CandidBlockHeader,
    ) -> CanisterResult<ActorResult<()>>;
    #[cfg(feature = "canister")]
    async fn accept_node_provider_update(
        &self,
        providers: Vec<Principal>,
        vote_threshold: u8,
    ) -> CanisterResult<ActorResult<bool>>;
}