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

Wallet Create CLI manager integration #11331

Merged

Conversation

michaelneuder
Copy link
Contributor

What type of PR is this?
Refactor/code health

What does this PR do? Why is it needed?
This PR addresses the wallet create functionality and refactors it as part of #9883. It follows up on #10554, #10686, #10824, #10841, #10890, #11136, #11278 which do similar migration for the accounts list, delete, backup, exit, import and wallet edit, recover.

This is a bit of a bigger PR, but I think closes out the refactor nicely!!!

  1. cmd/validator/accounts/{backup_test.go, delete_test.go, exit_test.go, import_test.go}. These files all made use of the accounts.CreateWalletWithKeymanager function, which was in the accounts/wallet_create.go file. Since we are moving the wallet creation functionality to a member function on a accounts CLI manager object, we need to replace each of these function calls with constructing a new CLI manager and calling acc.WalletCreate. We construct each of them just with the wallet directory, the keymanager type, and the password.
  2. cmd/validator/accounts/import.go. This was a little tricky, because this file made use of the ExtractWalletCreationConfigFromCli functions which was also defined in the validator/accounts package. However, we were aiming at removing all the clictx objects from that directory. Additionally, this file only used the function to extract the wallet dir and password (rather than needing all of the other logic from ExtractWalletCreationConfigFromCli. So I created a new function ExtractWalletDirPassword which just extracts the wallet dir and password from the CLI. This function is also used in the cmd/validator/wallet/create_test.go.
  3. cmd/validator/wallet/create.go. This is a new file that parses the CLI flags and constructs the CLI manager with the appropriate options. On the CLI manager, it simply calls the WalletCreate method with the context.Context(no longer a need for the cli.Context). I refactored ExtractWalletCreationConfigFromCli to return a slice of Option objects that we use to construct the CLI manager.
  4. cmd/validator/wallet/create_test.go. This is just a moving of the validator/accounts/wallet_create_test.go file into the cmd/validator/wallet directory.
  5. validator/accounts/cli_manager.go and validator/accounts/cli_options.go. I added two new options that the wallet create function depends on: keymanagerKind, skipMnemonicConfirm.
  6. validator/accounts/wallet_create.go. This is where we see the benefit of this refactor. We chop out all the CLI parsing stuff from the CreateAndSaveWalletCli function, and make it the WalletCreate method on the AccountsCLIManager pointer receiver.

Which issues(s) does this PR fix?
This is part of the keymanager refactor defined in #9883.
It is also described in #10339.

michaelneuder and others added 13 commits August 27, 2022 11:45
* Wallet recover CLI Manager migration

* bazel run //:gazelle -- fix

* fix lint and build errors

* add TODO to remove duplicate code

Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
Co-authored-by: Radosław Kapka <rkapka@wp.pl>
* Wallet recover CLI Manager migration

* bazel run //:gazelle -- fix

* fix lint and build errors

* add TODO to remove duplicate code

Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
Co-authored-by: Radosław Kapka <rkapka@wp.pl>
@michaelneuder michaelneuder requested a review from a team as a code owner August 27, 2022 16:21
@james-prysm james-prysm added UX cosmetic / user experience related Cleanup Code health! labels Aug 29, 2022
}

// ExtractWalletCreationConfigFromCli prompts the user for wallet creation input.
func ExtractWalletCreationConfigFromCli(cliCtx *cli.Context, keymanagerKind keymanager.Kind) ([]accounts.Option, error) {
Copy link
Contributor

@james-prysm james-prysm Aug 29, 2022

Choose a reason for hiding this comment

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

is there a better name for this now that you have refactored it to return account options?

other code is super nice to see, not seeing the cli used in the accounts package looks great!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice, good point! I changed it to ConstructCLIManagerOpts!

thanks!

@prylabs-bulldozer prylabs-bulldozer bot merged commit cbc2153 into prysmaticlabs:develop Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cleanup Code health! UX cosmetic / user experience related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants