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

Add Namada key to the store #15

Merged
merged 4 commits into from
Nov 10, 2023
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
16 changes: 14 additions & 2 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/relayer-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ tokio = { version = "1.0", features = ["full"] }
tracing = "0.1.36"
tracing-subscriber = { version = "0.3.14", features = ["fmt", "env-filter", "json"]}
time = "0.3"

[dependencies.tendermint]
version = "0.34.0"
features = ["secp256k1"]
Expand Down
46 changes: 42 additions & 4 deletions crates/relayer-cli/src/commands/keys/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ use abscissa_core::{Command, Runnable};
use eyre::eyre;
use hdpath::StandardHDPath;
use ibc_relayer::{
chain::namada::wallet::CliWalletUtils,
config::{ChainConfig, Config},
keyring::{
AnySigningKeyPair, KeyRing, Secp256k1KeyPair, SigningKeyPair, SigningKeyPairSized, Store,
AnySigningKeyPair, KeyRing, NamadaKeyPair, Secp256k1KeyPair, SigningKeyPair,
SigningKeyPairSized, Store,
},
};
use ibc_relayer_types::core::ics24_host::identifier::ChainId;
Expand Down Expand Up @@ -220,8 +222,42 @@ pub fn add_key(
keyring.add_key(key_name, key_pair.clone())?;
key_pair.into()
}
ChainConfig::Namada(_) => {
return Err(eyre!("Namada key cannot be added"));
ChainConfig::Namada(config) => {
let mut keyring =
KeyRing::new_namada(Store::Test, &config.id, &config.key_store_folder)?;

check_key_exists(&keyring, key_name, overwrite);

let path = if file.is_file() {
file.parent().ok_or(eyre!("invalid Namada wallet path"))?
} else {
file
};
let mut wallet = CliWalletUtils::new(path.to_path_buf());
wallet
.load()
.map_err(|_| eyre!("error loading Namada wallet"))?;

let keys = wallet.get_keys();
let (secret_key, pkh) = keys
.get(key_name)
.ok_or_else(|| eyre!("error loading the key from Namada wallet"))?;
let secret_key = secret_key
.get::<CliWalletUtils>(true, None)
.map_err(|_| eyre!("error loading the key from Namada wallet"))?;
let pkh =
pkh.ok_or_else(|| eyre!("error loading the public key hash from Namada wallet"))?;
let address = wallet
.find_address(key_name)
.ok_or_else(|| eyre!("error loading the address from Namada wallet"))?;
let namada_key = NamadaKeyPair {
alias: key_name.to_string(),
address: address.into_owned(),
pkh: pkh.clone(),
secret_key: secret_key.clone(),
};
keyring.add_key(key_name, namada_key.clone())?;
namada_key.into()
}
};

Expand Down Expand Up @@ -260,7 +296,9 @@ pub fn restore_key(
key_pair.into()
}
ChainConfig::Namada(_) => {
return Err(eyre!("Namada key cannot be restored"));
return Err(eyre!(
"Namada key can't be restored here. Use Namada wallet."
));
}
};

Expand Down
15 changes: 11 additions & 4 deletions crates/relayer-cli/src/commands/keys/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ pub fn delete_key(config: &ChainConfig, key_name: &str) -> eyre::Result<()> {
)?;
keyring.remove_key(key_name)?;
}
ChainConfig::Namada(_) => {
return Err(eyre!("Namada key cannot be deleted"));
ChainConfig::Namada(config) => {
let mut keyring =
KeyRing::new_namada(Store::Test, &config.id, &config.key_store_folder)?;
keyring.remove_key(key_name)?;
}
}
Ok(())
Expand All @@ -144,8 +146,13 @@ pub fn delete_all_keys(config: &ChainConfig) -> eyre::Result<()> {
keyring.remove_key(&key_name)?;
}
}
ChainConfig::Namada(_) => {
return Err(eyre!("Namada key cannot be deleted"));
ChainConfig::Namada(config) => {
let mut keyring =
KeyRing::new_namada(Store::Test, &config.id, &config.key_store_folder)?;
let keys = keyring.keys()?;
for (key_name, _) in keys {
keyring.remove_key(&key_name)?;
}
}
}
Ok(())
Expand Down
1 change: 1 addition & 0 deletions crates/relayer-rest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ tokio = "1.26"

[dev-dependencies]
reqwest = { version = "0.11.16", features = ["json"], default-features = false }
serde_json = "1"
toml = "0.7.3"
5 changes: 4 additions & 1 deletion crates/relayer-rest/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ where
let response = reqwest::get(&format!("http://127.0.0.1:{port}{path}"))
.await
.unwrap()
.json::<R>()
.json()
.await
.unwrap();
// Workaround for serde_json deserialization failure
// from_str/from_slice() failed for ChainConfig
let response = serde_json::from_value::<R>(response).unwrap();

assert_eq!(response, expected);

Expand Down
13 changes: 10 additions & 3 deletions crates/relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ ibc-proto = { version = "0.38.0", features = ["serde"] }
ibc-telemetry = { version = "0.26.0", path = "../telemetry", optional = true }
ibc-relayer-types = { version = "0.26.0", path = "../relayer-types", features = ["mocks"] }

namada = { git = "https://github.com/anoma/namada", rev = "7116b6aa916026e97f3f871f291c6ba1c7b427d2" }
namada_sdk = { git = "https://github.com/anoma/namada", rev = "7116b6aa916026e97f3f871f291c6ba1c7b427d2", features = ["std", "async-client"] }

subtle-encoding = "0.5"
humantime-serde = "1.1.1"
serde = "1.0"
Expand Down Expand Up @@ -73,6 +70,7 @@ strum = { version = "0.25", features = ["derive"] }
tokio-stream = "0.1.14"
once_cell = "1.17.1"
tracing-subscriber = { version = "0.3.14", features = ["fmt", "env-filter", "json"] }
rpassword = "5.0.1"

[dependencies.byte-unit]
version = "4.0.19"
Expand Down Expand Up @@ -111,6 +109,15 @@ default-features = false
version = "0.34.0"
default-features = false

[dependencies.namada]
git = "https://github.com/anoma/namada"
rev = "7116b6aa916026e97f3f871f291c6ba1c7b427d2"

[dependencies.namada_sdk]
git = "https://github.com/anoma/namada"
rev = "7116b6aa916026e97f3f871f291c6ba1c7b427d2"
features = ["std", "async-client"]

[dev-dependencies]
ibc-relayer-types = { version = "0.26.0", path = "../relayer-types", features = ["mocks"] }
serial_test = "2.0.0"
Expand Down
Loading
Loading