prysm-pulse/validator/accounts/v2/wallet_edit.go
Raul Jordan 60558b7970
Refactor Accounts and Keymanager Methods to Not Rely on CLI (#7135)
* keymanagers no longer use cli ctx
* rename important values to keymanageropts
* further refactor accounts methods to reduce cli dependency
* separating cli vs non cli methods for various accounts functions
* recover wallet cli vs non-cli mode
* ensure half of tests build
* accounts v2 package now builds
* full revamp wallet creation or opening wallets
* everything builds
* tests pass finally
* Merge branch 'master' into no-cli-keymanagers
* ensure commands work as expected
* Merge branch 'no-cli-keymanagers' of github.com:prysmaticlabs/prysm into no-cli-keymanagers
* further fix build
* account creation comments
* fix imports and comments
* fix up failing test
* fix build
* Update derived.go
* Update direct.go
* Update remote.go
* Fixed variable
* fix up red tests
* use Cli instead of CLI, fix tests, and address Radek's feedback
* Merge refs/heads/master into no-cli-keymanagers
* Merge refs/heads/master into no-cli-keymanagers
* Merge refs/heads/master into no-cli-keymanagers
* Merge refs/heads/master into no-cli-keymanagers
* Merge refs/heads/master into no-cli-keymanagers
* Merge refs/heads/master into no-cli-keymanagers
* Merge refs/heads/master into no-cli-keymanagers
* Merge refs/heads/master into no-cli-keymanagers
2020-08-31 19:46:45 +00:00

57 lines
1.8 KiB
Go

package v2
import (
"fmt"
"github.com/pkg/errors"
v2keymanager "github.com/prysmaticlabs/prysm/validator/keymanager/v2"
"github.com/prysmaticlabs/prysm/validator/keymanager/v2/remote"
"github.com/urfave/cli/v2"
)
// EditWalletConfigurationCli for a user's on-disk wallet, being able to change
// things such as remote gRPC credentials for remote signing, derivation paths
// for HD wallets, and more.
func EditWalletConfigurationCli(cliCtx *cli.Context) error {
wallet, err := OpenWalletOrElseCli(cliCtx, func(cliCtx *cli.Context) (*Wallet, error) {
return nil, errors.New(
"no wallet found, no configuration to edit",
)
})
if err != nil {
return errors.Wrap(err, "could not open wallet")
}
switch wallet.KeymanagerKind() {
case v2keymanager.Direct:
return errors.New("not possible to edit direct keymanager configuration")
case v2keymanager.Derived:
return errors.New("derived keymanager is not yet supported")
case v2keymanager.Remote:
enc, err := wallet.ReadKeymanagerConfigFromDisk(cliCtx.Context)
if err != nil {
return errors.Wrap(err, "could not read config")
}
opts, err := remote.UnmarshalOptionsFile(enc)
if err != nil {
return errors.Wrap(err, "could not unmarshal config")
}
log.Info("Current configuration")
// Prints the current configuration to stdout.
fmt.Println(opts)
newCfg, err := inputRemoteKeymanagerConfig(cliCtx)
if err != nil {
return errors.Wrap(err, "could not get keymanager config")
}
encodedCfg, err := remote.MarshalOptionsFile(cliCtx.Context, newCfg)
if err != nil {
return errors.Wrap(err, "could not marshal config file")
}
if err := wallet.WriteKeymanagerConfigToDisk(cliCtx.Context, encodedCfg); err != nil {
return errors.Wrap(err, "could not write config to disk")
}
default:
return fmt.Errorf("keymanager type %s is not supported", wallet.KeymanagerKind())
}
return nil
}