-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added keys restore command boileplate for abscissa. Restore key funct…
…ionality not implemented yet #47
- Loading branch information
Showing
9 changed files
with
133 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//! `keys` subcommand | ||
use abscissa_core::{Command, Help, Options, Runnable}; | ||
|
||
mod restore; | ||
|
||
/// `keys` subcommand | ||
#[derive(Command, Debug, Options, Runnable)] | ||
pub enum KeysCmd { | ||
/// The `help` subcommand | ||
#[options(help = "get usage information")] | ||
Help(Help<Self>), | ||
|
||
/// The `keys restore` subcommand | ||
#[options(help = "keys restore")] | ||
Restore(restore::KeyRestoreCmd), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use crate::application::app_config; | ||
use abscissa_core::{Command, Options, Runnable}; | ||
use relayer::config::Config; | ||
|
||
use crate::error::{Error, Kind}; | ||
use crate::prelude::*; | ||
use relayer::crypto::keybase::{restore_key, KeysRestoreOptions}; | ||
|
||
#[derive(Clone, Command, Debug, Options)] | ||
pub struct KeyRestoreCmd { | ||
#[options(free, help = "identifier of the chain")] | ||
chain_id: Option<String>, | ||
|
||
#[options(free, help = "the key name")] | ||
name: Option<String>, | ||
|
||
#[options(free, help = "mnemonic to add key")] | ||
mnemonic: Option<String>, | ||
} | ||
|
||
impl KeyRestoreCmd { | ||
fn validate_options(&self, config: &Config) -> Result<KeysRestoreOptions, String> { | ||
let chain_id = self | ||
.chain_id | ||
.clone() | ||
.ok_or_else(|| "missing chain identifier".to_string())?; | ||
|
||
let chain_config = config | ||
.chains | ||
.iter() | ||
.find(|c| c.id == chain_id.parse().unwrap()) | ||
.ok_or_else(|| "missing chain configuration".to_string())?; | ||
|
||
let key_name = self | ||
.name | ||
.clone() | ||
.ok_or_else(|| "missing key name".to_string())?; | ||
|
||
let mnemonic_words = self | ||
.name | ||
.clone() | ||
.ok_or_else(|| "missing mnemonic".to_string())?; | ||
|
||
Ok(KeysRestoreOptions { | ||
name: key_name, | ||
mnemonic: mnemonic_words, | ||
chain_config: chain_config.clone(), | ||
}) | ||
} | ||
} | ||
|
||
impl Runnable for KeyRestoreCmd { | ||
fn run(&self) { | ||
let config = app_config(); | ||
|
||
let opts = match self.validate_options(&config) { | ||
Err(err) => { | ||
status_err!("invalid options: {}", err); | ||
return; | ||
} | ||
Ok(result) => result, | ||
}; | ||
|
||
let res: Result<(), Error> = restore_key(opts).map_err(|e| Kind::Keys.context(e).into()); | ||
|
||
match res { | ||
Ok(r) => status_info!("keys store, result: ", "{:?}", r), | ||
Err(e) => status_info!("keys store failed, error: ", "{}", e), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod keybase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::chain::CosmosSDKChain; | ||
use crate::config::ChainConfig; | ||
use crate::error::{Error, Kind}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct KeysRestoreOptions { | ||
pub name: String, | ||
pub mnemonic: String, | ||
pub chain_config: ChainConfig, | ||
} | ||
|
||
pub fn restore_key(opts: KeysRestoreOptions) -> Result<(), Error> { | ||
// Get the destination chain | ||
let chain = CosmosSDKChain::from_config(opts.clone().chain_config)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters