Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CW client extension traits #7

Merged
merged 10 commits into from
Jan 27, 2025
35 changes: 35 additions & 0 deletions ibc-clients/cw-context/src/context/client_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! traits for the `Context` type.
use core::fmt::Display;

use cosmwasm_std::{Checksum, Deps, DepsMut};
use ibc_client_wasm_types::client_state::ClientState as WasmClientState;
use ibc_client_wasm_types::consensus_state::ConsensusState as WasmConsensusState;
use ibc_core::client::context::{ClientExecutionContext, ClientValidationContext};
Expand Down Expand Up @@ -195,3 +196,37 @@ where
Ok(())
}
}

pub trait CwClientValidation<'a>: ClientValidationContext {
fn deps(&self) -> Option<&Deps<'a>>;
fn deps_mut(&mut self) -> Option<&mut DepsMut<'a>>;
fn checksum(&self, data: &[u8]) -> Checksum;
}

pub trait CwClientExecution<'a>: CwClientValidation<'a> + ClientExecutionContext {}

impl<'a, C: ClientType<'a>> CwClientValidation<'a> for Context<'a, C>
where
<C::ClientState as TryFrom<Any>>::Error: Display,
<C::ConsensusState as TryFrom<Any>>::Error: Display,
{
fn deps(&self) -> Option<&Deps<'a>> {
self.deps.as_ref()
}

fn deps_mut(&mut self) -> Option<&mut DepsMut<'a>> {
self.deps_mut.as_mut()
}

fn checksum(&self, data: &[u8]) -> Checksum {
Checksum::generate(data)
}
}

impl<'a, C> CwClientExecution<'a> for Context<'a, C>
where
C: ClientType<'a>,
<C::ClientState as TryFrom<Any>>::Error: Display,
<C::ConsensusState as TryFrom<Any>>::Error: Display,
{
}
2 changes: 1 addition & 1 deletion ibc-clients/ics07-tendermint/src/client_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ibc_client_tendermint::consensus_state::ConsensusState;
#[derive(Clone, Debug)]
pub struct TendermintClient;

impl<'a> ClientType<'a> for TendermintClient {
impl ClientType<'_> for TendermintClient {
type ClientState = ClientState;
type ConsensusState = ConsensusState;
}
Loading