prysm-pulse/validator/accounts/v2/wallet_edit.go
Raul Jordan 4017743f7f
Accounts V2: Refactor Wallet Open / Close and Keymanager Initialization (#6668)
* refactoring create account

* dep

* much easier, create a derived account by simply unlocking wallet

* revert changes to new

* make open wallet smarter and utilize cli ctx

* remove the wallet config

* successfully build

* simplify ctx creation for tests

* tests should pass individually

* tests pass

* fixed up to allow for wallet password file input

* fix broken tests

* formatting

* fmt

* simplify recover

* fixed up tests

* implicit use of default wallet path working

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2020-07-21 23:49:04 -05:00

54 lines
1.7 KiB
Go

package v2
import (
"context"
"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"
)
// EditWalletConfiguration 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 EditWalletConfiguration(cliCtx *cli.Context) error {
ctx := context.Background()
wallet, err := OpenWallet(cliCtx)
if err != nil {
return errors.Wrap(err, "could not open wallet")
}
switch wallet.KeymanagerKind() {
case v2keymanager.Direct:
return errors.New("no configuration options available to edit for direct keymanager")
case v2keymanager.Derived:
return errors.New("derived keymanager is not yet supported")
case v2keymanager.Remote:
enc, err := wallet.ReadKeymanagerConfigFromDisk(ctx)
if err != nil {
return errors.Wrap(err, "could not read config")
}
cfg, err := remote.UnmarshalConfigFile(enc)
if err != nil {
return errors.Wrap(err, "could not unmarshal config")
}
log.Infof("Current configuration")
fmt.Printf("%s\n", cfg)
newCfg, err := inputRemoteKeymanagerConfig(cliCtx)
if err != nil {
return errors.Wrap(err, "could not get keymanager config")
}
encodedCfg, err := remote.MarshalConfigFile(ctx, newCfg)
if err != nil {
return errors.Wrap(err, "could not marshal config file")
}
if err := wallet.WriteKeymanagerConfigToDisk(ctx, 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
}