Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion clap-utils/src/compute_budget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use {
pub const COMPUTE_UNIT_PRICE_ARG: ArgConstant<'static> = ArgConstant {
name: "compute_unit_price",
long: "--with-compute-unit-price",
help: "Set compute unit price for transaction, in increments of 0.000001 lamports per compute unit.",
help: "Set compute unit price for transaction, in increments of 0.000001 lamports per compute \
unit.",
};

pub const COMPUTE_UNIT_LIMIT_ARG: ArgConstant<'static> = ArgConstant {
Expand Down
6 changes: 3 additions & 3 deletions clap-utils/src/fee_payer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use {
pub const FEE_PAYER_ARG: ArgConstant<'static> = ArgConstant {
name: "fee_payer",
long: "fee-payer",
help: "Specify the fee-payer account. This may be a keypair file, the ASK keyword \n\
or the pubkey of an offline signer, provided an appropriate --signer argument \n\
is also passed. Defaults to the client keypair.",
help: "Specify the fee-payer account. This may be a keypair file, the ASK keyword or the \
pubkey of an offline signer, provided an appropriate --signer argument is also passed. \
Defaults to the client keypair.",
};

pub fn fee_payer_arg<'a, 'b>() -> Arg<'a, 'b> {
Expand Down
2 changes: 1 addition & 1 deletion clap-utils/src/input_parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ pub fn lamports_of_sol(matches: &ArgMatches<'_>, name: &str) -> Option<u64> {
let lamports = if lamports.is_empty() {
0
} else {
format!("{:0<9}", lamports)[..9].parse().ok()?
format!("{lamports:0<9}")[..9].parse().ok()?
};
Some(
LAMPORTS_PER_SOL
Expand Down
26 changes: 15 additions & 11 deletions clap-utils/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ impl DefaultSigner {
})
.map_err(|_| {
std::io::Error::other(format!(
"No default signer found, run \"solana-keygen new -o {}\" to create a new one",
"No default signer found, run \"solana-keygen new -o {}\" to create a new \
one",
self.path
))
})?;
Expand Down Expand Up @@ -773,7 +774,8 @@ pub fn signer_from_path_with_config(
}
SignerSourceKind::Filepath(path) => match read_keypair_file(&path) {
Err(e) => Err(std::io::Error::other(format!(
"could not read keypair file \"{path}\". Run \"solana-keygen new\" to create a keypair file: {e}"
"could not read keypair file \"{path}\". Run \"solana-keygen new\" to create a \
keypair file: {e}"
))
.into()),
Ok(file) => Ok(Box::new(file)),
Expand Down Expand Up @@ -807,9 +809,9 @@ pub fn signer_from_path_with_config(
} else if config.allow_null_signer || matches.is_present(SIGN_ONLY_ARG.name) {
Ok(Box::new(NullSigner::new(&pubkey)))
} else {
Err(std::io::Error::other(
format!("missing signature for supplied pubkey: {pubkey}"),
)
Err(std::io::Error::other(format!(
"missing signature for supplied pubkey: {pubkey}"
))
.into())
}
}
Expand Down Expand Up @@ -893,8 +895,8 @@ pub fn resolve_signer_from_path(
}
SignerSourceKind::Filepath(path) => match read_keypair_file(&path) {
Err(e) => Err(std::io::Error::other(format!(
"could not read keypair file \"{path}\". \
Run \"solana-keygen new\" to create a keypair file: {e}"
"could not read keypair file \"{path}\". Run \"solana-keygen new\" to create a \
keypair file: {e}"
))
.into()),
Ok(_) => Ok(Some(path.to_string())),
Expand Down Expand Up @@ -933,7 +935,8 @@ pub const ASK_KEYWORD: &str = "ASK";
pub const SKIP_SEED_PHRASE_VALIDATION_ARG: ArgConstant<'static> = ArgConstant {
long: "skip-seed-phrase-validation",
name: "skip_seed_phrase_validation",
help: "Skip validation of seed phrases. Use this if your phrase does not use the BIP39 official English word list",
help: "Skip validation of seed phrases. Use this if your phrase does not use the BIP39 \
official English word list",
};

/// Prompts user for a passphrase and then asks for confirmirmation to check for mistakes
Expand Down Expand Up @@ -1012,8 +1015,8 @@ pub fn keypair_from_path(
}
SignerSourceKind::Filepath(path) => match read_keypair_file(&path) {
Err(e) => Err(std::io::Error::other(format!(
"could not read keypair file \"{path}\". \
Run \"solana-keygen new\" to create a keypair file: {e}"
"could not read keypair file \"{path}\". Run \"solana-keygen new\" to create a \
keypair file: {e}"
))
.into()),
Ok(file) => Ok(file),
Expand Down Expand Up @@ -1043,7 +1046,8 @@ pub fn keypair_from_seed_phrase(
let seed_phrase = prompt_password(format!("[{keypair_name}] seed phrase: "))?;
let seed_phrase = seed_phrase.trim();
let passphrase_prompt = format!(
"[{keypair_name}] If this seed phrase has an associated passphrase, enter it now. Otherwise, press ENTER to continue: ",
"[{keypair_name}] If this seed phrase has an associated passphrase, enter it now. \
Otherwise, press ENTER to continue: ",
);

let keypair = if skip_validation {
Expand Down
3 changes: 2 additions & 1 deletion clap-v3-utils/src/compute_budget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use {
pub const COMPUTE_UNIT_PRICE_ARG: ArgConstant<'static> = ArgConstant {
name: "compute_unit_price",
long: "--with-compute-unit-price",
help: "Set compute unit price for transaction, in increments of 0.000001 lamports per compute unit.",
help: "Set compute unit price for transaction, in increments of 0.000001 lamports per compute \
unit.",
};

pub const COMPUTE_UNIT_LIMIT_ARG: ArgConstant<'static> = ArgConstant {
Expand Down
6 changes: 3 additions & 3 deletions clap-v3-utils/src/fee_payer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use {
pub const FEE_PAYER_ARG: ArgConstant<'static> = ArgConstant {
name: "fee_payer",
long: "fee-payer",
help: "Specify the fee-payer account. This may be a keypair file, the ASK keyword \n\
or the pubkey of an offline signer, provided an appropriate --signer argument \n\
is also passed. Defaults to the client keypair.",
help: "Specify the fee-payer account. This may be a keypair file, the ASK keyword or the \
pubkey of an offline signer, provided an appropriate --signer argument is also passed. \
Defaults to the client keypair.",
};

#[allow(deprecated)]
Expand Down
3 changes: 2 additions & 1 deletion clap-v3-utils/src/input_parsers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use {
pub mod signer;
#[deprecated(
since = "1.17.0",
note = "Please use the functions in `solana_clap_v3_utils::input_parsers::signer` directly instead"
note = "Please use the functions in `solana_clap_v3_utils::input_parsers::signer` directly \
instead"
)]
#[allow(deprecated)]
pub use signer::{
Expand Down
11 changes: 8 additions & 3 deletions clap-v3-utils/src/input_validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ where
// Return an error if a keypair file cannot be parsed
#[deprecated(
since = "1.18.0",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol, deprecated in v1.18! Probably about time we remove them. (Not for this PR though.)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was going to start peeling this out but there is still some chain of usage so I did not pursue further

note = "please use `SignerSourceParserBuilder::default().allow_file_path().allow_prompt().allow_legacy().build()` instead"
note = "please use \
`SignerSourceParserBuilder::default().allow_file_path().allow_prompt().allow_legacy().\
build()` instead"
)]
pub fn is_keypair_or_ask_keyword<T>(string: T) -> Result<(), String>
where
Expand All @@ -115,7 +117,8 @@ where
// Return an error if a `SignerSourceKind::Prompt` cannot be parsed
#[deprecated(
since = "1.18.0",
note = "please use `SignerSourceParserBuilder::default().allow_prompt().allow_legacy().build()` instead"
note = "please use \
`SignerSourceParserBuilder::default().allow_prompt().allow_legacy().build()` instead"
)]
pub fn is_prompt_signer_source(string: &str) -> Result<(), String> {
if string == ASK_KEYWORD {
Expand All @@ -135,7 +138,9 @@ pub fn is_prompt_signer_source(string: &str) -> Result<(), String> {
// Return an error if string cannot be parsed as pubkey string or keypair file location
#[deprecated(
since = "1.18.0",
note = "please use `SignerSourceParserBuilder::default().allow_pubkey().allow_file_path().build()` instead"
note = "please use \
`SignerSourceParserBuilder::default().allow_pubkey().allow_file_path().build()` \
instead"
)]
#[allow(deprecated)]
pub fn is_pubkey_or_keypair<T>(string: T) -> Result<(), String>
Expand Down
7 changes: 4 additions & 3 deletions clap-v3-utils/src/keygen/derivation_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ pub fn derivation_path_arg<'a>() -> Arg<'a> {
.takes_value(true)
.min_values(0)
.max_values(1)
.help("Derivation path. All indexes will be promoted to hardened. \
If arg is not presented then derivation path will not be used. \
If arg is presented with empty DERIVATION_PATH value then m/44'/501'/0'/0' will be used."
.help(
"Derivation path. All indexes will be promoted to hardened. If arg is not presented \
then derivation path will not be used. If arg is presented with empty \
DERIVATION_PATH value then m/44'/501'/0'/0' will be used.",
)
}

Expand Down
14 changes: 8 additions & 6 deletions clap-v3-utils/src/keygen/mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,17 @@ pub fn no_passphrase_and_message() -> (String, String) {
pub fn acquire_passphrase_and_message(
matches: &ArgMatches,
) -> Result<(String, String), Box<dyn error::Error>> {
#[rustfmt::skip]
const PROMPT: &str =
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to leave this one as is as this is regularly displayed to users; on the other hand the adjustments to FEE_PAYER_ARG are in help messages only

"\nFor added security, enter a BIP39 passphrase\n\
\nNOTE! This passphrase improves security of the recovery seed phrase NOT the\n\
keypair file itself, which is stored as insecure plain text\n\
\nBIP39 Passphrase (empty for none): ";

if matches.try_contains_id(NO_PASSPHRASE_ARG.name)? {
Ok(no_passphrase_and_message())
} else {
match prompt_passphrase(
"\nFor added security, enter a BIP39 passphrase\n\
\nNOTE! This passphrase improves security of the recovery seed phrase NOT the\n\
keypair file itself, which is stored as insecure plain text\n\
\nBIP39 Passphrase (empty for none): ",
) {
match prompt_passphrase(PROMPT) {
Ok(passphrase) => {
println!();
Ok((passphrase, " and your BIP39 passphrase".to_string()))
Expand Down
48 changes: 27 additions & 21 deletions clap-v3-utils/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,11 @@ impl DefaultSigner {
}
})
.map_err(|_| {
std::io::Error::other(
format!(
"No default signer found, run \"solana-keygen new -o {}\" to create a new one",
std::io::Error::other(format!(
"No default signer found, run \"solana-keygen new -o {}\" to create a new \
one",
self.path
),
)
))
})?;
*self.is_path_checked.borrow_mut() = true;
}
Expand Down Expand Up @@ -652,9 +651,10 @@ pub fn signer_from_source_with_config(
)?))
}
SignerSourceKind::Filepath(path) => match read_keypair_file(path) {
Err(e) => Err(std::io::Error::other(
format!("could not read keypair file \"{path}\". Run \"solana-keygen new\" to create a keypair file: {e}"),
)
Err(e) => Err(std::io::Error::other(format!(
"could not read keypair file \"{path}\". Run \"solana-keygen new\" to create a \
keypair file: {e}"
))
.into()),
Ok(file) => Ok(Box::new(file)),
},
Expand All @@ -680,17 +680,21 @@ pub fn signer_from_source_with_config(
}
}
SignerSourceKind::Pubkey(pubkey) => {
let presigner = try_pubkeys_sigs_of(matches, SIGNER_ARG.name).ok().flatten()
let presigner = try_pubkeys_sigs_of(matches, SIGNER_ARG.name)
.ok()
.flatten()
.as_ref()
.and_then(|presigners| presigner_from_pubkey_sigs(pubkey, presigners));
if let Some(presigner) = presigner {
Ok(Box::new(presigner))
} else if config.allow_null_signer || matches.try_contains_id(SIGN_ONLY_ARG.name).unwrap_or(false) {
} else if config.allow_null_signer
|| matches.try_contains_id(SIGN_ONLY_ARG.name).unwrap_or(false)
{
Ok(Box::new(NullSigner::new(pubkey)))
} else {
Err(std::io::Error::other(
format!("missing signature for supplied pubkey: {pubkey}"),
)
Err(std::io::Error::other(format!(
"missing signature for supplied pubkey: {pubkey}"
))
.into())
}
}
Expand Down Expand Up @@ -793,8 +797,8 @@ pub fn resolve_signer_from_source(
}
SignerSourceKind::Filepath(path) => match read_keypair_file(path) {
Err(e) => Err(std::io::Error::other(format!(
"could not read keypair file \"{path}\". \
Run \"solana-keygen new\" to create a keypair file: {e}"
"could not read keypair file \"{path}\". Run \"solana-keygen new\" to create a \
keypair file: {e}"
))
.into()),
Ok(_) => Ok(Some(path.to_string())),
Expand Down Expand Up @@ -834,7 +838,8 @@ pub const ASK_KEYWORD: &str = "ASK";
pub const SKIP_SEED_PHRASE_VALIDATION_ARG: ArgConstant<'static> = ArgConstant {
long: "skip-seed-phrase-validation",
name: "skip_seed_phrase_validation",
help: "Skip validation of seed phrases. Use this if your phrase does not use the BIP39 official English word list",
help: "Skip validation of seed phrases. Use this if your phrase does not use the BIP39 \
official English word list",
};

/// Prompts user for a passphrase and then asks for confirmirmation to check for mistakes
Expand Down Expand Up @@ -1071,8 +1076,8 @@ fn encodable_key_from_source<K: EncodableKey + SeedDerivable>(
)?),
SignerSourceKind::Filepath(path) => match K::read_from_file(path) {
Err(e) => Err(std::io::Error::other(format!(
"could not read keypair file \"{path}\". \
Run \"solana-keygen new\" to create a keypair file: {e}"
"could not read keypair file \"{path}\". Run \"solana-keygen new\" to create a \
keypair file: {e}"
))
.into()),
Ok(file) => Ok(file),
Expand Down Expand Up @@ -1152,7 +1157,8 @@ fn encodable_key_from_seed_phrase<K: EncodableKey + SeedDerivable>(
let seed_phrase = prompt_password(format!("[{key_name}] seed phrase: "))?;
let seed_phrase = seed_phrase.trim();
let passphrase_prompt = format!(
"[{key_name}] If this seed phrase has an associated passphrase, enter it now. Otherwise, press ENTER to continue: ",
"[{key_name}] If this seed phrase has an associated passphrase, enter it now. Otherwise, \
press ENTER to continue: ",
);

let key = if skip_validation {
Expand Down Expand Up @@ -1349,7 +1355,7 @@ mod tests {
legacy: false,
};

let signer_arg = format!("{}={}", pubkey, signature);
let signer_arg = format!("{pubkey}={signature}");

let clap_app = Command::new("test").arg(
Arg::new(SIGNER_ARG.name)
Expand Down Expand Up @@ -1390,7 +1396,7 @@ mod tests {
legacy: false,
};

let signer_arg = format!("{}={}", pubkey, signature);
let signer_arg = format!("{pubkey}={signature}");

let clap_app = Command::new("test").arg(
Arg::new(SIGNER_ARG.name)
Expand Down
37 changes: 33 additions & 4 deletions cli-output/src/cli_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ impl VerboseDisplay for CliPrioritizationFeeStats {
fn write_str(&self, f: &mut dyn std::fmt::Write) -> fmt::Result {
writeln!(f, "{:<11} prioritization_fee", "slot")?;
for fee in &self.fees {
write!(f, "{}", fee)?;
write!(f, "{fee}")?;
}
write!(f, "{}", self)
write!(f, "{self}")
}
}

Expand Down Expand Up @@ -3541,13 +3541,42 @@ mod tests {
recent_timestamp: BlockTimestamp::default(),
..CliVoteAccount::default()
};
#[rustfmt::skip]
let expected_output_common =
"Account Balance: 0.00001 SOL\n\
Validator Identity: 11111111111111111111111111111111\n\
Vote Authority: None\n\
Withdraw Authority: \n\
Credits: 0\n\
Commission: 0%\n\
Root Slot: ~\n\
Recent Timestamp: 1970-01-01T00:00:00Z from slot 0\n";

let s = format!("{c}");
assert_eq!(s, "Account Balance: 0.00001 SOL\nValidator Identity: 11111111111111111111111111111111\nVote Authority: None\nWithdraw Authority: \nCredits: 0\nCommission: 0%\nRoot Slot: ~\nRecent Timestamp: 1970-01-01T00:00:00Z from slot 0\nEpoch Rewards:\n Epoch Reward Slot Time Amount New Balance Percent Change APR Commission\n 1 100 1970-01-01 00:00:00 UTC ◎0.00000001 ◎0.0000001 11.000% 10.00% 1%\n 2 200 1970-01-12 13:46:40 UTC ◎0.000000012 ◎0.0000001 11.000% 13.00% 1%\n");
#[rustfmt::skip]
let expected_epoch_rewards_output =
"Epoch Rewards:\n \
Epoch Reward Slot Time Amount New Balance Percent Change APR Commission\n \
1 100 1970-01-01 00:00:00 UTC ◎0.00000001 ◎0.0000001 11.000% 10.00% 1%\n \
2 200 1970-01-12 13:46:40 UTC ◎0.000000012 ◎0.0000001 11.000% 13.00% 1%\n";
assert_eq!(
s,
format!("{expected_output_common}{expected_epoch_rewards_output}")
);
println!("{s}");

c.use_csv = true;
let s = format!("{c}");
assert_eq!(s, "Account Balance: 0.00001 SOL\nValidator Identity: 11111111111111111111111111111111\nVote Authority: None\nWithdraw Authority: \nCredits: 0\nCommission: 0%\nRoot Slot: ~\nRecent Timestamp: 1970-01-01T00:00:00Z from slot 0\nEpoch Rewards:\nEpoch,Reward Slot,Time,Amount,New Balance,Percent Change,APR,Commission\n1,100,1970-01-01 00:00:00 UTC,0.00000001,0.0000001,11%,10.00%,1%\n2,200,1970-01-12 13:46:40 UTC,0.000000012,0.0000001,11%,13.00%,1%\n");
#[rustfmt::skip]
let expected_epoch_rewards_output =
"Epoch Rewards:\n\
Epoch,Reward Slot,Time,Amount,New Balance,Percent Change,APR,Commission\n\
1,100,1970-01-01 00:00:00 UTC,0.00000001,0.0000001,11%,10.00%,1%\n\
2,200,1970-01-12 13:46:40 UTC,0.000000012,0.0000001,11%,13.00%,1%\n";
assert_eq!(
s,
format!("{expected_output_common}{expected_epoch_rewards_output}")
);
Comment thread
steviez marked this conversation as resolved.
println!("{s}");
}
}
Loading
Loading