Revert "Improve missing default signer error messaging (#17486)"

This reverts commit 6d40d0d141.
This commit is contained in:
Trent Nelson
2021-05-27 18:04:48 -06:00
committed by Trent Nelson
parent 831e87c65d
commit ca8c1c6c42
8 changed files with 66 additions and 37 deletions

View File

@ -89,33 +89,13 @@ impl CliSignerInfo {
.collect()
}
}
#[derive(Debug)]
pub struct DefaultSigner {
pub arg_name: String,
pub path: String,
}
impl DefaultSigner {
pub fn new(path: String) -> Self {
Self {
arg_name: "keypair".to_string(),
path,
}
}
pub fn from_path(path: String) -> Result<Self, Box<dyn error::Error>> {
std::fs::metadata(&path)
.map_err(|_| {
std::io::Error::new(
std::io::ErrorKind::Other,
format!(
"No default signer found, run \"solana-keygen new -o {}\" to create a new one",
path
),
)
.into()
})
.map(|_| Self::new(path))
}
pub fn generate_unique_signers(
&self,
bulk_signers: Vec<Option<Box<dyn Signer>>>,
@ -277,7 +257,9 @@ pub(crate) fn parse_signer_source<S: AsRef<str>>(
ASK_KEYWORD => Ok(SignerSource::new_legacy(SignerSourceKind::Prompt)),
_ => match Pubkey::from_str(source.as_str()) {
Ok(pubkey) => Ok(SignerSource::new(SignerSourceKind::Pubkey(pubkey))),
Err(_) => Ok(SignerSource::new(SignerSourceKind::Filepath(source))),
Err(_) => std::fs::metadata(source.as_str())
.map(|_| SignerSource::new(SignerSourceKind::Filepath(source)))
.map_err(|err| err.into()),
},
}
}
@ -751,6 +733,10 @@ mod tests {
// Catchall into SignerSource::Filepath fails
let junk = "sometextthatisnotapubkeyorfile".to_string();
assert!(Pubkey::from_str(&junk).is_err());
assert!(matches!(
parse_signer_source(&junk),
Err(SignerSourceError::IoError(_))
));
let prompt = "prompt:".to_string();
assert!(matches!(