Skip to content

Commit

Permalink
Fix query client consensus command (informalsystems#287)
Browse files Browse the repository at this point in the history
* Add epoch to query client consensus

* Review comments
  • Loading branch information
ancazamfir committed Oct 7, 2020
1 parent abb80c9 commit baf27d3
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions relayer-cli/src/commands/query/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ pub struct QueryClientConsensusCmd {
#[options(free, help = "identifier of the client to query")]
client_id: Option<String>,

#[options(free, help = "epoch of the client's consensus state to query")]
consensus_epoch: Option<u64>,

#[options(free, help = "height of the client's consensus state to query")]
consensus_height: Option<u64>,

Expand All @@ -116,6 +119,7 @@ pub struct QueryClientConsensusCmd {
#[derive(Debug)]
struct QueryClientConsensusOptions {
client_id: ClientId,
consensus_epoch: u64,
consensus_height: u64,
height: u64,
proof: bool,
Expand All @@ -129,10 +133,11 @@ impl QueryClientConsensusCmd {
let (chain_config, client_id) =
validate_common_options(&self.chain_id, &self.client_id, config)?;

match self.consensus_height {
Some(consensus_height) => {
match (self.consensus_epoch, self.consensus_height) {
(Some(consensus_epoch), Some(consensus_height)) => {
let opts = QueryClientConsensusOptions {
client_id,
consensus_epoch,
consensus_height,
height: match self.height {
Some(h) => h,
Expand All @@ -145,7 +150,9 @@ impl QueryClientConsensusCmd {
};
Ok((chain_config, opts))
}
None => Err("missing client consensus height".to_string()),
(Some(consensus_epoch), None) => Err("missing client consensus height".to_string()),

(None, _) => Err("missing client consensus epoch".to_string()),
}
}
}
Expand All @@ -172,7 +179,11 @@ impl Runnable for QueryClientConsensusCmd {
let chain = CosmosSDKChain::from_config(chain_config).unwrap();
let res: Result<AnyConsensusState, Error> = chain
.query(
ClientConsensusState(opts.client_id, opts.consensus_height),
ClientConsensusState {
client_id: opts.client_id,
epoch: opts.consensus_epoch,
height: opts.consensus_height,
},
opts.height,
opts.proof,
)
Expand Down

0 comments on commit baf27d3

Please sign in to comment.