Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove CosmosSdkConfig dependencies #484

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/cli/cli-components/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ hermes-logging-components = { workspace = true }
hermes-test-components = { workspace = true }

cgp = { workspace = true }
http = { workspace = true }
serde = { workspace = true, features = ["derive"] }
toml = { workspace = true }
clap = { workspace = true, features = ["derive"] }
1 change: 1 addition & 0 deletions crates/cli/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ eyre = { workspace = true }
toml = { workspace = true }
oneline-eyre = { workspace = true }
hdpath = { workspace = true }
http = { workspace = true }
humantime = { workspace = true }
tracing = { workspace = true }
tonic = { workspace = true }
Expand Down
16 changes: 8 additions & 8 deletions crates/cli/cli/src/commands/keys/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use hdpath::StandardHDPath;
use hermes_cli_components::traits::build::CanLoadBuilder;
use hermes_cli_framework::command::CommandRunner;
use hermes_cli_framework::output::Output;
use ibc_relayer::chain::cosmos::config::CosmosSdkConfig;
use hermes_cosmos_chain_components::impls::types::config::CosmosChainConfig;
use ibc_relayer::keyring::{
AnySigningKeyPair, KeyRing, Secp256k1KeyPair, SigningKeyPair, SigningKeyPairSized, Store,
};
Expand Down Expand Up @@ -94,7 +94,7 @@ pub struct KeysAddCmd {
}

