1
1
use abscissa_core:: clap:: Parser ;
2
2
3
3
use ibc_relayer:: chain:: counterparty:: commitments_on_chain;
4
- use ibc_relayer:: chain:: requests:: Paginate ;
4
+ use ibc_relayer:: chain:: handle:: ChainHandle ;
5
+ use ibc_relayer:: chain:: requests:: { Paginate , QueryHeight } ;
6
+ use ibc_relayer_types:: core:: ics02_client:: height:: Height ;
5
7
use ibc_relayer_types:: core:: ics24_host:: identifier:: { ChainId , ChannelId , PortId } ;
6
8
7
9
use crate :: cli_utils:: spawn_chain_runtime;
8
- use crate :: conclude:: Output ;
10
+ use crate :: conclude:: { exit_with_unrecoverable_error , Output } ;
9
11
use crate :: error:: Error ;
10
12
use crate :: prelude:: * ;
11
13
@@ -40,6 +42,13 @@ pub struct QueryPacketCommitmentsCmd {
40
42
help = "Identifier of the channel to query"
41
43
) ]
42
44
channel_id : ChannelId ,
45
+
46
+ #[ clap(
47
+ long = "height" ,
48
+ value_name = "HEIGHT" ,
49
+ help = "Height of the state to query. Leave unspecified for latest height."
50
+ ) ]
51
+ height : Option < u64 > ,
43
52
}
44
53
45
54
impl QueryPacketCommitmentsCmd {
@@ -48,12 +57,25 @@ impl QueryPacketCommitmentsCmd {
48
57
49
58
let chain = spawn_chain_runtime ( & config, & self . chain_id ) ?;
50
59
51
- commitments_on_chain ( & chain, & self . port_id , & self . channel_id , Paginate :: All )
52
- . map_err ( Error :: supervisor)
53
- . map ( |( seqs_vec, height) | PacketSeqs {
54
- height,
55
- seqs : seqs_vec,
56
- } )
60
+ let query_height = self . height . map_or ( QueryHeight :: Latest , |revision_height| {
61
+ QueryHeight :: Specific (
62
+ Height :: new ( chain. id ( ) . version ( ) , revision_height)
63
+ . unwrap_or_else ( exit_with_unrecoverable_error) ,
64
+ )
65
+ } ) ;
66
+
67
+ commitments_on_chain (
68
+ & chain,
69
+ & query_height,
70
+ & self . port_id ,
71
+ & self . channel_id ,
72
+ Paginate :: All ,
73
+ )
74
+ . map_err ( Error :: supervisor)
75
+ . map ( |( seqs_vec, height) | PacketSeqs {
76
+ height,
77
+ seqs : seqs_vec,
78
+ } )
57
79
}
58
80
}
59
81
@@ -85,7 +107,8 @@ mod tests {
85
107
QueryPacketCommitmentsCmd {
86
108
chain_id: ChainId :: from_string( "chain_id" ) ,
87
109
port_id: PortId :: from_str( "port_id" ) . unwrap( ) ,
88
- channel_id: ChannelId :: from_str( "channel-07" ) . unwrap( )
110
+ channel_id: ChannelId :: from_str( "channel-07" ) . unwrap( ) ,
111
+ height: None ,
89
112
} ,
90
113
QueryPacketCommitmentsCmd :: parse_from( [
91
114
"test" ,
@@ -105,7 +128,8 @@ mod tests {
105
128
QueryPacketCommitmentsCmd {
106
129
chain_id: ChainId :: from_string( "chain_id" ) ,
107
130
port_id: PortId :: from_str( "port_id" ) . unwrap( ) ,
108
- channel_id: ChannelId :: from_str( "channel-07" ) . unwrap( )
131
+ channel_id: ChannelId :: from_str( "channel-07" ) . unwrap( ) ,
132
+ height: None ,
109
133
} ,
110
134
QueryPacketCommitmentsCmd :: parse_from( [
111
135
"test" ,
0 commit comments