Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ffc82f3
Don't use move semantics if not needed (#8793)
jackcmay Mar 11, 2020
4596ce3
SDK: Deboilerplate `TransportError` with thiserror
t-nelson Mar 10, 2020
e2cb9bf
Enable interchange between `TransportError` and `ClientError`
t-nelson Mar 10, 2020
c63389e
SDK: Retval consistency between `Client` and `AsyncClient` traits
t-nelson Mar 10, 2020
3ecc913
Client: Introduce/use `Result` type
t-nelson Mar 10, 2020
8afb187
Client: Remove unused `RpcResponseIn` type
t-nelson Mar 10, 2020
e8806d0
Client: Rename `RpcResponse` to more appropriate `RpcResult`
t-nelson Mar 10, 2020
5389168
Client: Death to `io::Result` return types
t-nelson Mar 11, 2020
e029f57
Client: Struct-ify `ClientError`
t-nelson Mar 11, 2020
cc53f94
Client: Add optional `command` parameter to `ClientError`
t-nelson Mar 11, 2020
432a5af
RpcClient: Stop abusing `io::Error` (low-fruit)
t-nelson Mar 11, 2020
2776cff
ClientError: Use `thiserror`'s `Display` impl
t-nelson Mar 11, 2020
f229d66
Extend `RpcError`'s utility
t-nelson Mar 12, 2020
3e41efd
RpcClient: Stop abusing `io::Error` (the rest)
t-nelson Mar 12, 2020
8a603ac
CLI: Shim `main()` so we can `Display` format errors
t-nelson Mar 12, 2020
7c46d22
claputils: format input validator errors with `Display`
t-nelson Mar 12, 2020
f3edd75
SDK: `thiserror` for hash and sig parse erros
t-nelson Mar 12, 2020
9ee8467
Keygen: Shim main to format errors with `Display`
t-nelson Mar 12, 2020
a3894be
SDK: `thiserror` for `InstructionError`
t-nelson Mar 12, 2020
8052b45
CLI: `thiserror` for `CliError`
t-nelson Mar 12, 2020
959151b
CLI: Format user messages with `Display`
t-nelson Mar 12, 2020
4f9786a
Client: Tweak `Display` for `ClientError`
t-nelson Mar 12, 2020
e4e9e61
RpcClient: Improve messaging when TX cannot be confirmed
t-nelson Mar 12, 2020
d3c8f8b
fu death io res retval
t-nelson Mar 12, 2020
28d446a
CLI/Keygen - fix shell return value on error
t-nelson Mar 12, 2020
b6fcea0
Tweak `InstructionError` `Display` messages as per review
t-nelson Mar 13, 2020
ab5a4a8
Cleanup hackjob return code fix
t-nelson Mar 13, 2020
3a27fc9
Embrace that which you hate most
t-nelson Mar 13, 2020
3640018
Too much...
t-nelson Mar 13, 2020
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions archiver-lib/src/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,7 @@ impl Archiver {
&archiver_keypair.pubkey(),
&storage_keypair.pubkey(),
);
let message =
Message::new_with_payer(vec![ix], Some(&archiver_keypair.pubkey()));
let message = Message::new_with_payer(&[ix], Some(&archiver_keypair.pubkey()));
if let Err(e) = client.send_message(&[archiver_keypair.as_ref()], message) {
error!("unable to redeem reward, tx failed: {:?}", e);
} else {
Expand Down Expand Up @@ -613,6 +612,7 @@ impl Archiver {
ErrorKind::Other,
"setup_mining_account: signature not found",
),
TransportError::Custom(e) => io::Error::new(ErrorKind::Other, e),
})?;
}
Ok(())
Expand Down Expand Up @@ -655,7 +655,7 @@ impl Archiver {
Signature::new(&meta.signature.as_ref()),
meta.blockhash,
);
let message = Message::new_with_payer(vec![instruction], Some(&archiver_keypair.pubkey()));
let message = Message::new_with_payer(&[instruction], Some(&archiver_keypair.pubkey()));
let mut transaction = Transaction::new(
&[archiver_keypair.as_ref(), storage_keypair.as_ref()],
message,
Expand Down
1 change: 1 addition & 0 deletions clap-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ clap = "2.33.0"
rpassword = "4.0"
solana-remote-wallet = { path = "../remote-wallet", version = "1.0.6" }
solana-sdk = { path = "../sdk", version = "1.0.6" }
thiserror = "1.0.11"
tiny-bip39 = "0.7.0"
url = "2.1.0"
chrono = "0.4"
Expand Down
26 changes: 13 additions & 13 deletions clap-utils/src/input_validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ use std::str::FromStr;
pub fn is_pubkey(string: String) -> Result<(), String> {
match string.parse::<Pubkey>() {
Ok(_) => Ok(()),
Err(err) => Err(format!("{:?}", err)),
Err(err) => Err(format!("{}", err)),
}
}

// Return an error if a hash cannot be parsed.
pub fn is_hash(string: String) -> Result<(), String> {
match string.parse::<Hash>() {
Ok(_) => Ok(()),
Err(err) => Err(format!("{:?}", err)),
Err(err) => Err(format!("{}", err)),
}
}

// Return an error if a keypair file cannot be parsed.
pub fn is_keypair(string: String) -> Result<(), String> {
read_keypair_file(&string)
.map(|_| ())
.map_err(|err| format!("{:?}", err))
.map_err(|err| format!("{}", err))
}

// Return an error if a keypair file cannot be parsed
Expand All @@ -38,7 +38,7 @@ pub fn is_keypair_or_ask_keyword(string: String) -> Result<(), String> {
}
read_keypair_file(&string)
.map(|_| ())
.map_err(|err| format!("{:?}", err))
.map_err(|err| format!("{}", err))
}

