Trait TestHost

Source
pub trait TestHost:
    Default
    + Debug
    + Sized {
    type Block: TestBlock;
    type ClientState: Into<AnyClientState> + Debug;
    type BlockParams: Debug + Default;
    type LightClientParams: Debug + Default;

    // Required methods
    fn history(&self) -> &Vec<Self::Block>;
    fn push_block(&mut self, block: Self::Block);
    fn generate_block(
        &self,
        commitment_root: Vec<u8>,
        height: u64,
        timestamp: Timestamp,
        params: &Self::BlockParams,
    ) -> Self::Block;
    fn generate_client_state(
        &self,
        latest_height: &Height,
        params: &Self::LightClientParams,
    ) -> Self::ClientState;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn latest_height(&self) -> Height { ... }
    fn latest_block(&self) -> Self::Block { ... }
    fn get_block(&self, target_height: &Height) -> Option<Self::Block> { ... }
    fn commit_block(
        &mut self,
        commitment_root: Vec<u8>,
        block_time: Duration,
        params: &Self::BlockParams,
    ) { ... }
    fn validate(&self) -> Result<(), String> { ... }
}
Expand description

TestHost is a trait that defines the interface for a host blockchain.

Required Associated Types§

Source

type Block: TestBlock

The type of block produced by the host.

Source

type ClientState: Into<AnyClientState> + Debug

The type of client state produced by the host.

Source

type BlockParams: Debug + Default

The type of block parameter to produce a block.

Source

type LightClientParams: Debug + Default

The type of light client parameters to produce a light client state.

Required Methods§

Source

fn history(&self) -> &Vec<Self::Block>

The history of blocks produced by the host chain.

Source

fn push_block(&mut self, block: Self::Block)

Add a block to the host chain.

Source

fn generate_block( &self, commitment_root: Vec<u8>, height: u64, timestamp: Timestamp, params: &Self::BlockParams, ) -> Self::Block

Generate a block at the given height and timestamp, using the provided parameters.

Source

fn generate_client_state( &self, latest_height: &Height, params: &Self::LightClientParams, ) -> Self::ClientState

Generate a client state using the block at the given height and the provided parameters.

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true if the host chain has no blocks.

Source

fn latest_height(&self) -> Height

The latest height of the host chain.

Source

fn latest_block(&self) -> Self::Block

The latest block of the host chain.

Source

fn get_block(&self, target_height: &Height) -> Option<Self::Block>

Get the block at the given height.

Source

fn commit_block( &mut self, commitment_root: Vec<u8>, block_time: Duration, params: &Self::BlockParams, )

Commit a block with commitment root to the blockchain, by extending the history of blocks.

Source

fn validate(&self) -> Result<(), String>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§