hermes_cli/commands/clear/
packets.rs1use futures::stream::{self, StreamExt};
2use hermes_cli_components::traits::build::CanLoadBuilder;
3use hermes_cli_framework::command::CommandRunner;
4use hermes_cli_framework::output::Output;
5use hermes_relayer_components::build::traits::builders::birelay_builder::CanBuildBiRelay;
6use hermes_relayer_components::relay::traits::packet_clearer::CanClearPackets;
7use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ChannelId, ClientId, PortId};
8
9use crate::contexts::app::HermesApp;
10use crate::Result;
11
12#[derive(Debug, clap::Parser)]
13pub struct PacketsClear {
14 #[clap(
15 long = "chain",
16 required = true,
17 value_name = "CHAIN_ID",
18 help_heading = "REQUIRED",
19 help = "Identifier of the chain to query"
20 )]
21 chain_id: ChainId,
22
23 #[clap(
24 long = "port",
25 required = true,
26 value_name = "PORT_ID",
27 help_heading = "REQUIRED",
28 help = "Identifier of the port"
29 )]
30 port_id: PortId,
31
32 #[clap(
33 long = "channel",
34 alias = "chan",
35 required = true,
36 value_name = "CHANNEL_ID",
37 help_heading = "REQUIRED",
38 help = "Identifier of the channel"
39 )]
40 channel_id: ChannelId,
41
42 #[clap(
43 long = "client",
44 required = true,
45 value_name = "CLIENT_ID",
46 help_heading = "REQUIRED",
47 help = "Identifier of the client"
48 )]
49 client_id: ClientId,
50
51 #[clap(
52 long = "counterparty-chain",
53 required = true,
54 value_name = "COUNTERPARTY_CHAIN_ID",
55 help_heading = "REQUIRED",
56 help = "Identifier of the counterparty chain to query"
57 )]
58 counterparty_chain_id: ChainId,
59
60 #[clap(
61 long = "counterparty-client",
62 required = true,
63 value_name = "COUNTERPARTY_CLIENT_ID",
64 help_heading = "REQUIRED",
65 help = "Identifier of the counterparty client"
66 )]
67 counterparty_client_id: ClientId,
68
69 #[clap(
70 long = "counterparty-port",
71 required = true,
72 value_name = "COUNTERPARTY_PORT_ID",
73 help_heading = "REQUIRED",
74 help = "Identifier of the counterparty port"
75 )]
76 counterparty_port_id: PortId,
77
78 #[clap(
79 long = "counterparty-channel",
80 required = true,
81 value_name = "COUNTERPARTY_CHANNEL_ID",
82 help_heading = "REQUIRED",
83 help = "Identifier of the counterparty channel"
84 )]
85 counterparty_channel_id: ChannelId,
86}
87
88impl CommandRunner<HermesApp> for PacketsClear {
89 async fn run(&self, app: &HermesApp) -> Result<Output> {
90 let builder = app.load_builder().await?;
91
92 let relayer = builder
93 .build_birelay(
94 &self.chain_id,
95 &self.counterparty_chain_id,
96 &self.client_id,
97 &self.counterparty_client_id, )
99 .await?;
100
101 stream::iter(vec![
102 relayer.relay_a_to_b.clear_packets(
103 &self.channel_id,
104 &self.port_id,
105 &self.counterparty_channel_id,
106 &self.counterparty_port_id,
107 ),
108 relayer.relay_b_to_a.clear_packets(
109 &self.counterparty_channel_id,
110 &self.counterparty_port_id,
111 &self.channel_id,
112 &self.port_id,
113 ),
114 ])
115 .for_each_concurrent(None, |x| async {
116 let _ = x.await;
117 })
118 .await;
119
120 Ok(Output::success("Packet clear"))
121 }
122}