// Return an error if string cannot be parsed as pubkey string or keypair file location
Expand Down Expand Up @@ -73,10 +73,10 @@ pub fn is_pubkey_sig(string: String) -> Result<(), String> {
.ok_or_else(|| "Malformed signer string".to_string())?,
) {
Ok(_) => Ok(()),
Err(err) => Err(format!("{:?}", err)),
Err(err) => Err(format!("{}", err)),
}
}
Err(err) => Err(format!("{:?}", err)),
Err(err) => Err(format!("{}", err)),
}
}

Expand All @@ -90,28 +90,28 @@ pub fn is_url(string: String) -> Result<(), String> {
Err("no host provided".to_string())
}
}
Err(err) => Err(format!("{:?}", err)),
Err(err) => Err(format!("{}", err)),
}
}

pub fn is_slot(slot: String) -> Result<(), String> {
slot.parse::<Slot>()
.map(|_| ())
.map_err(|e| format!("{:?}", e))
.map_err(|e| format!("{}", e))
}

pub fn is_port(port: String) -> Result<(), String> {
port.parse::<u16>()
.map(|_| ())
.map_err(|e| format!("{:?}", e))
.map_err(|e| format!("{}", e))
}

pub fn is_valid_percentage(percentage: String) -> Result<(), String> {
percentage
.parse::<u8>()
.map_err(|e| {
format!(
"Unable to parse input percentage, provided: {}, err: {:?}",
"Unable to parse input percentage, provided: {}, err: {}",
percentage, e
)
})
Expand Down Expand Up @@ -141,7 +141,7 @@ pub fn is_amount(amount: String) -> Result<(), String> {
pub fn is_rfc3339_datetime(value: String) -> Result<(), String> {
DateTime::parse_from_rfc3339(&value)
.map(|_| ())
.map_err(|e| format!("{:?}", e))
.map_err(|e| format!("{}", e))
}

pub fn is_derivation(value: String) -> Result<(), String> {
Expand All @@ -152,15 +152,15 @@ pub fn is_derivation(value: String) -> Result<(), String> {
.parse::<u32>()
.map_err(|e| {
format!(
"Unable to parse derivation, provided: {}, err: {:?}",
"Unable to parse derivation, provided: {}, err: {}",
account, e
)
})
.and_then(|_| {
if let Some(change) = parts.next() {
change.parse::<u32>().map_err(|e| {
format!(
"Unable to parse derivation, provided: {}, err: {:?}",
"Unable to parse derivation, provided: {}, err: {}",
change, e
)
})
Expand Down
17 changes: 12 additions & 5 deletions clap-utils/src/keypair.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{input_parsers::pubkeys_sigs_of, offline::SIGNER_ARG, ArgConstant};
use bip39::{Language, Mnemonic, Seed};
use clap::{ArgMatches, Error, ErrorKind};
use clap::ArgMatches;
use rpassword::prompt_password_stderr;
use solana_remote_wallet::{
remote_keypair::generate_remote_keypair,
Expand Down Expand Up @@ -71,7 +71,14 @@ pub fn signer_from_path(
false,
)?))
}
KeypairUrl::Filepath(path) => Ok(Box::new(read_keypair_file(&path)?)),
KeypairUrl::Filepath(path) => match read_keypair_file(&path) {
Err(e) => Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!("could not find keypair file: {} error: {}", path, e),
)
.into()),
Ok(file) => Ok(Box::new(file)),
},
KeypairUrl::Stdin => {
let mut stdin = std::io::stdin();
Ok(Box::new(read_keypair(&mut stdin)?))
Expand All @@ -95,9 +102,9 @@ pub fn signer_from_path(
if let Some(presigner) = presigner {
Ok(Box::new(presigner))
} else {
Err(Error::with_description(
"Missing signature for supplied pubkey",
ErrorKind::MissingRequiredArgument,
Err(std::io::Error::new(
std::io::ErrorKind::Other,
"missing signature for supplied pubkey".to_string(),
)
.into())
}
Expand Down
19 changes: 19 additions & 0 deletions clap-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use thiserror::Error;

#[macro_export]
macro_rules! version {
() => {
Expand All @@ -23,6 +25,23 @@ pub struct ArgConstant<'a> {
pub help: &'a str,
}

/// Error type for forwarding Errors out of `main()` of a `clap` app
/// and still using the `Display` formatter
#[derive(Error)]
#[error("{0}")]
pub struct DisplayError(Box<dyn std::error::Error>);
impl DisplayError {
pub fn new_as_boxed(inner: Box<dyn std::error::Error>) -> Box<Self> {
DisplayError(inner).into()
}
}

impl std::fmt::Debug for DisplayError {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(fmt, "{}", self.0)
}
}

pub mod input_parsers;
pub mod input_validators;
pub mod keypair;
Expand Down
Loading