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

Minor refactoring for channel handshake #503

Merged
merged 6 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
use cgp::core::component::UseDelegate;
use cgp::prelude::*;
use hermes_chain_type_components::traits::types::counterparty::CanUseCounterparty;
use hermes_chain_type_components::traits::types::ibc::channel_id::HasChannelIdType;
use hermes_chain_type_components::traits::types::ibc::port_id::HasPortIdType;
use hermes_chain_type_components::traits::types::message::HasMessageType;

use crate::traits::types::channel::{
ChannelOpenAckPayloadOf, ChannelOpenConfirmPayloadOf, ChannelOpenTryPayloadOf,
HasChannelOpenAckPayloadType, HasChannelOpenConfirmPayloadType, HasChannelOpenTryPayloadType,
HasInitChannelOptionsType,
};
use crate::traits::types::ibc::HasIbcChainTypes;
use crate::types::aliases::{ChannelIdOf, PortIdOf};

#[cgp_component {
provider: ChannelOpenInitMessageBuilder,
context: Chain,
}]
#[async_trait]
pub trait CanBuildChannelOpenInitMessage<Counterparty>:
HasInitChannelOptionsType<Counterparty> + HasIbcChainTypes<Counterparty> + HasErrorType
where
Counterparty: HasIbcChainTypes<Self>,
Sized
+ HasMessageType
+ HasPortIdType<Counterparty>
+ HasInitChannelOptionsType<Counterparty>
+ HasErrorType
+ CanUseCounterparty<Counterparty, Counterparty: HasPortIdType<Self>>
{
async fn build_channel_open_init_message(
&self,
port_id: &Self::PortId,
counterparty_port_id: &Counterparty::PortId,
counterparty_port_id: &PortIdOf<Counterparty, Self>,
init_channel_options: &Self::InitChannelOptions,
) -> Result<Self::Message, Self::Error>;
}
Expand All @@ -31,16 +39,22 @@ where
}]
#[async_trait]
pub trait CanBuildChannelOpenTryMessage<Counterparty>:
HasIbcChainTypes<Counterparty> + HasErrorType
where
Counterparty: HasChannelOpenTryPayloadType<Self> + HasIbcChainTypes<Self>,
HasMessageType
+ HasPortIdType<Counterparty>
+ HasErrorType
+ CanUseCounterparty<
Counterparty,
Counterparty: HasChannelIdType<Self>
+ HasPortIdType<Self>
+ HasChannelOpenTryPayloadType<Self>,
>
{
async fn build_channel_open_try_message(
&self,
port_id: &Self::PortId,
counterparty_port_id: &Counterparty::PortId,
counterparty_channel_id: &Counterparty::ChannelId,
counterparty_payload: Counterparty::ChannelOpenTryPayload,
counterparty_port_id: &PortIdOf<Counterparty, Self>,
counterparty_channel_id: &ChannelIdOf<Counterparty, Self>,
counterparty_payload: ChannelOpenTryPayloadOf<Counterparty, Self>,
) -> Result<Self::Message, Self::Error>;
}

Expand All @@ -50,16 +64,23 @@ where
}]
#[async_trait]
pub trait CanBuildChannelOpenAckMessage<Counterparty>:
HasIbcChainTypes<Counterparty> + HasErrorType
where
Counterparty: HasChannelOpenAckPayloadType<Self> + HasIbcChainTypes<Self>,
HasMessageType
+ HasPortIdType<Counterparty>
+ HasChannelIdType<Counterparty>
+ HasErrorType
+ CanUseCounterparty<
Counterparty,
Counterparty: HasChannelIdType<Self>
+ HasPortIdType<Self>
+ HasChannelOpenAckPayloadType<Self>,
>
{
async fn build_channel_open_ack_message(
&self,
port_id: &Self::PortId,
channel_id: &Self::ChannelId,
counterparty_channel_id: &Counterparty::ChannelId,
counterparty_payload: Counterparty::ChannelOpenAckPayload,
counterparty_channel_id: &ChannelIdOf<Counterparty, Self>,
counterparty_payload: ChannelOpenAckPayloadOf<Counterparty, Self>,
) -> Result<Self::Message, Self::Error>;
}

