use core::time::Duration;
use ibc_core_channel_types::channel::ChannelEnd;
use ibc_core_channel_types::commitment::{AcknowledgementCommitment, PacketCommitment};
use ibc_core_channel_types::packet::Receipt;
use ibc_core_client_context::prelude::*;
use ibc_core_client_types::Height;
use ibc_core_commitment_types::commitment::CommitmentPrefix;
use ibc_core_connection_types::version::{pick_version, Version as ConnectionVersion};
use ibc_core_connection_types::ConnectionEnd;
use ibc_core_handler_types::events::IbcEvent;
use ibc_core_host_types::error::HostError;
use ibc_core_host_types::identifiers::{ConnectionId, Sequence};
use ibc_core_host_types::path::{
AckPath, ChannelEndPath, ClientConnectionPath, CommitmentPath, ConnectionPath, ReceiptPath,
SeqAckPath, SeqRecvPath, SeqSendPath,
};
use ibc_primitives::prelude::*;
use ibc_primitives::{Signer, Timestamp};
use crate::utils::calculate_block_delay;
pub trait ValidationContext {
type V: ClientValidationContext;
type HostClientState: ClientStateValidation<Self::V>;
type HostConsensusState: ConsensusState;
fn get_client_validation_context(&self) -> &Self::V;
fn host_height(&self) -> Result<Height, HostError>;
fn host_timestamp(&self) -> Result<Timestamp, HostError>;
fn host_consensus_state(&self, height: &Height) -> Result<Self::HostConsensusState, HostError>;
fn client_counter(&self) -> Result<u64, HostError>;
fn connection_end(&self, conn_id: &ConnectionId) -> Result<ConnectionEnd, HostError>;
fn validate_self_client(
&self,
client_state_of_host_on_counterparty: Self::HostClientState,
) -> Result<(), HostError>;
fn commitment_prefix(&self) -> CommitmentPrefix;
fn connection_counter(&self) -> Result<u64, HostError>;
fn get_compatible_versions(&self) -> Vec<ConnectionVersion> {
ConnectionVersion::compatibles()
}
fn pick_version(
&self,
counterparty_candidate_versions: &[ConnectionVersion],
) -> Result<ConnectionVersion, HostError> {
pick_version(
&self.get_compatible_versions(),
counterparty_candidate_versions,
)
.map_err(HostError::missing_state)
}
fn channel_end(&self, channel_end_path: &ChannelEndPath) -> Result<ChannelEnd, HostError>;
fn get_next_sequence_send(&self, seq_send_path: &SeqSendPath) -> Result<Sequence, HostError>;
fn get_next_sequence_recv(&self, seq_recv_path: &SeqRecvPath) -> Result<Sequence, HostError>;
fn get_next_sequence_ack(&self, seq_ack_path: &SeqAckPath) -> Result<Sequence, HostError>;
fn get_packet_commitment(
&self,
commitment_path: &CommitmentPath,
) -> Result<PacketCommitment, HostError>;
fn get_packet_receipt(&self, receipt_path: &ReceiptPath) -> Result<Receipt, HostError>;
fn get_packet_acknowledgement(
&self,
ack_path: &AckPath,
) -> Result<AcknowledgementCommitment, HostError>;
fn channel_counter(&self) -> Result<u64, HostError>;
fn max_expected_time_per_block(&self) -> Duration;
fn block_delay(&self, delay_period_time: &Duration) -> u64 {
calculate_block_delay(delay_period_time, &self.max_expected_time_per_block())
}
fn validate_message_signer(&self, signer: &Signer) -> Result<(), HostError>;
}
pub trait ExecutionContext: ValidationContext {
type E: ClientExecutionContext;
fn get_client_execution_context(&mut self) -> &mut Self::E;
fn increase_client_counter(&mut self) -> Result<(), HostError>;
fn store_connection(
&mut self,
connection_path: &ConnectionPath,
connection_end: ConnectionEnd,
) -> Result<(), HostError>;
fn store_connection_to_client(
&mut self,
client_connection_path: &ClientConnectionPath,
conn_id: ConnectionId,
) -> Result<(), HostError>;
fn increase_connection_counter(&mut self) -> Result<(), HostError>;
fn store_packet_commitment(
&mut self,
commitment_path: &CommitmentPath,
commitment: PacketCommitment,
) -> Result<(), HostError>;
fn delete_packet_commitment(
&mut self,
commitment_path: &CommitmentPath,
) -> Result<(), HostError>;
fn store_packet_receipt(
&mut self,
receipt_path: &ReceiptPath,
receipt: Receipt,
) -> Result<(), HostError>;
fn store_packet_acknowledgement(
&mut self,
ack_path: &AckPath,
ack_commitment: AcknowledgementCommitment,
) -> Result<(), HostError>;
fn delete_packet_acknowledgement(&mut self, ack_path: &AckPath) -> Result<(), HostError>;
fn store_channel(
&mut self,
channel_end_path: &ChannelEndPath,
channel_end: ChannelEnd,
) -> Result<(), HostError>;
fn store_next_sequence_send(
&mut self,
seq_send_path: &SeqSendPath,
seq: Sequence,
) -> Result<(), HostError>;
fn store_next_sequence_recv(
&mut self,
seq_recv_path: &SeqRecvPath,
seq: Sequence,
) -> Result<(), HostError>;
fn store_next_sequence_ack(
&mut self,
seq_ack_path: &SeqAckPath,
seq: Sequence,
) -> Result<(), HostError>;
fn increase_channel_counter(&mut self) -> Result<(), HostError>;
fn emit_ibc_event(&mut self, event: IbcEvent) -> Result<(), HostError>;
fn log_message(&mut self, message: String) -> Result<(), HostError>;
}
pub type ClientStateRef<Ctx> =
<<Ctx as ValidationContext>::V as ClientValidationContext>::ClientStateRef;
pub type ClientStateMut<Ctx> =
<<Ctx as ExecutionContext>::E as ClientExecutionContext>::ClientStateMut;
pub type ConsensusStateRef<Ctx> =
<<Ctx as ValidationContext>::V as ClientValidationContext>::ConsensusStateRef;