Cli: Add resolve-signer subcommand (#8859) (#8870)

automerge
This commit is contained in:
mergify[bot]
2020-03-14 22:14:24 -07:00
committed by GitHub
parent b0cf65dfc8
commit 27e4e9cb8d
6 changed files with 179 additions and 5 deletions

View File

@@ -391,6 +391,7 @@ pub enum CliCommand {
Cancel(Pubkey),
Confirm(Signature),
Pay(PayCommand),
ResolveSigner(Option<String>),
ShowAccount {
pubkey: Pubkey,
output_file: Option<String>,
@@ -859,6 +860,13 @@ pub fn parse_command(
signers: vec![],
})
}
("resolve-signer", Some(matches)) => {
let signer_path = resolve_signer(matches, "signer", wallet_manager)?;
Ok(CliCommandInfo {
command: CliCommand::ResolveSigner(signer_path),
signers: vec![],
})
}
("send-signature", Some(matches)) => {
let to = value_of(matches, "to").unwrap();
let process_id = value_of(matches, "process_id").unwrap();
@@ -2020,6 +2028,13 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
*nonce_account,
*nonce_authority,
),
CliCommand::ResolveSigner(path) => {
if let Some(path) = path {
Ok(path.to_string())
} else {
Ok("Signer is valid".to_string())
}
}
CliCommand::ShowAccount {
pubkey,
output_file,
@@ -2374,6 +2389,19 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, '
.arg(nonce_arg())
.arg(nonce_authority_arg()),
)
.subcommand(
SubCommand::with_name("resolve-signer")
.about("Checks that a signer is valid, and returns its specific path; useful for signers that may be specified generally, eg. usb://ledger")
.arg(
Arg::with_name("signer")
.index(1)
.value_name("KEYPAIR or PUBKEY or REMOTE WALLET PATH")
.takes_value(true)
.required(true)
.validator(is_valid_signer)
.help("The signer path to resolve")
)
)
.subcommand(
SubCommand::with_name("send-signature")
.about("Send a signature to authorize a transfer")
@@ -2752,6 +2780,31 @@ mod tests {
}
);
// Test ResolveSigner Subcommand, KeypairUrl::Filepath
let test_resolve_signer =
test_commands
.clone()
.get_matches_from(vec!["test", "resolve-signer", &keypair_file]);
assert_eq!(
parse_command(&test_resolve_signer, "", None).unwrap(),
CliCommandInfo {
command: CliCommand::ResolveSigner(Some(keypair_file.clone())),
signers: vec![],
}
);
// Test ResolveSigner Subcommand, KeypairUrl::Pubkey (Presigner)
let test_resolve_signer =
test_commands
.clone()
.get_matches_from(vec!["test", "resolve-signer", &pubkey_string]);
assert_eq!(
parse_command(&test_resolve_signer, "", None).unwrap(),
CliCommandInfo {
command: CliCommand::ResolveSigner(Some(pubkey.to_string())),
signers: vec![],
}
);
// Test Simple Pay Subcommand
let test_pay =
test_commands