mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
4017743f7f
* 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>
54 lines
1.7 KiB
Go
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
|
|
}
|