2020-07-16 05:08:16 +00:00
|
|
|
package v2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2020-09-17 01:34:42 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/validator/accounts/v2/prompt"
|
|
|
|
"github.com/prysmaticlabs/prysm/validator/accounts/v2/wallet"
|
2020-07-16 05:08:16 +00:00
|
|
|
v2keymanager "github.com/prysmaticlabs/prysm/validator/keymanager/v2"
|
|
|
|
"github.com/prysmaticlabs/prysm/validator/keymanager/v2/remote"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
2020-08-31 19:46:45 +00:00
|
|
|
// EditWalletConfigurationCli for a user's on-disk wallet, being able to change
|
2020-07-16 05:08:16 +00:00
|
|
|
// things such as remote gRPC credentials for remote signing, derivation paths
|
|
|
|
// for HD wallets, and more.
|
2020-08-31 19:46:45 +00:00
|
|
|
func EditWalletConfigurationCli(cliCtx *cli.Context) error {
|
2020-09-17 01:34:42 +00:00
|
|
|
w, err := wallet.OpenWalletOrElseCli(cliCtx, func(cliCtx *cli.Context) (*wallet.Wallet, error) {
|
2020-08-31 19:46:45 +00:00
|
|
|
return nil, errors.New(
|
|
|
|
"no wallet found, no configuration to edit",
|
|
|
|
)
|
|
|
|
})
|
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-09-17 01:34:42 +00:00
|
|
|
switch w.KeymanagerKind() {
|
2020-07-16 05:08:16 +00:00
|
|
|
case v2keymanager.Direct:
|
2020-08-02 20:02:04 +00:00
|
|
|
return errors.New("not possible to edit direct keymanager configuration")
|
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:
|
2020-09-17 01:34:42 +00:00
|
|
|
enc, err := w.ReadKeymanagerConfigFromDisk(cliCtx.Context)
|
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 read config")
|
2020-07-16 05:08:16 +00:00
|
|
|
}
|
2020-08-31 19:46:45 +00:00
|
|
|
opts, err := remote.UnmarshalOptionsFile(enc)
|
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 unmarshal config")
|
2020-07-16 05:08:16 +00:00
|
|
|
}
|
2020-07-29 01:20:13 +00:00
|
|
|
log.Info("Current configuration")
|
|
|
|
// Prints the current configuration to stdout.
|
2020-08-31 19:46:45 +00:00
|
|
|
fmt.Println(opts)
|
2020-09-17 01:34:42 +00:00
|
|
|
newCfg, err := prompt.InputRemoteKeymanagerConfig(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 get keymanager config")
|
2020-07-16 05:08:16 +00:00
|
|
|
}
|
2020-08-31 19:46:45 +00:00
|
|
|
encodedCfg, err := remote.MarshalOptionsFile(cliCtx.Context, newCfg)
|
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 marshal config file")
|
2020-07-16 05:08:16 +00:00
|
|
|
}
|
2020-09-17 01:34:42 +00:00
|
|
|
if err := w.WriteKeymanagerConfigToDisk(cliCtx.Context, 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-09-17 01:34:42 +00:00
|
|
|
return fmt.Errorf("keymanager type %s is not supported", w.KeymanagerKind())
|
2020-07-16 05:08:16 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|