#cosmwasm #ibc #tendermint #light-client #ics-07

no-std ibc-client-tendermint-cw

Contains the implementation of the ICS-07 Tendermint Client logic as a CosmWasm contract. It leverages the ibc-client-cw crate to integrate the Tendermint light client into a CosmWasm contract

5 releases (breaking)

new 0.56.0 Nov 15, 2024
0.55.0 Oct 17, 2024
0.54.0 Aug 13, 2024
0.53.0 May 14, 2024
0.52.0 Apr 26, 2024

#5 in #light-client

Download history 161/week @ 2024-07-20 36/week @ 2024-07-27 7/week @ 2024-08-03 110/week @ 2024-08-10 11/week @ 2024-08-17 11/week @ 2024-09-14 16/week @ 2024-09-21 4/week @ 2024-09-28 149/week @ 2024-10-12 25/week @ 2024-10-19 1/week @ 2024-10-26 2/week @ 2024-11-02

177 downloads per month

Apache-2.0

67KB
1.5K SLoC

ibc-client-tendermint-cw crate

This crate showcases how to reuse an ibc-rs light client as a CosmWasm contract utilizing the ibc-client-cw crate.

The ibc-client-cw crate exposes the requisite types and traits needed to reuse the ibc-rs light clients. Notably, it offers a ClientType trait, which requires two associated types: ClientState and ConsensusState. These types take any type that implement the ClientStateExecution and ConsensusState traits from the ibc-core crate.

For example, to reuse the existing ibc-client-tendermint:

use ibc_client_cw::api::ClientType;
use ibc_client_tendermint::client_state::ClientState;
use ibc_client_tendermint::consensus_state::ConsensusState;

#[derive(Clone, Debug)]
pub struct TendermintClient;

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

Once the ClientType trait is implemented, the ibc-client-cw crate can be used to complete the entry points for the CosmWasm contract:

use cosmwasm_std::{entry_point, Binary, Deps, DepsMut, Env, MessageInfo, Response};
use ibc_client_cw::context::Context;
use ibc_client_cw::types::{ContractError, InstantiateMsg, QueryMsg, SudoMsg};

pub type TendermintContext<'a> = Context<'a, TendermintClient>;

#[entry_point]
pub fn instantiate(
    deps: DepsMut<'_>,
    env: Env,
    _info: MessageInfo,
    msg: InstantiateMsg,
) -> Result<Response, ContractError> {
    let mut ctx = TendermintContext::new_mut(deps, env)?;
    let data = ctx.instantiate(msg)?;
    Ok(Response::default().set_data(data))
}

#[entry_point]
pub fn sudo(deps: DepsMut<'_>, env: Env, msg: SudoMsg) -> Result<Response, ContractError> {
    let mut ctx = TendermintContext::new_mut(deps, env)?;
    let data = ctx.sudo(msg)?;
    Ok(Response::default().set_data(data))
}

#[entry_point]
pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> Result<Binary, ContractError> {
    let ctx = TendermintContext::new_ref(deps, env)?;
    ctx.query(msg)
}

The above snippets compile into a fully working CosmWasm contract that implements the Tendermint IBC light client.

Dependencies

~25MB
~530K SLoC