diff --git a/crates/apps_lib/src/cli.rs b/crates/apps_lib/src/cli.rs index 3481a911259..80d69a98a9b 100644 --- a/crates/apps_lib/src/cli.rs +++ b/crates/apps_lib/src/cli.rs @@ -33,6 +33,7 @@ const WALLET_CMD: &str = "wallet"; const RELAYER_CMD: &str = "relayer"; pub mod cmds { + use super::args::CliTypes; use super::utils::*; use super::{ args, ArgMatches, CLIENT_CMD, NODE_CMD, RELAYER_CMD, WALLET_CMD, @@ -3130,21 +3131,21 @@ pub mod cmds { } #[derive(Clone, Debug)] - pub struct SignOffline(pub args::SignOffline); + pub struct SignOffline(pub args::SignOffline); impl SubCmd for SignOffline { const CMD: &'static str = "sign-offline"; fn parse(matches: &ArgMatches) -> Option { - matches - .subcommand_matches(Self::CMD) - .map(|matches| Self(args::SignOffline::parse(matches))) + matches.subcommand_matches(Self::CMD).map(|matches| { + Self(args::SignOffline::::parse(matches)) + }) } fn def() -> App { App::new(Self::CMD) .about(wrap!("Offlne sign a transaction.")) - .add_args::() + .add_args::>() } } @@ -3403,7 +3404,7 @@ pub mod args { DefaultFn(|| PortId::from_str("transfer").unwrap()), ); pub const PRE_GENESIS: ArgFlag = flag("pre-genesis"); - pub const PRIVATE_KEYS: ArgMulti = + pub const PRIVATE_KEYS: ArgMulti = arg_multi("secret-keys"); pub const PROPOSAL_PGF_STEWARD: ArgFlag = flag("pgf-stewards"); pub const PROPOSAL_PGF_FUNDING: ArgFlag = flag("pgf-funding"); @@ -7945,18 +7946,18 @@ pub mod args { } #[derive(Clone, Debug)] - pub struct SignOffline { + pub struct SignOffline { pub tx_path: PathBuf, - pub secret_keys: Vec, - pub owner: Address, + pub secret_keys: Vec, + pub owner: C::Address, pub output_folder_path: Option, } - impl Args for SignOffline { + impl Args for SignOffline { fn parse(matches: &ArgMatches) -> Self { let tx_path = DATA_PATH.parse(matches); let secret_keys = PRIVATE_KEYS.parse(matches); - let owner = RAW_ADDRESS.parse(matches); + let owner = OWNER.parse(matches); let output_folder_path = OUTPUT_FOLDER_PATH.parse(matches); Self { @@ -7977,7 +7978,7 @@ pub mod args { "The set of private keys to use to sign the transaction. The \ order matters." ))) - .arg(RAW_ADDRESS.def().help(wrap!("The owner's address."))) + .arg(OWNER.def().help(wrap!("The owner's address."))) .arg( OUTPUT_FOLDER_PATH .def() @@ -7986,6 +7987,28 @@ pub mod args { } } + impl CliToSdk> for SignOffline { + type Error = std::io::Error; + + fn to_sdk( + self, + ctx: &mut Context, + ) -> Result, Self::Error> { + let chain_ctx = ctx.borrow_mut_chain_or_exit(); + + Ok(SignOffline:: { + tx_path: self.tx_path, + secret_keys: self + .secret_keys + .iter() + .map(|key| chain_ctx.get_cached(key)) + .collect(), + owner: chain_ctx.get(&self.owner), + output_folder_path: self.output_folder_path, + }) + } + } + #[derive(Clone, Debug)] pub struct DefaultBaseDir {} diff --git a/crates/apps_lib/src/cli/client.rs b/crates/apps_lib/src/cli/client.rs index 73d491d107d..45b954551c4 100644 --- a/crates/apps_lib/src/cli/client.rs +++ b/crates/apps_lib/src/cli/client.rs @@ -793,7 +793,10 @@ impl CliApi { utils::pk_to_tm_address(global_args, args) } ClientUtils::SignOffline(SignOffline(args)) => { - utils::sign_offline(global_args, args).await + let mut ctx = cli::Context::new::(global_args) + .expect("expected to construct a context"); + let args = args.to_sdk(&mut ctx)?; + utils::sign_offline(args).await } ClientUtils::DefaultBaseDir(DefaultBaseDir(args)) => { utils::default_base_dir(global_args, args) diff --git a/crates/apps_lib/src/client/utils.rs b/crates/apps_lib/src/client/utils.rs index 95f54c4ce78..6a227ea3625 100644 --- a/crates/apps_lib/src/client/utils.rs +++ b/crates/apps_lib/src/client/utils.rs @@ -1035,7 +1035,6 @@ pub async fn sign_genesis_tx( /// Offline sign a transactions. pub async fn sign_offline( - _global_args: args::Global, args::SignOffline { tx_path, secret_keys, diff --git a/crates/tests/src/integration/ledger_tests.rs b/crates/tests/src/integration/ledger_tests.rs index 18c6478a0b9..ea0e35a066f 100644 --- a/crates/tests/src/integration/ledger_tests.rs +++ b/crates/tests/src/integration/ledger_tests.rs @@ -1594,7 +1594,7 @@ fn offline_sign() -> Result<()> { "sign-offline", "--data-path", &offline_tx, - "--address", + "--owner", &bertha_address, "--secret-keys", &bertha_sk,