Expand All @@ -69,23 +90,28 @@ where
}]
#[async_trait]
pub trait CanBuildChannelOpenConfirmMessage<Counterparty>:
HasIbcChainTypes<Counterparty> + HasErrorType
where
Counterparty: HasChannelOpenConfirmPayloadType<Self> + HasIbcChainTypes<Self>,
HasMessageType
+ HasPortIdType<Counterparty>
+ HasChannelIdType<Counterparty>
+ HasErrorType
+ CanUseCounterparty<Counterparty, Counterparty: HasChannelOpenConfirmPayloadType<Self>>
{
async fn build_channel_open_confirm_message(
&self,
port_id: &Self::PortId,
channel_id: &Self::ChannelId,
counterparty_payload: Counterparty::ChannelOpenConfirmPayload,
counterparty_payload: ChannelOpenConfirmPayloadOf<Counterparty, Self>,
) -> Result<Self::Message, Self::Error>;
}

impl<Chain, Counterparty, Components, Delegate> ChannelOpenInitMessageBuilder<Chain, Counterparty>
for UseDelegate<Components>
where
Chain: HasInitChannelOptionsType<Counterparty> + HasIbcChainTypes<Counterparty> + HasErrorType,
Counterparty: HasIbcChainTypes<Chain>,
Chain: HasMessageType
+ HasPortIdType<Counterparty>
+ HasInitChannelOptionsType<Counterparty>
+ HasErrorType,
Counterparty: HasPortIdType<Chain>,
Delegate: ChannelOpenInitMessageBuilder<Chain, Counterparty>,
Components: DelegateComponent<Counterparty, Delegate = Delegate>,
{
Expand All @@ -108,8 +134,9 @@ where
impl<Chain, Counterparty, Components, Delegate> ChannelOpenTryMessageBuilder<Chain, Counterparty>
for UseDelegate<Components>
where
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
Counterparty: HasChannelOpenTryPayloadType<Chain> + HasIbcChainTypes<Chain>,
Chain: HasMessageType + HasPortIdType<Counterparty> + HasErrorType,
Counterparty:
HasChannelIdType<Chain> + HasPortIdType<Chain> + HasChannelOpenTryPayloadType<Chain>,
Delegate: ChannelOpenTryMessageBuilder<Chain, Counterparty>,
Components: DelegateComponent<Counterparty, Delegate = Delegate>,
{
Expand All @@ -134,8 +161,12 @@ where
impl<Chain, Counterparty, Components, Delegate> ChannelOpenAckMessageBuilder<Chain, Counterparty>
for UseDelegate<Components>
where
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
Counterparty: HasChannelOpenAckPayloadType<Chain> + HasIbcChainTypes<Chain>,
Chain: HasMessageType
+ HasPortIdType<Counterparty>
+ HasChannelIdType<Counterparty>
+ HasErrorType,
Counterparty:
HasChannelIdType<Chain> + HasPortIdType<Chain> + HasChannelOpenAckPayloadType<Chain>,
Delegate: ChannelOpenAckMessageBuilder<Chain, Counterparty>,
Components: DelegateComponent<Counterparty, Delegate = Delegate>,
{
Expand All @@ -160,8 +191,11 @@ where
impl<Chain, Counterparty, Components, Delegate>
ChannelOpenConfirmMessageBuilder<Chain, Counterparty> for UseDelegate<Components>
where
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
Counterparty: HasChannelOpenConfirmPayloadType<Chain> + HasIbcChainTypes<Chain>,
Chain: HasMessageType
+ HasPortIdType<Counterparty>
+ HasChannelIdType<Counterparty>
+ HasErrorType,
Counterparty: HasChannelOpenConfirmPayloadType<Chain>,
Delegate: ChannelOpenConfirmMessageBuilder<Chain, Counterparty>,
Components: DelegateComponent<Counterparty, Delegate = Delegate>,
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use cgp::core::component::UseDelegate;
use cgp::prelude::*;
use hermes_chain_type_components::traits::types::counterparty::CanUseCounterparty;

use crate::traits::types::create_client::{
HasCreateClientMessageOptionsType, HasCreateClientPayloadType,
CreateClientPayloadOf, HasCreateClientMessageOptionsType, HasCreateClientPayloadType,
};
use crate::traits::types::message::HasMessageType;

Expand All @@ -12,14 +13,15 @@ use crate::traits::types::message::HasMessageType;
}]
#[async_trait]
pub trait CanBuildCreateClientMessage<Counterparty>:
HasCreateClientMessageOptionsType<Counterparty> + HasMessageType + HasErrorType
where
Counterparty: HasCreateClientPayloadType<Self>,
HasCreateClientMessageOptionsType<Counterparty>
+ HasMessageType
+ HasErrorType
+ CanUseCounterparty<Counterparty, Counterparty: HasCreateClientPayloadType<Self>>
{
async fn build_create_client_message(
&self,
create_client_options: &Self::CreateClientMessageOptions,
counterparty_payload: Counterparty::CreateClientPayload,
counterparty_payload: CreateClientPayloadOf<Counterparty, Self>,
) -> Result<Self::Message, Self::Error>;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
use cgp::prelude::*;
use hermes_chain_type_components::traits::types::height::HasHeightType;
use hermes_chain_type_components::traits::types::ibc::channel_id::HasChannelIdType;
use hermes_chain_type_components::traits::types::ibc::port_id::HasPortIdType;

use crate::traits::types::channel::{
HasChannelOpenAckPayloadType, HasChannelOpenConfirmPayloadType, HasChannelOpenTryPayloadType,
};
use crate::traits::types::client_state::HasClientStateType;
use crate::traits::types::ibc::HasIbcChainTypes;

#[cgp_component {
provider: ChannelOpenTryPayloadBuilder,
context: Chain,
}]
#[async_trait]
pub trait CanBuildChannelOpenTryPayload<Counterparty>:
HasIbcChainTypes<Counterparty>
HasHeightType
+ HasChannelIdType<Counterparty>
+ HasPortIdType<Counterparty>
+ HasChannelOpenTryPayloadType<Counterparty>
+ HasClientStateType<Counterparty>
+ HasErrorType
Expand All @@ -32,7 +36,9 @@ pub trait CanBuildChannelOpenTryPayload<Counterparty>:
}]
#[async_trait]
pub trait CanBuildChannelOpenAckPayload<Counterparty>:
HasIbcChainTypes<Counterparty>
HasHeightType
+ HasChannelIdType<Counterparty>
+ HasPortIdType<Counterparty>
+ HasChannelOpenAckPayloadType<Counterparty>
+ HasClientStateType<Counterparty>
+ HasErrorType
Expand All @@ -52,7 +58,9 @@ pub trait CanBuildChannelOpenAckPayload<Counterparty>:
}]
#[async_trait]
pub trait CanBuildChannelOpenConfirmPayload<Counterparty>:
HasIbcChainTypes<Counterparty>
HasHeightType
+ HasChannelIdType<Counterparty>
+ HasPortIdType<Counterparty>
+ HasChannelOpenConfirmPayloadType<Counterparty>
+ HasClientStateType<Counterparty>
+ HasErrorType
Expand Down
15 changes: 12 additions & 3 deletions crates/chain/chain-components/src/traits/queries/channel_end.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use core::fmt::Debug;

