2020-10-15 22:31:52 +00:00
|
|
|
package accounts
|
2020-07-16 05:08:16 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2021-09-17 21:55:24 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/validator/accounts/userprompt"
|
2020-10-15 22:31:52 +00:00
|
|
|
"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
|
|
|
}
|
2022-03-22 03:04:09 +00:00
|
|
|
if w.KeymanagerKind() != keymanager.Remote {
|
|
|
|
return errors.New(
|
|
|
|
fmt.Sprintf("Keymanager type: %s doesn't support configuration editing",
|
|
|
|
w.KeymanagerKind().String()))
|
|
|
|
}
|
|
|
|
return editRemoteWallet(cliCtx, w)
|
|
|
|
}
|
|
|
|
|
|
|
|
func editRemoteWallet(cliCtx *cli.Context, w *wallet.Wallet) error {
|
|
|
|
enc, err := w.ReadKeymanagerConfigFromDisk(cliCtx.Context)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not read config")
|
|
|
|
}
|
|
|
|
opts, err := remote.UnmarshalOptionsFile(enc)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not unmarshal config")
|
|
|
|
}
|
|
|
|
log.Info("Current configuration")
|
|
|
|
// Prints the current configuration to stdout.
|
|
|
|
fmt.Println(opts)
|
|
|
|
newCfg, err := userprompt.InputRemoteKeymanagerConfig(cliCtx)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not get keymanager config")
|
|
|
|
}
|
|
|
|
encodedCfg, err := remote.MarshalOptionsFile(cliCtx.Context, newCfg)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not marshal config file")
|
|
|
|
}
|
|
|
|
if err := w.WriteKeymanagerConfigToDisk(cliCtx.Context, encodedCfg); err != nil {
|
|
|
|
return errors.Wrap(err, "could not write config to disk")
|
2020-07-16 05:08:16 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|