Skip to content

Commit

Permalink
update ibc-client-tendermint-cw README
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed May 10, 2024
1 parent 03f19c0 commit b21ffc6
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions ibc-clients/ics07-tendermint/cw-contract/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
# `cw-contract` crate
# `ibc-client-tendermint-cw` crate

This crate showcases a barebones CosmWasm contract implementation utilizing the `ibc-client-cw`
crate, which exposes the requisite interfaces needed to implement contracts on top of `ibc-rs`.
This crate showcases how to reuse `ibc-rs` light clients as a
[CosmWasm contract](https://github.com/cosmos/ibc/blob/main/spec/client/ics-008-wasm-client/README.md)
utilizing the `ibc-client-cw` crate.

The following template can be used to get you started:
The `ibc-client-cw` crate exposes the requisite types and traits needed to reuse
the `ibc-rs` light clients. Notably, it offers a
[`ClientType`](https://docs.rs/ibc-client-cw/latest/ibc_client_cw/api/trait.ClientType.html)
trait, which requires two associated types: `ClientState` and `ConsensusState`.
These types take any type that implements the
[`ClientStateExecution`](https://docs.rs/ibc-core/latest/ibc_core/client/context/client_state/trait.ClientStateExecution.html)
and
[`ConsensusState`](https://docs.rs/ibc-core/latest/ibc_core/client/context/consensus_state/trait.ConsensusState.html)
traits from the `ibc-core` crate.

For example, to reuse the existing
[`ibc-client-tendermint`](https://docs.rs/ibc-client-tendermint/latest/ibc_client_tendermint/):

```rs
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:

```rs
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(
Expand All @@ -39,3 +66,6 @@ pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> Result<Binary, Contract
ctx.query(msg)
}
```

The above snippets compile into a fully working CosmWasm contract implementing
Tendermint IBC light client.

0 comments on commit b21ffc6

Please sign in to comment.