Skip to content

Commit

Permalink
remove ChainHandle deps in ChannelHandshakePayloadBuilder p1
Browse files Browse the repository at this point in the history
  • Loading branch information
thaodt committed Apr 2, 2024
1 parent 25d0200 commit ed6a175
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use hermes_relayer_components::chain::traits::payload_builders::channel_handshake::ChannelHandshakePayloadBuilder;
use hermes_relayer_components::chain::traits::types::channel::HasChannelHandshakePayloadTypes;
use hermes_relayer_components::chain::traits::queries::channel::CanQueryChannel;
use hermes_relayer_components::chain::traits::types::channel::{HasChannelEndsType, HasChannelHandshakePayloadTypes};
use hermes_relayer_components::chain::traits::types::client_state::HasClientStateType;
use hermes_relayer_components::chain::traits::types::ibc::HasIbcChainTypes;
use ibc_relayer::chain::handle::ChainHandle;
Expand All @@ -24,7 +25,9 @@ where
ChannelOpenConfirmPayload = CosmosChannelOpenConfirmPayload,
> + HasIbcChainTypes<Counterparty, Height = Height, PortId = PortId, ChannelId = ChannelId>
+ HasClientStateType<Counterparty>
+ HasBlockingChainHandle,
+ HasBlockingChainHandle
// + HasChannelEndsType<Counterparty>
// + CanQueryChannel<Counterparty>,
{
async fn build_channel_open_try_payload(
chain: &Chain,
Expand All @@ -37,6 +40,7 @@ where
let port_id = port_id.clone();
let channel_id = channel_id.clone();

//TODO: replace this
chain
.with_blocking_chain_handle(move |chain_handle| {
let (channel_end, _) = chain_handle
Expand Down
33 changes: 33 additions & 0 deletions crates/cosmos/cosmos-chain-components/src/impls/queries/channel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// use cgp_core::prelude::*;
// use cgp_core::CanRaiseError;
use hermes_relayer_components::chain::traits::queries::channel::ChannelBytesQuerier;
use hermes_relayer_components::chain::traits::types::ibc::HasIbcChainTypes;
use ibc_relayer_types::core::ics24_host::identifier::{PortId, ChannelId};
use ibc_relayer_types::Height;

use crate::traits::abci_query::CanQueryAbci;

pub struct QueryCosmosChannelFromAbci;

pub const IBC_QUERY_PATH: &str = "store/ibc/key";

impl<Chain, Counterparty> ChannelBytesQuerier<Chain, Counterparty>
for QueryCosmosChannelFromAbci
where
Chain: HasIbcChainTypes<Counterparty, PortId = PortId, ChannelId = ChannelId, Height = Height> + CanQueryAbci,
{
async fn query_channel_bytes(
chain: &Chain,
port_id: &PortId,
channel_id: &ChannelId,
height: &Height,
) -> Result<Vec<u8>, Chain::Error> {
let channel_ends_path = format!("channelEnds/ports/{port_id}/channels/{channel_id}");

let channel_bytes = chain
.query_abci(IBC_QUERY_PATH, channel_ends_path.as_bytes(), height)
.await?;

Ok(channel_bytes)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ pub mod send_packets;
pub mod unreceived_acks;
pub mod unreceived_packet;
pub mod write_ack_event;
pub mod channel;
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ pub struct CosmosChannelOpenConfirmPayload {
pub update_height: Height,
pub proof_ack: CommitmentProofBytes,
}


pub struct CosmosChannelEnd {
pub port_id: String,
pub channel_id: String,
pub update_height: Height,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use core::marker::PhantomData;

use cgp_core::{DelegateComponent, HasErrorType};

use crate::chain::traits::{queries::channel::ChannelQuerier, types::{channel::HasChannelEndsType, ibc::HasIbcChainTypes}};

pub struct DelegateQueryChannel<Components>(pub PhantomData<Components>);

impl<Chain, Counterparty, Components, Delegate> ChannelQuerier<Chain, Counterparty>
for DelegateQueryChannel<Components>
where
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
Counterparty: HasChannelEndsType<Chain>,
Components: DelegateComponent<Counterparty, Delegate = Delegate>,
Delegate: ChannelQuerier<Chain, Counterparty>,
{
async fn query_channel(
chain: &Chain,
port_id: &Chain::PortId,
channel_id: &Chain::ChannelId,
height: &Chain::Height,
) -> Result<Counterparty::ChannelEnd, Chain::Error> {
Delegate::query_channel(chain, port_id, channel_id, height).await
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod client_state;
pub mod consensus_state;
pub mod channel;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use alloc::vec::Vec;
use cgp_core::prelude::*;

use crate::chain::traits::types::{channel::HasChannelEndsType, ibc::HasIbcChainTypes};

#[derive_component(ChannelQuerierComponent, ChannelQuerier<Chain>)]
#[async_trait]
pub trait CanQueryChannel<Counterparty>: HasIbcChainTypes<Counterparty> + HasErrorType
where
Counterparty: HasChannelEndsType<Self>,
{
async fn query_channel(
&self,
port_id: &Self::PortId,
channel_id: &Self::ChannelId,
height: &Self::Height,
) -> Result<Counterparty::ChannelEnd, Self::Error>;
}

#[derive_component(ChannelBytesQuerierComponent, ChannelBytesQuerier<Chain>)]
#[async_trait]
pub trait CanQueryChannelBytes<Counterparty>:
HasIbcChainTypes<Counterparty> + HasErrorType
{
async fn query_channel_bytes(
&self,
port_id: &Self::PortId,
channel_id: &Self::ChannelId,
height: &Self::Height,
) -> Result<Vec<u8>, Self::Error>;
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ pub mod send_packets;
pub mod unreceived_acks_sequences;
pub mod unreceived_packet_sequences;
pub mod write_ack;
pub mod channel;
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ pub trait HasChannelHandshakePayloadTypes<Counterparty> {

type ChannelOpenConfirmPayload: Async;
}


#[derive_component(ChannelEndsTypeComponent, ProvideChannelEndsType<Chain>)]
pub trait HasChannelEndsType<Counterparty> {
type ChannelEnd: Async;
}

0 comments on commit ed6a175

Please sign in to comment.