2020-07-16 05:08:16 +00:00
|
|
|
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()
|
2020-07-22 04:49:04 +00:00
|
|
|
wallet, err := OpenWallet(cliCtx)
|
2020-07-16 05:08:16 +00:00
|
|
|
if err != nil {
|
2020-07-22 02:04:08 +00:00
|
|
|
return errors.Wrap(err, "could not open wallet")
|
2020-07-16 05:08:16 +00:00
|
|
|
}
|
2020-07-22 04:49:04 +00:00
|
|
|
switch wallet.KeymanagerKind() {
|
2020-07-16 05:08:16 +00:00
|
|
|
case v2keymanager.Direct:
|
2020-07-22 02:04:08 +00:00
|
|
|
return errors.New("no configuration options available to edit for direct keymanager")
|
2020-07-16 05:08:16 +00:00
|
|
|
case v2keymanager.Derived:
|
2020-07-22 02:04:08 +00:00
|
|
|
return errors.New("derived keymanager is not yet supported")
|
2020-07-16 05:08:16 +00:00
|
|
|
case v2keymanager.Remote:
|
|
|
|
enc, err := wallet.ReadKeymanagerConfigFromDisk(ctx)
|
|
|
|
if err != nil {
|
2020-07-22 02:04:08 +00:00
|
|
|
return errors.Wrap(err, "could not read config")
|
2020-07-16 05:08:16 +00:00
|
|
|
}
|
|
|
|
cfg, err := remote.UnmarshalConfigFile(enc)
|
|
|
|
if err != nil {
|
2020-07-22 02:04:08 +00:00
|
|
|
return errors.Wrap(err, "could not unmarshal config")
|
2020-07-16 05:08:16 +00:00
|
|
|
}
|
|
|
|
log.Infof("Current configuration")
|
|
|
|
fmt.Printf("%s\n", cfg)
|
|
|
|
newCfg, err := inputRemoteKeymanagerConfig(cliCtx)
|
|
|
|
if err != nil {
|
2020-07-22 02:04:08 +00:00
|
|
|
return errors.Wrap(err, "could not get keymanager config")
|
2020-07-16 05:08:16 +00:00
|
|
|
}
|
|
|
|
encodedCfg, err := remote.MarshalConfigFile(ctx, newCfg)
|
|
|
|
if err != nil {
|
2020-07-22 02:04:08 +00:00
|
|
|
return errors.Wrap(err, "could not marshal config file")
|
2020-07-16 05:08:16 +00:00
|
|
|
}
|
|
|
|
if err := wallet.WriteKeymanagerConfigToDisk(ctx, encodedCfg); err != nil {
|
2020-07-22 02:04:08 +00:00
|
|
|
return errors.Wrap(err, "could not write config to disk")
|
2020-07-16 05:08:16 +00:00
|
|
|
}
|
|
|
|
default:
|
2020-07-22 04:49:04 +00:00
|
|
|
return fmt.Errorf("keymanager type %s is not supported", wallet.KeymanagerKind())
|
2020-07-16 05:08:16 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|