Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: Fix multisig parsing #72

Merged
merged 2 commits into from
Jan 14, 2025
Merged

Conversation

joncinque
Copy link
Contributor

@joncinque joncinque commented Jan 14, 2025

Problem

As pointed out in #58, the CLI currently fails when just running create-account <MINT_ADDRESS>, because a multisig argument is expected during all commands. Clap v3's version of values_of gives an error if the arg is not configured in the command.

This was probably missed during the port over to clap v3.

Summary of changes

Do the same thing as elsewhere, and change values_of to try_get_many(...).ok().flatten().

This is the last place using values_of in the CLI that could fail.

Closes #58

#### Problem

As pointed out in solana-program#58, the CLI currently fails when just running
`create-account <MINT_ADDRESS>`, because a multisig argument is expected
during all commands. Clap v3's version of `values_of` gives an error if
the arg is not configured in the command.

This was probably missed during the port over to clap v3.

#### Summary of changes

Do the same thing as elsewhere, and change `values_of` to
`try_get_many(...).ok().flatten()`.

This is the last place using `values_of` in the CLI that could fail.
Copy link
Contributor

@samkim-crypto samkim-crypto left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! I must have missed this while upgrading to clap-v3. The tests seem to fail, but with the suggestion below, it should all pass.

@@ -48,9 +48,9 @@ fn signers_of(
name: &str,
wallet_manager: &mut Option<Rc<RemoteWalletManager>>,
) -> Result<Option<SignersOf>, Box<dyn std::error::Error>> {
if let Some(values) = matches.values_of(name) {
if let Some(values) = matches.try_get_many(name).ok().flatten() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if let Some(values) = matches.try_get_many(name).ok().flatten() {
if let Some(values) = matches.try_get_many::<String>(name).ok().flatten() {

In clap-v3, we generally always have to specify the type that we are parsing for. We should parse this to a proper type rather than a String, but that will require update the updating the validation function is_valid_signer, which will follow after solana-labs/solana-program-library#7447. So let's just update it to String here for now.

let mut results = Vec::new();
for (i, value) in values.enumerate() {
for (i, value) in values.copied().enumerate() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for (i, value) in values.copied().enumerate() {
for (i, value) in values.enumerate() {

We are parsing for an owned String type, so we can remove the copied().

@joncinque
Copy link
Contributor Author

Ok great, thanks for the suggestions -- this should be good for another look!

Copy link
Contributor

@samkim-crypto samkim-crypto left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@joncinque joncinque merged commit 72f7b88 into solana-program:main Jan 14, 2025
19 checks passed
@joncinque joncinque deleted the valuesof branch January 14, 2025 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants