Skip to content

Commit

Permalink
relayer: lift keys to ChainConfig::list_keys
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor committed Oct 14, 2023
1 parent b1a39d7 commit c158cba
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
3 changes: 1 addition & 2 deletions crates/relayer-cli/src/commands/config/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ use abscissa_core::{Command, Runnable};
use crate::conclude::Output;

use ibc_relayer::config::{store, ChainConfig, Config};
use ibc_relayer::keyring::list_keys;

use std::collections::HashSet;
use std::path::PathBuf;
use tracing::{info, warn};

fn find_key(chain_config: &ChainConfig) -> Option<String> {
let keys = list_keys(chain_config).ok()?;
let keys = chain_config.list_keys().ok()?;
keys.into_iter().next().map(|(name, _)| name)
}

Expand Down
7 changes: 2 additions & 5 deletions crates/relayer-cli/src/commands/keys/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use abscissa_core::{Command, Runnable};

use crate::conclude::Output;
use crate::{application::app_config, conclude::json};
use ibc_relayer::{
config::{ChainConfig, Config},
keyring::list_keys,
};
use ibc_relayer::config::{ChainConfig, Config};
use ibc_relayer_types::core::ics24_host::identifier::ChainId;

#[derive(Clone, Command, Debug, Parser, PartialEq, Eq)]
Expand Down Expand Up @@ -45,7 +42,7 @@ impl Runnable for KeysListCmd {
Ok(result) => result,
};

match list_keys(&opts.chain_config) {
match opts.chain_config.list_keys() {
Ok(keys) if json() => {
let keys = keys.into_iter().collect::<HashMap<_, _>>();
Output::success(keys).exit()
Expand Down
29 changes: 27 additions & 2 deletions crates/relayer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ use ibc_relayer_types::core::ics23_commitment::specs::ProofSpecs;
use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ChannelId, PortId};
use ibc_relayer_types::timestamp::ZERO_DURATION;

use crate::config::gas_multiplier::GasMultiplier;
use crate::config::types::{MaxMsgNum, MaxTxSize, Memo};
use crate::error::Error as RelayerError;
use crate::extension_options::ExtensionOptionDynamicFeeTx;
use crate::keyring::Store;
use crate::{
config::gas_multiplier::GasMultiplier,
keyring::{AnySigningKeyPair, KeyRing},
};
use crate::{
config::types::{MaxMsgNum, MaxTxSize, Memo},
keyring,
};

pub use crate::config::Error as ConfigError;
pub use error::Error;
Expand Down Expand Up @@ -586,6 +592,25 @@ impl ChainConfig {
Self::CosmosSdk(config) => config.key_name = key_name,
}
}

pub fn list_keys(&self) -> Result<Vec<(String, AnySigningKeyPair)>, keyring::errors::Error> {
let keys = match self {
ChainConfig::CosmosSdk(config) => {
let keyring = KeyRing::new_secp256k1(
Store::Test,
&config.account_prefix,
&config.id,
&config.key_store_folder,
)?;
keyring
.keys()?
.into_iter()
.map(|(key_name, keys)| (key_name, keys.into()))
.collect()
}
};
Ok(keys)
}
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
Expand Down
19 changes: 0 additions & 19 deletions crates/relayer/src/keyring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use std::path::PathBuf;
use ibc_relayer_types::core::ics24_host::identifier::ChainId;
use serde::{Deserialize, Serialize};

use crate::config::ChainConfig;
use errors::Error;

pub const KEYSTORE_DEFAULT_FOLDER: &str = ".hermes/keys/";
Expand Down Expand Up @@ -288,24 +287,6 @@ impl KeyRing<Ed25519KeyPair> {
}

// Why is this not a method on `ChainConfig`?
pub fn list_keys(config: &ChainConfig) -> Result<Vec<(String, AnySigningKeyPair)>, Error> {
let keys = match config {
ChainConfig::CosmosSdk(config) => {
let keyring = KeyRing::new_secp256k1(
Store::Test,
&config.account_prefix,
&config.id,
&config.key_store_folder,
)?;
keyring
.keys()?
.into_iter()
.map(|(key_name, keys)| (key_name, keys.into()))
.collect()
}
};
Ok(keys)
}

fn disk_store_path(folder_name: &str, keystore_folder: &Option<PathBuf>) -> Result<PathBuf, Error> {
let ks_folder = match keystore_folder {
Expand Down

0 comments on commit c158cba

Please sign in to comment.