-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor event traits to better support Starknet events (#531)
* Define event extractor traits * Rename ChannelClosedError to ErrChannelClosed * Implement CanExtractFromEvent<CosmosCreateClientEvent> * Use CanExtractFromMessageResponse for create client events * Use extractor for connection and channel events * Refactor send packet event * Refactor write ack event * Remove unused trait bounds * Add provider trait for HasEventSubscription * Return Option in event subscription getter * Remove HasEventType bound from HasSendPacketEvent * Relax API for build_packet_from_write_ack_event * Introduce CanBuildPacketFromSendPacket * Move around PacketFromWriteAckEventBuilder * Remove extract packet method from HasSendPacketEvent * Add build_ack_from_write_ack_event * Fix clippy
- Loading branch information
1 parent
3ff219f
commit 8e62668
Showing
48 changed files
with
582 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#![no_std] | ||
#![allow(clippy::type_complexity)] | ||
|
||
extern crate alloc; | ||
|
||
|
7 changes: 6 additions & 1 deletion
7
crates/chain/chain-components/src/traits/event_subscription.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
use cgp::prelude::*; | ||
use hermes_runtime_components::traits::runtime::HasRuntime; | ||
use hermes_runtime_components::traits::subscription::HasSubscription; | ||
|
||
use crate::traits::types::event::HasEventType; | ||
use crate::traits::types::height::HasHeightType; | ||
|
||
#[cgp_component { | ||
provider: EventSubscriptionGetter, | ||
context: Chain, | ||
}] | ||
pub trait HasEventSubscription: HasHeightType + HasEventType + HasRuntime | ||
where | ||
Self::Runtime: HasSubscription, | ||
{ | ||
fn event_subscription( | ||
&self, | ||
) -> &<Self::Runtime as HasSubscription>::Subscription<(Self::Height, Self::Event)>; | ||
) -> Option<&<Self::Runtime as HasSubscription>::Subscription<(Self::Height, Self::Event)>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use core::marker::PhantomData; | ||
|
||
use cgp::core::component::UseDelegate; | ||
use cgp::prelude::*; | ||
use hermes_chain_type_components::traits::fields::message_response_events::HasMessageResponseEvents; | ||
use hermes_chain_type_components::traits::types::event::HasEventType; | ||
use hermes_chain_type_components::traits::types::message_response::HasMessageResponseType; | ||
|
||
#[cgp_component { | ||
provider: MessageResponseExtractor, | ||
context: Chain, | ||
}] | ||
pub trait CanExtractFromMessageResponse<Data>: HasMessageResponseType { | ||
fn try_extract_from_message_response( | ||
&self, | ||
_tag: PhantomData<Data>, | ||
message_response: &Self::MessageResponse, | ||
) -> Option<Data>; | ||
} | ||
|
||
#[cgp_component { | ||
provider: EventExtractor, | ||
context: Chain, | ||
}] | ||
pub trait CanExtractFromEvent<Data>: HasEventType { | ||
fn try_extract_from_event(&self, _tag: PhantomData<Data>, event: &Self::Event) -> Option<Data>; | ||
} | ||
|
||
pub struct ExtractFromMessageResponseViaEvents; | ||
|
||
impl<Chain, Data> MessageResponseExtractor<Chain, Data> for ExtractFromMessageResponseViaEvents | ||
where | ||
Chain: HasMessageResponseEvents + CanExtractFromEvent<Data>, | ||
{ | ||
fn try_extract_from_message_response( | ||
chain: &Chain, | ||
tag: PhantomData<Data>, | ||
message_response: &Chain::MessageResponse, | ||
) -> Option<Data> { | ||
Chain::message_response_events(message_response) | ||
.iter() | ||
.find_map(|event| chain.try_extract_from_event(tag, event)) | ||
} | ||
} | ||
|
||
impl<Chain, Data, Components> MessageResponseExtractor<Chain, Data> for UseDelegate<Components> | ||
where | ||
Chain: HasMessageResponseType, | ||
Components: DelegateComponent<Data>, | ||
Components::Delegate: MessageResponseExtractor<Chain, Data>, | ||
{ | ||
fn try_extract_from_message_response( | ||
chain: &Chain, | ||
tag: PhantomData<Data>, | ||
message_response: &Chain::MessageResponse, | ||
) -> Option<Data> { | ||
Components::Delegate::try_extract_from_message_response(chain, tag, message_response) | ||
} | ||
} | ||
|
||
impl<Chain, Data, Components> EventExtractor<Chain, Data> for UseDelegate<Components> | ||
where | ||
Chain: HasEventType, | ||
Components: DelegateComponent<Data>, | ||
Components::Delegate: EventExtractor<Chain, Data>, | ||
{ | ||
fn try_extract_from_event( | ||
chain: &Chain, | ||
tag: PhantomData<Data>, | ||
event: &Chain::Event, | ||
) -> Option<Data> { | ||
Components::Delegate::try_extract_from_event(chain, tag, event) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
crates/chain/chain-components/src/traits/packet/from_send_packet.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use cgp::prelude::*; | ||
use hermes_chain_type_components::traits::types::ibc::packet::HasOutgoingPacketType; | ||
|
||
use crate::traits::types::ibc_events::send_packet::HasSendPacketEvent; | ||
|
||
#[cgp_component { | ||
provider: PacketFromSendPacketEventBuilder, | ||
context: Chain, | ||
}] | ||
#[async_trait] | ||
pub trait CanBuildPacketFromSendPacket<Counterparty>: | ||
Sized + HasSendPacketEvent<Counterparty> + HasOutgoingPacketType<Counterparty> + HasAsyncErrorType | ||
{ | ||
async fn build_packet_from_send_packet_event( | ||
&self, | ||
event: &Self::SendPacketEvent, | ||
) -> Result<Self::OutgoingPacket, Self::Error>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod fields; | ||
pub mod filter; | ||
pub mod from_send_packet; | ||
pub mod from_write_ack; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.