2020-10-15 22:31:52 +00:00
|
|
|
package accounts
|
2020-07-16 05:08:16 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2020-10-15 22:31:52 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/validator/accounts/prompt"
|
|
|
|
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
|
|
|
"github.com/prysmaticlabs/prysm/validator/keymanager"
|
|
|
|
"github.com/prysmaticlabs/prysm/validator/keymanager/remote"
|
2020-07-16 05:08:16 +00:00
|
|
|
"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-10-22 17:31:03 +00:00
|
|
|
return nil, wallet.ErrNoWalletFound
|
2020-08-31 19:46:45 +00:00
|
|
|
})
|
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-10-16 18:45:14 +00:00
|
|
|
case keymanager.Imported:
|
|
|
|
return errors.New("not possible to edit imported keymanager configuration")
|
2020-10-15 22:31:52 +00:00
|
|
|
case keymanager.Derived:
|
2020-07-22 02:04:08 +00:00
|
|
|
return errors.New("derived keymanager is not yet supported")
|
2020-10-15 22:31:52 +00:00
|
|
|
case keymanager.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:
|
2021-01-22 20:21:34 +00:00
|
|
|
return fmt.Errorf(errKeymanagerNotSupported, w.KeymanagerKind())
|
2020-07-16 05:08:16 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|