use cgp::prelude::*;
use hermes_chain_type_components::traits::types::height::HasHeightType;
use hermes_chain_type_components::traits::types::ibc::channel_id::HasChannelIdType;
use hermes_chain_type_components::traits::types::ibc::port_id::HasPortIdType;

use crate::traits::types::channel::HasChannelEndType;
use crate::traits::types::ibc::HasIbcChainTypes;
Expand All @@ -12,7 +15,11 @@ use crate::traits::types::proof::HasCommitmentProofType;
}]
#[async_trait]
pub trait CanQueryChannelEnd<Counterparty>:
HasChannelEndType<Counterparty> + HasIbcChainTypes<Counterparty> + HasErrorType
HasHeightType
+ HasChannelIdType<Counterparty>
+ HasPortIdType<Counterparty>
+ HasChannelEndType<Counterparty>
+ HasErrorType
{
async fn query_channel_end(
&self,
Expand All @@ -28,8 +35,10 @@ pub trait CanQueryChannelEnd<Counterparty>:
}]
#[async_trait]
pub trait CanQueryChannelEndWithProofs<Counterparty>:
HasChannelEndType<Counterparty>
+ HasIbcChainTypes<Counterparty>
HasHeightType
+ HasChannelIdType<Counterparty>
+ HasPortIdType<Counterparty>
+ HasChannelEndType<Counterparty>
+ HasCommitmentProofType
+ HasErrorType
{
Expand Down
21 changes: 21 additions & 0 deletions crates/chain/chain-components/src/traits/types/channel.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use cgp::core::component::WithProvider;
use cgp::core::types::traits::ProvideType;
use cgp::prelude::*;

#[cgp_component {
Expand Down Expand Up @@ -25,6 +27,9 @@ pub trait HasChannelOpenTryPayloadType<Counterparty> {
type ChannelOpenTryPayload: Async;
}

pub type ChannelOpenTryPayloadOf<Chain, Counterparty> =
<Chain as HasChannelOpenTryPayloadType<Counterparty>>::ChannelOpenTryPayload;

#[cgp_component {
name: ChannelOpenAckPayloadTypeComponent,
provider: ProvideChannelOpenAckPayloadType,
Expand All @@ -34,6 +39,9 @@ pub trait HasChannelOpenAckPayloadType<Counterparty> {
type ChannelOpenAckPayload: Async;
}

pub type ChannelOpenAckPayloadOf<Chain, Counterparty> =
<Chain as HasChannelOpenAckPayloadType<Counterparty>>::ChannelOpenAckPayload;

#[cgp_component {
name: ChannelOpenConfirmPayloadTypeComponent,
provider: ProvideChannelOpenConfirmPayloadType,
Expand All @@ -43,6 +51,9 @@ pub trait HasChannelOpenConfirmPayloadType<Counterparty> {
type ChannelOpenConfirmPayload: Async;
}

pub type ChannelOpenConfirmPayloadOf<Chain, Counterparty> =
<Chain as HasChannelOpenConfirmPayloadType<Counterparty>>::ChannelOpenConfirmPayload;

#[cgp_component {
name: ChannelEndTypeComponent,
provider: ProvideChannelEndType,
Expand All @@ -51,3 +62,13 @@ pub trait HasChannelOpenConfirmPayloadType<Counterparty> {
pub trait HasChannelEndType<Counterparty>: Async {
type ChannelEnd: Async;
}

impl<Chain, Counterparty, Provider, ChannelEnd> ProvideChannelEndType<Chain, Counterparty>
for WithProvider<Provider>
where
Provider: ProvideType<Chain, ChannelEndTypeComponent, Type = ChannelEnd>,
Chain: Async,
ChannelEnd: Async,
{
type ChannelEnd = ChannelEnd;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ pub trait HasCreateClientPayloadType<Counterparty>: Async {
type CreateClientPayload: Async;
}

pub type CreateClientPayloadOf<Chain, Counterparty> =
<Chain as HasCreateClientPayloadType<Counterparty>>::CreateClientPayload;

#[cgp_component {
name: CreateClientEventComponent,
provider: ProvideCreateClientEvent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ use crate::impls::queries::ack_packet::QueryCosmosAckPacket;
use crate::impls::queries::ack_packets::QueryAckPacketsConcurrently;
use crate::impls::queries::block::QueryCometBlock;
use crate::impls::queries::chain_id::QueryChainIdFromAbci;
use crate::impls::queries::chain_status::QueryChainStatusWithChainHandle;
use crate::impls::queries::chain_status::QueryCosmosChainStatus;
use crate::impls::queries::channel_end::QueryCosmosChannelEndFromAbci;
use crate::impls::queries::client_state::QueryCosmosClientStateFromAbci;
use crate::impls::queries::connection_end::QueryCosmosConnectionEndFromAbci;
Expand Down Expand Up @@ -314,7 +314,7 @@ cgp_preset! {
PacketFromWriteAckBuilderComponent:
BuildCosmosPacketFromWriteAck,
ChainStatusQuerierComponent:
QueryChainStatusWithChainHandle,
QueryCosmosChainStatus,
InitConnectionOptionsTypeComponent:
ProvideCosmosInitConnectionOptionsType,
InitChannelOptionsTypeComponent:
Expand Down
Loading
Loading