-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(relayer): build packet messages, query packet status, extract pa…
…cket event (#169) * dummy impl to convert from IbcPacket * build_receive_packet_message for starknet * build_ack_packet_message for starknet * add trait bounds * build_timeout_unordered_packet_message for starknet * try_extract_write_ack_event * add trait bounds * query_packet_commitment for starknet * query_packet_acknowledgement for starknet * impl u32 array decode * add trait bound * query_packet_is_received for starknet * query_packet_receipt for starknet * query if ack exits * impl IbcPacket to CairoPacket * use CairoPacket::try_from * add todo comment * fix typo --------- Co-authored-by: Farhad Shabani <farhad.shabani@gmail.com>
- Loading branch information
1 parent
d542304
commit 717b229
Showing
14 changed files
with
631 additions
and
97 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
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
54 changes: 47 additions & 7 deletions
54
relayer/crates/starknet-chain-components/src/impls/events/ack.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,23 +1,63 @@ | ||
use cgp::prelude::*; | ||
use hermes_cairo_encoding_components::strategy::ViaCairo; | ||
use hermes_cairo_encoding_components::types::as_felt::AsFelt; | ||
use hermes_chain_components::traits::types::event::HasEventType; | ||
use hermes_chain_components::traits::types::ibc_events::write_ack::ProvideWriteAckEvent; | ||
use hermes_chain_components::traits::types::packets::ack::HasAcknowledgementType; | ||
use hermes_encoding_components::traits::decode::CanDecode; | ||
use hermes_encoding_components::traits::has_encoding::HasDefaultEncoding; | ||
use hermes_encoding_components::traits::types::encoded::HasEncodedType; | ||
use starknet::core::types::Felt; | ||
|
||
use crate::types::channel_id::ChannelId; | ||
use crate::types::event::StarknetEvent; | ||
use crate::types::events::packet::WriteAcknowledgementEvent; | ||
use crate::types::messages::ibc::channel::PortId; | ||
use crate::types::messages::ibc::packet::{Acknowledgement, Sequence}; | ||
|
||
pub struct UseStarknetWriteAckEvent; | ||
|
||
impl<Chain, Counterparty> ProvideWriteAckEvent<Chain, Counterparty> for UseStarknetWriteAckEvent | ||
impl<Chain, Counterparty, Encoding> ProvideWriteAckEvent<Chain, Counterparty> | ||
for UseStarknetWriteAckEvent | ||
where | ||
Chain: HasEventType<Event = StarknetEvent> | ||
+ HasAcknowledgementType<Counterparty, Acknowledgement = Vec<u8>>, | ||
+ HasAcknowledgementType<Counterparty, Acknowledgement = Vec<u8>> | ||
+ HasDefaultEncoding<AsFelt, Encoding = Encoding>, | ||
Encoding: HasEncodedType<Encoded = Vec<Felt>> | ||
+ CanDecode<ViaCairo, Product![Sequence, PortId, ChannelId, PortId, ChannelId]> | ||
+ CanDecode<ViaCairo, Product![Vec<Felt>, Acknowledgement]>, | ||
{ | ||
type WriteAckEvent = Vec<u8>; | ||
type WriteAckEvent = WriteAcknowledgementEvent; | ||
|
||
fn try_extract_write_ack_event(_event: &StarknetEvent) -> Option<Self::WriteAckEvent> { | ||
todo!() | ||
fn try_extract_write_ack_event(event: &StarknetEvent) -> Option<Self::WriteAckEvent> { | ||
// TODO(rano): don't have access to the EventEncoding | ||
// Ideally, EventEncoding to decode directly from StarknetEvent | ||
|
||
let cairo_encoding = Chain::default_encoding(); | ||
|
||
let product![ | ||
sequence_on_a, | ||
port_id_on_a, | ||
channel_id_on_a, | ||
port_id_on_b, | ||
channel_id_on_b, | ||
] = cairo_encoding.decode(&event.keys).ok()?; | ||
|
||
let product![packet_data, acknowledgement,] = cairo_encoding.decode(&event.data).ok()?; | ||
|
||
Some(WriteAcknowledgementEvent { | ||
sequence_on_a, | ||
port_id_on_a, | ||
channel_id_on_a, | ||
port_id_on_b, | ||
channel_id_on_b, | ||
packet_data, | ||
acknowledgement, | ||
}) | ||
} | ||
|
||
fn write_acknowledgement(ack: &Vec<u8>) -> impl AsRef<Vec<u8>> + Send { | ||
ack | ||
fn write_acknowledgement(_ack: &WriteAcknowledgementEvent) -> impl AsRef<Vec<u8>> + Send { | ||
// TODO(rano): ack.acknowledgement.ack is Vec<Felt> | ||
vec![0x1] | ||
} | ||
} |
Oops, something went wrong.