Skip to content

Commit

Permalink
Remove unwrap calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ljoss17 committed Dec 2, 2024
1 parent e636232 commit e79abf2
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 35 deletions.
10 changes: 2 additions & 8 deletions crates/cli/cli/src/commands/query/channel/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,14 @@ impl CommandRunner<HermesApp> for QueryChannelClient {
let channel_id = self.channel_id.clone();
let port_id = self.port_id.clone();

let mut client = QueryClient::connect(chain.grpc_address().clone())
.await
.unwrap();
let mut client = QueryClient::connect(chain.grpc_address().clone()).await?;

let request = tonic::Request::new(QueryChannelClientStateRequest {
port_id: port_id.to_string(),
channel_id: channel_id.to_string(),
});

let response = client
.channel_client_state(request)
.await
.unwrap()
.into_inner();
let response = client.channel_client_state(request).await?.into_inner();

let client_state = response.identified_client_state;

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/cli/src/commands/query/channel/ends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl CommandRunner<HermesApp> for QueryChannelEnds {
.query_abci(IBC_QUERY_PATH, client_state_path.as_bytes(), &query_height)
.await?;

let client_state = AnyClientState::decode_vec(&client_state_bytes).unwrap();
let client_state = AnyClientState::decode_vec(&client_state_bytes)?;

let channel_counterparty = channel_end.counterparty().clone();
let connection_counterparty = connection_end.counterparty().clone();
Expand Down
6 changes: 2 additions & 4 deletions crates/cli/cli/src/commands/query/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ impl CommandRunner<HermesApp> for QueryChannels {
let dst_chain_id = self.counterparty_chain_id.clone();
let show_counterparty = self.show_counterparty;

let mut client = QueryClient::connect(chain.grpc_address().clone())
.await
.unwrap();
let mut client = QueryClient::connect(chain.grpc_address().clone()).await?;

let request = tonic::Request::new(QueryChannelsRequest { pagination: None });

let response = client.channels(request).await.unwrap().into_inner();
let response = client.channels(request).await?.into_inner();

let all_channels = response
.channels
Expand Down
6 changes: 2 additions & 4 deletions crates/cli/cli/src/commands/query/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ impl CommandRunner<HermesApp> for QueryConnections {
let counterparty_chain_id = self.counterparty_chain_id.clone();
let verbose = self.verbose;

let mut client = QueryClient::connect(chain.grpc_address().clone())
.await
.unwrap();
let mut client = QueryClient::connect(chain.grpc_address().clone()).await?;

let request = tonic::Request::new(QueryConnectionsRequest { pagination: None });

let response = client.connections(request).await.unwrap().into_inner();
let response = client.connections(request).await?.into_inner();

let all_connections = response
.connections
Expand Down
27 changes: 17 additions & 10 deletions crates/cli/cli/src/commands/query/packet/pending.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::fmt;
use oneline_eyre::eyre::eyre;
use serde::Serialize;

use hermes_chain_components::traits::queries::chain_status::CanQueryChainHeight;
Expand Down Expand Up @@ -134,10 +135,18 @@ impl QueryPendingPackets {

let channel_end = ChannelEnd::decode_vec(&channel_end_bytes)?;

let counterparty_channel_id = channel_end.counterparty().channel_id().unwrap();
let counterparty_channel_id = channel_end.counterparty().channel_id().ok_or_else(|| {
eyre!(
"missing counterparty channel ID for channel `{}`",
channel_id
)
})?;
let counterparty_port_id = channel_end.counterparty().port_id();

let connection_id = channel_end.connection_hops.first().unwrap();
let connection_id = channel_end
.connection_hops
.first()
.ok_or_else(|| eyre!("missing connection ID for channel `{}`", channel_id))?;

// connection end query path
let connection_path = format!("connections/{connection_id}");
Expand All @@ -146,7 +155,7 @@ impl QueryPendingPackets {
.query_abci(IBC_QUERY_PATH, connection_path.as_bytes(), &latest_height)
.await?;

let connection_end = ConnectionEnd::decode_vec(&connnection_end_bytes).unwrap();
let connection_end = ConnectionEnd::decode_vec(&connnection_end_bytes)?;

let client_id = connection_end.client_id();

Expand All @@ -157,7 +166,7 @@ impl QueryPendingPackets {
.query_abci(IBC_QUERY_PATH, client_state_path.as_bytes(), &latest_height)
.await?;

let client_state = AnyClientState::decode_vec(&client_state_bytes).unwrap();
let client_state = AnyClientState::decode_vec(&client_state_bytes)?;

let counterparty_chain_id = client_state.chain_id();
let counterparty_chain = builder.build_chain(&counterparty_chain_id.clone()).await?;
Expand Down Expand Up @@ -189,8 +198,7 @@ impl QueryPendingPackets {
counterparty_port_id,
&commitment_sequences,
)
.await
.unwrap();
.await?;

let unreceived_acknowledgement_sequences = if let Some((acks_on_counterparty, _)) =
acks_and_height_on_counterparty
Expand All @@ -201,7 +209,7 @@ impl QueryPendingPackets {
&port_id,
&acks_on_counterparty,
)
.await.unwrap()
.await?
} else {
Vec::new()
};
Expand Down Expand Up @@ -235,8 +243,7 @@ impl QueryPendingPackets {
&port_id,
&commitment_sequences,
)
.await
.unwrap();
.await?;

let unreceived_acknowledgement_sequences = if let Some((acks_on_counterparty, _)) =
acks_and_height_on_counterparty
Expand All @@ -247,7 +254,7 @@ impl QueryPendingPackets {
counterparty_port_id,
&acks_on_counterparty,
)
.await.unwrap()
.await?
} else {
Vec::new()
};
Expand Down
23 changes: 15 additions & 8 deletions crates/cli/cli/src/commands/query/packet/pending_acks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,25 @@ impl QueryPendingAcks {
.query_abci(IBC_QUERY_PATH, channel_end_path.as_bytes(), &latest_height)
.await?;

let channel_end = ChannelEnd::decode_vec(&channel_end_bytes).unwrap();
let channel_end = ChannelEnd::decode_vec(&channel_end_bytes)?;

// check if channel end is initialized, otherwize return error.
if channel_end.state_matches(&State::Uninitialized) {
return Err(eyre!("channel with id `{channel_id}` is uninitialized").into());
}

let counterparty_channel_id = channel_end.counterparty().channel_id().unwrap();
let counterparty_channel_id = channel_end.counterparty().channel_id().ok_or_else(|| {
eyre!(
"missing counterparty channel ID for channel `{}`",
channel_id
)
})?;
let counterparty_port_id = channel_end.counterparty().port_id();

let connection_id = channel_end.connection_hops.first().unwrap();
let connection_id = channel_end
.connection_hops
.first()
.ok_or_else(|| eyre!("missing connection ID for channel `{}`", channel_id))?;

// connection end query path
let connection_path = format!("connections/{connection_id}");
Expand All @@ -91,7 +99,7 @@ impl QueryPendingAcks {
.query_abci(IBC_QUERY_PATH, connection_path.as_bytes(), &latest_height)
.await?;

let connection_end = ConnectionEnd::decode_vec(&connnection_end_bytes).unwrap();
let connection_end = ConnectionEnd::decode_vec(&connnection_end_bytes)?;

let client_id = connection_end.client_id();

Expand All @@ -102,7 +110,7 @@ impl QueryPendingAcks {
.query_abci(IBC_QUERY_PATH, client_state_path.as_bytes(), &latest_height)
.await?;

let client_state = AnyClientState::decode_vec(&client_state_bytes).unwrap();
let client_state = AnyClientState::decode_vec(&client_state_bytes)?;

let counterparty_chain_id = client_state.chain_id();
let counterparty_chain = builder.build_chain(&counterparty_chain_id.clone()).await?;
Expand All @@ -123,8 +131,7 @@ impl QueryPendingAcks {
counterparty_port_id,
&commitment_sequences,
)
.await
.unwrap();
.await?;

let unreceived_acknowledgement_sequences_and_height = if let Some((
acks_on_counterparty,
Expand All @@ -138,7 +145,7 @@ impl QueryPendingAcks {
&port_id,
&acks_on_counterparty,
)
.await.unwrap(), height))
.await?, height))
} else {
None
};
Expand Down

0 comments on commit e79abf2

Please sign in to comment.