prysm-pulse/validator/accounts/wallet_edit.go
Radosław Kapka 8ffb95bd9d
Allow dynamic key reloading when having inactive keys (imported & derived) (#8119)
* restart waiting for activation on key change

* test fixes

* wiat for activation comments

* regression test

* log fatal when validator cast fails

* derived keymanager

* review comments

* add buffer to channel

* simplify key refetch logic

* reload keys into empty wallet

* removed warning on wallet creation

* add empty line

* export AccountsKeystoreRepresentation type

* unit test for handleAccountsChanged

* test ctx cancellation

* add missing mockRemoteKeymanager interface function

* gazelle

* gzl

* fix panic inside goroutine during runner tests

* rename error message variables

* Update validator/accounts/accounts_list_test.go

* reorder imports

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
2021-01-22 20:21:34 +00:00

57 lines
1.9 KiB
Go

package accounts
import (
"fmt"
"github.com/pkg/errors"
"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"
"github.com/urfave/cli/v2"
)
// EditWalletConfigurationCli 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 EditWalletConfigurationCli(cliCtx *cli.Context) error {
w, err := wallet.OpenWalletOrElseCli(cliCtx, func(cliCtx *cli.Context) (*wallet.Wallet, error) {
return nil, wallet.ErrNoWalletFound
})
if err != nil {
return errors.Wrap(err, "could not open wallet")
}
switch w.KeymanagerKind() {
case keymanager.Imported:
return errors.New("not possible to edit imported keymanager configuration")
case keymanager.Derived:
return errors.New("derived keymanager is not yet supported")
case keymanager.Remote:
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 := prompt.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")
}
default:
return fmt.Errorf(errKeymanagerNotSupported, w.KeymanagerKind())
}
return nil
}