impl KeysAddCmd {
fn options(&self, chain_config: &CosmosSdkConfig) -> eyre::Result<KeysAddOptions> {
fn options(&self, chain_config: &CosmosChainConfig) -> eyre::Result<KeysAddOptions> {
let name = self
.key_name
.clone()
Expand All @@ -114,12 +114,12 @@ impl KeysAddCmd {
#[derive(Clone, Debug)]
pub struct KeysAddOptions {
pub name: String,
pub config: CosmosSdkConfig,
pub config: CosmosChainConfig,
pub hd_path: StandardHDPath,
}

pub fn add_key(
config: &CosmosSdkConfig,
config: &CosmosChainConfig,
key_name: &str,
file: &Path,
hd_path: &StandardHDPath,
Expand All @@ -128,7 +128,7 @@ pub fn add_key(
let mut keyring = KeyRing::new_secp256k1(
Store::Test,
&config.account_prefix,
&config.id,
&ChainId::from_string(&config.id),
&config.key_store_folder,
)?;

Expand All @@ -146,7 +146,7 @@ pub fn restore_key(
mnemonic: &Path,
key_name: &str,
hdpath: &StandardHDPath,
config: &CosmosSdkConfig,
config: &CosmosChainConfig,
overwrite: bool,
) -> eyre::Result<AnySigningKeyPair> {
let mnemonic_content =
Expand All @@ -155,7 +155,7 @@ pub fn restore_key(
let mut keyring = KeyRing::new_secp256k1(
Store::Test,
&config.account_prefix,
&config.id,
&ChainId::from_string(&config.id),
&config.key_store_folder,
)?;

Expand All @@ -164,7 +164,7 @@ pub fn restore_key(
let key_pair = Secp256k1KeyPair::from_mnemonic(
&mnemonic_content,
hdpath,
&config.address_type,
&ibc_relayer::config::AddressType::Cosmos,
keyring.account_prefix(),
)?;

Expand Down
14 changes: 7 additions & 7 deletions crates/cli/cli/src/commands/keys/delete.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use hermes_cli_components::traits::build::CanLoadBuilder;
use hermes_cli_framework::command::CommandRunner;
use hermes_cli_framework::output::Output;
use ibc_relayer::chain::cosmos::config::CosmosSdkConfig;
use hermes_cosmos_chain_components::impls::types::config::CosmosChainConfig;
use ibc_relayer::keyring::{KeyRing, Store};
use ibc_relayer_types::core::ics24_host::identifier::ChainId;
use oneline_eyre::eyre::{eyre, Context};
Expand Down Expand Up @@ -46,7 +46,7 @@ pub struct KeysDeleteCmd {
}

impl KeysDeleteCmd {
fn options(&self, config: &CosmosSdkConfig) -> eyre::Result<KeysDeleteOptions<'_>> {
fn options(&self, config: &CosmosChainConfig) -> eyre::Result<KeysDeleteOptions<'_>> {
let id = match (self.all, &self.key_name) {
(true, None) => KeysDeleteId::All,
(false, Some(ref key_name)) => KeysDeleteId::Named(key_name),
Expand All @@ -67,7 +67,7 @@ impl KeysDeleteCmd {
#[derive(Clone, Debug)]
struct KeysDeleteOptions<'a> {
id: KeysDeleteId<'a>,
config: CosmosSdkConfig,
config: CosmosChainConfig,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -118,11 +118,11 @@ impl CommandRunner<HermesApp> for KeysDeleteCmd {
}
}

fn delete_key(config: &CosmosSdkConfig, key_name: &str) -> eyre::Result<()> {
fn delete_key(config: &CosmosChainConfig, key_name: &str) -> eyre::Result<()> {
let mut keyring = KeyRing::new_secp256k1(
Store::Test,
&config.account_prefix,
&config.id,
&ChainId::from_string(&config.id),
&config.key_store_folder,
)?;

Expand All @@ -131,11 +131,11 @@ fn delete_key(config: &CosmosSdkConfig, key_name: &str) -> eyre::Result<()> {
Ok(())
}

fn delete_all_keys(config: &CosmosSdkConfig) -> eyre::Result<()> {
fn delete_all_keys(config: &CosmosChainConfig) -> eyre::Result<()> {
let mut keyring = KeyRing::new_secp256k1(
Store::Test,
&config.account_prefix,
&config.id,
&ChainId::from_string(&config.id),
&config.key_store_folder,
)?;

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/cli/src/commands/keys/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl CommandRunner<HermesApp> for KeysListCmd {
let keyring = KeyRing::new_secp256k1(
Store::Test,
&chain_config.account_prefix,
&chain_config.id,
&ChainId::from_string(&chain_config.id),
&chain_config.key_store_folder,
)?;

Expand Down
4 changes: 3 additions & 1 deletion crates/cli/cli/src/commands/query/channel/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use hermes_cli_components::traits::build::CanLoadBuilder;
use hermes_cli_framework::command::CommandRunner;
use hermes_cli_framework::output::Output;
use hermes_cosmos_chain_components::traits::grpc_address::HasGrpcAddress;
use http::Uri;
use ibc::core::channel::types::proto::v1::query_client::QueryClient;
use ibc::core::channel::types::proto::v1::QueryChannelClientStateRequest;
use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ChannelId, PortId};
Expand Down Expand Up @@ -47,7 +48,8 @@ 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?;
let mut client =
QueryClient::connect(Uri::try_from(&chain.grpc_address().to_string())?).await?;

let request = tonic::Request::new(QueryChannelClientStateRequest {
port_id: port_id.to_string(),
Expand Down
4 changes: 3 additions & 1 deletion crates/cli/cli/src/commands/query/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use hermes_cli_framework::output::{json, Output};
use hermes_cosmos_chain_components::traits::grpc_address::HasGrpcAddress;
use hermes_cosmos_relayer::contexts::chain::CosmosChain;
use hermes_relayer_components::chain::traits::queries::chain_status::CanQueryChainHeight;
use http::Uri;
use ibc::core::channel::types::proto::v1::query_client::QueryClient;
use ibc::core::channel::types::proto::v1::QueryChannelsRequest;
use ibc_relayer_types::core::ics04_channel::channel::{IdentifiedChannelEnd, State};
Expand Down Expand Up @@ -52,7 +53,8 @@ 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?;
let mut client =
QueryClient::connect(Uri::try_from(&chain.grpc_address().to_string())?).await?;

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

Expand Down
4 changes: 3 additions & 1 deletion crates/cli/cli/src/commands/query/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use hermes_cli_framework::output::{json, Output};
use hermes_cosmos_chain_components::traits::grpc_address::HasGrpcAddress;
use hermes_cosmos_relayer::contexts::chain::CosmosChain;
use hermes_relayer_components::chain::traits::queries::client_state::CanQueryClientStateWithLatestHeight;
use http::Uri;
use ibc::core::connection::types::proto::v1::query_client::QueryClient;
use ibc::core::connection::types::proto::v1::QueryConnectionsRequest;
use ibc_relayer_types::core::ics02_client::client_state::ClientState;
Expand Down Expand Up @@ -50,7 +51,8 @@ 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?;
let mut client =
QueryClient::connect(Uri::try_from(&chain.grpc_address().to_string())?).await?;

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

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/cli/src/impls/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ where
.into_iter()
.map(|config| {
let ChainConfig::CosmosSdk(config) = config;
config
config.into()
})
.collect();

Expand Down
2 changes: 2 additions & 0 deletions crates/cli/cli/src/impls/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use ibc_relayer_types::core::ics02_client::height::HeightError;
use ibc_relayer_types::core::ics03_connection::error::Error as Ics03Error;
use ibc_relayer_types::core::ics23_commitment::error::Error as Ics23Error;
use ibc_relayer_types::core::ics24_host::error::ValidationError as Ics24ValidationError;
use tonic::transport::Error as TransportError;

pub struct ProvideCliError;

Expand Down Expand Up @@ -59,6 +60,7 @@ delegate_components! {
Ics03Error,
Ics23Error,
Ics24ValidationError,
TransportError,
]: ReportError,
[
<'a> &'a str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use cgp::core::error::CanRaiseError;
use hermes_relayer_components::chain::traits::queries::consensus_state_height::ConsensusStateHeightsQuerier;
use hermes_relayer_components::chain::traits::types::height::HasHeightType;
use hermes_relayer_components::chain::traits::types::ibc::HasIbcChainTypes;
use http::uri::InvalidUri;
use http::Uri;
use ibc_proto::ibc::core::client::v1::query_client::QueryClient;
use ibc_relayer::chain::requests::QueryConsensusStateHeightsRequest;
use ibc_relayer_types::core::ics24_host::identifier::ClientId;
Expand All @@ -19,17 +21,20 @@ where
Chain: HasIbcChainTypes<Counterparty, ClientId = ClientId>
+ HasGrpcAddress
+ CanRaiseError<TransportError>
+ CanRaiseError<InvalidUri>
+ CanRaiseError<Status>,
Counterparty: HasHeightType<Height = Height>,
{
async fn query_consensus_state_heights(
chain: &Chain,
client_id: &ClientId,
) -> Result<Vec<Height>, Chain::Error> {
let mut client = QueryClient::connect(chain.grpc_address().clone())
.await
.map_err(Chain::raise_error)?
.max_decoding_message_size(33554432);
let mut client = QueryClient::connect(
Uri::try_from(&chain.grpc_address().to_string()).map_err(Chain::raise_error)?,
)
.await
.map_err(Chain::raise_error)?
.max_decoding_message_size(33554432);

let request = QueryConsensusStateHeightsRequest {
client_id: client_id.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ use cgp::core::error::CanRaiseError;
use eyre::eyre;
use hermes_relayer_components::chain::traits::queries::packet_acknowledgements::PacketAcknowledgementsQuerier;
use hermes_relayer_components::chain::traits::types::ibc::HasIbcChainTypes;
use http::uri::InvalidUri;
use http::Uri;
use ibc_proto::ibc::core::channel::v1::query_client::QueryClient as ChannelQueryClient;
use ibc_relayer::chain::requests::{Paginate, QueryPacketAcknowledgementsRequest};
use ibc_relayer_types::core::ics02_client::error::Error as Ics02Error;
use ibc_relayer_types::core::ics04_channel::packet::Sequence;
use ibc_relayer_types::core::ics24_host::identifier::{ChannelId, PortId};
use ibc_relayer_types::Height;
use tonic::Request;
use tonic::transport::Error as TransportError;
use tonic::{Request, Status};

use crate::traits::grpc_address::HasGrpcAddress;

Expand All @@ -25,6 +29,10 @@ where
ChannelId = ChannelId,
Sequence = Sequence,
> + HasGrpcAddress
+ CanRaiseError<InvalidUri>
+ CanRaiseError<TransportError>
+ CanRaiseError<Status>
+ CanRaiseError<Ics02Error>
+ CanRaiseError<eyre::Report>,
Counterparty: HasIbcChainTypes<Chain, Sequence = Sequence, Height = Height>,
{
Expand All @@ -34,9 +42,11 @@ where
port_id: &Chain::PortId,
sequences: &[Counterparty::Sequence],
) -> Result<Option<(Vec<Counterparty::Sequence>, Chain::Height)>, Chain::Error> {
let mut client = ChannelQueryClient::connect(chain.grpc_address().clone())
.await
.map_err(|e| Chain::raise_error(e.into()))?;
let mut client = ChannelQueryClient::connect(
Uri::try_from(&chain.grpc_address().to_string()).map_err(Chain::raise_error)?,
)
.await
.map_err(Chain::raise_error)?;

let raw_request = QueryPacketAcknowledgementsRequest {
port_id: port_id.clone(),
Expand All @@ -50,7 +60,7 @@ where
let response = client
.packet_acknowledgements(request)
.await
.map_err(|e| Chain::raise_error(e.into()))?
.map_err(Chain::raise_error)?
.into_inner();

let commit_set = sequences.iter().cloned().collect::<HashSet<_>>();
Expand All @@ -68,7 +78,7 @@ where
.height
.ok_or_else(|| Chain::raise_error(eyre!("missing height in response")))?;

let height = Height::try_from(raw_height).map_err(|e| Chain::raise_error(e.into()))?;
let height = Height::try_from(raw_height).map_err(Chain::raise_error)?;

Ok(Some((response_acks, height)))
}
Expand Down
Loading
Loading