-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
[clap-v3-utils] Remove deprecated functions #34989
[clap-v3-utils] Remove deprecated functions #34989
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #34989 +/- ##
========================================
Coverage 81.7% 81.8%
========================================
Files 836 836
Lines 224834 225069 +235
========================================
+ Hits 183847 184136 +289
+ Misses 40987 40933 -54 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks fine to me. One nit, plus a request for deduplication.
if value == ASK_KEYWORD { | ||
let skip_validation = matches.try_contains_id(SKIP_SEED_PHRASE_VALIDATION_ARG.name)?; | ||
keypair_from_seed_phrase(name, skip_validation, true, None, true).map(Some) | ||
} else { | ||
read_keypair_file(value).map(Some) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to de-deupe this with the logic in try_keypairs_of
-- I know the duplication predates you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes good point. If try_keypairs_of
returns a keypair vector of length greater than 1, it is actually unclear what the behavior of this function should be. Whether multiple keypairs are allowed should be caught by Args
, so technically this choice will not matter if the function is used correctly... I pushed a change that simply pops the keypair out of the returned vector. Please take a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a push? I don't see any changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry I don't quite know where those commit went... But I pushed the changes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhh, I was confused about your comment until reading the code just now. By deduping, I actually meant put the following code in a helper fn that gets called from both methods:
if value == ASK_KEYWORD {
let skip_validation = matches.try_contains_id(SKIP_SEED_PHRASE_VALIDATION_ARG.name)?;
keypair_from_seed_phrase(name, skip_validation, true, None, true).map(Some)
} else {
read_keypair_file(value).map(Some)
}
(And elsewhere, if we use it other places)
Probably what you have written is fine, but I don't know if there might be costs to calling try_get_many
when we only expect one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh oops! Sorry for the misinterpretation. I added a helper function extract_keypair
to include the keypair extraction logic.
I think technically, the helper function should be named keypair_from_path
, but we already have a public function with that name. The try_keypair_of
and try_keypairs_of
should probably use the existing keypair_from_path
(unless we strictly want to restrict the source to just ASK
or file), but that will be changing the functionality so we probably don't want to change it now.
Ok(matches.try_get_many::<String>(name)?.map(|values| { | ||
values | ||
.map(|value| { | ||
value.parse::<Pubkey>().unwrap_or_else(|_| { | ||
read_keypair_file(value) | ||
.expect("read_keypair_file failed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this can be refactored to avoid the expect()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error handling was a bit tricky to do inside maps and closures, so I ended up using a for-loop to propagate the error. If you see a more elegant solution, let me know!
Ok(matches.try_get_many::<String>(name)?.map(|values| { | ||
values | ||
.map(|pubkey_signer_string| { | ||
let mut signer = pubkey_signer_string.split('='); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer splitn()
to avoid succeeding on invalid inputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, valid point. I ended up using split_once
, which also returns an option.
let key = Pubkey::from_str(signer.next().unwrap()).unwrap(); | ||
let sig = Signature::from_str(signer.next().unwrap()).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should avoid unwrap()
ing on user inputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, I ended up using a for-loop here, so let me know if you see a more elegant solution.
…, `try_pubkey_of`, and `try_pubkeys_of`
@CriesofCarrots @t-nelson, it would be great to get this PR merged before the migration 🙏 . Can you take one last look at the PR to check if the changes look sound? |
This repository is no longer in use. Please re-open this pull request in the agave repo: https://github.com/anza-xyz/agave |
Problem
Solana clap-v3-utils still uses deprecated functions from clap-v2.
Summary of Changes
possible_values
,value_of
, andmultiple_occurrences
with the updated functions from clap-v3.clap-v3
functionskeypair_of
,keypairs_of
, etc. in favor of theirtry_
variantsClap-v3 has a feature
deprecated
that, when included, gives warnings on deprecated functions. With this PR, all the deprecated functions should either be removed or explicitly allowed (on deprecated functions). However, if I include thedeprecated
feature, it seems to turn this feature on in the rest of the repo on CI checks, so I left it out for now.Fixes #