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 edit CLI Manager migration #11136

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 edit functionality and refactors it as part of #9883. It follows up on #10554, #10686, #10824, #10841, #10890 which do similar migration for the accounts list, delete, backup, exit, and import.

  1. cmd/validator/wallet/edit.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 WalletEdit method with the context.Context(no longer a need for the cli.Context). The options specific to the import functionality are: WithWallet and WithKeymangerOpts.
  2. cmd/validator/wallet/edit_test.go. This is the new location the test that was in validator/accounts/wallet_edit_test.go. As written, this tests are built for the CLI context interface, so if we are moving the logic for handling to the cmd/validator/wallet directory, it makes sense to also move the test here. Note that we duplicate a few functions and a struct into this file: setupWalletAndPasswordsDir, testWalletConfig, and setupWalletCtx. These are defined in different tests in the validator/accounts directory, and thus aren't importable into this package. One weird aside, these functions are actually also defined in the cmd/validator/accounts/delete_test.go too for the same reason (the test depended on them and couldn't import from test files in validator/acconts. When I tried to create a shared library for both accounts/delete_test.go and wallet/edit_test.go I kept running into the following compile error: https://pastebin.com/2n2VB7Ez. I left a TODO in the code to figure this out to remove the duplication.
  3. validator/accounts/wallet_edit.go. This is where we see the benefit of this refactor. We chop out all the CLI parsing stuff from the EditWalletConfigurationCli function, and make it the WalletEdit method on the AccountsCLIManager pointer receiver.
  4. validator/accounts/cli_manager.go and validator/accounts/cli_options.go. I added a new option that the wallet edit function depends on: keymanagerOpts *remote.KeymanagerOpts.

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

@michaelneuder michaelneuder requested a review from a team as a code owner July 31, 2022 17:16
@james-prysm james-prysm added the Cleanup Code health! label Aug 1, 2022
Copy link
Contributor

@james-prysm james-prysm left a comment

Choose a reason for hiding this comment

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

Changes look good and were easy to follow

"github.com/urfave/cli/v2"
)

func walletEdit(c *cli.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we call this remote wallet edit or something? wallet is pretty generic if the feature is only really used for the remote keymanager configs, might be kind of confusing in the future. one of the old functions is called edit remote wallet which shows more what it's meant for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed to remoteWalletEdit! good call, thanks!

Copy link
Contributor

@james-prysm james-prysm left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cleanup Code health!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants