use ibc_core_client_types::Height;
use ibc_core_host_types::error::HostError;
use ibc_core_host_types::identifiers::ClientId;
use ibc_core_host_types::path::{ClientConsensusStatePath, ClientStatePath};
use ibc_primitives::prelude::*;
use ibc_primitives::Timestamp;
use crate::client_state::{ClientStateExecution, ClientStateValidation};
use crate::consensus_state::ConsensusState;
pub trait ClientValidationContext: Sized {
type ClientStateRef: ClientStateValidation<Self>;
type ConsensusStateRef: ConsensusState;
fn client_state(&self, client_id: &ClientId) -> Result<Self::ClientStateRef, HostError>;
fn consensus_state(
&self,
client_cons_state_path: &ClientConsensusStatePath,
) -> Result<Self::ConsensusStateRef, HostError>;
fn client_update_meta(
&self,
client_id: &ClientId,
height: &Height,
) -> Result<(Timestamp, Height), HostError>;
}
pub trait ClientExecutionContext:
ClientValidationContext<ClientStateRef = Self::ClientStateMut>
{
type ClientStateMut: ClientStateExecution<Self>;
fn client_state_mut(&self, client_id: &ClientId) -> Result<Self::ClientStateMut, HostError> {
self.client_state(client_id)
}
fn store_client_state(
&mut self,
client_state_path: ClientStatePath,
client_state: Self::ClientStateRef,
) -> Result<(), HostError>;
fn store_consensus_state(
&mut self,
consensus_state_path: ClientConsensusStatePath,
consensus_state: Self::ConsensusStateRef,
) -> Result<(), HostError>;
fn delete_consensus_state(
&mut self,
consensus_state_path: ClientConsensusStatePath,
) -> Result<(), HostError>;
fn store_update_meta(
&mut self,
client_id: ClientId,
height: Height,
host_timestamp: Timestamp,
host_height: Height,
) -> Result<(), HostError>;
fn delete_update_meta(&mut self, client_id: ClientId, height: Height) -> Result<(), HostError>;
}
pub trait ExtClientValidationContext: ClientValidationContext {
fn host_timestamp(&self) -> Result<Timestamp, HostError>;
fn host_height(&self) -> Result<Height, HostError>;
fn consensus_state_heights(&self, client_id: &ClientId) -> Result<Vec<Height>, HostError>;
fn next_consensus_state(
&self,
client_id: &ClientId,
height: &Height,
) -> Result<Option<Self::ConsensusStateRef>, HostError>;
fn prev_consensus_state(
&self,
client_id: &ClientId,
height: &Height,
) -> Result<Option<Self::ConsensusStateRef>, HostError>;
}
pub trait ExtClientExecutionContext: ExtClientValidationContext + ClientExecutionContext {}
impl<T> ExtClientExecutionContext for T where T: ExtClientValidationContext + ClientExecutionContext {}
pub trait Convertible<C>: TryFrom<C> + Into<C> {}
impl<T, C> Convertible<C> for T where T: TryFrom<C> + Into<C> {}