prysm-pulse/cmd/validator/accounts/wallet_utils.go
james-prysm df694aad71
prysmctl: validator exit (#11515)
* moving voluntary exit command to prysmctl

* fixing linting

* fixing imports

* removing unused import:

* refactoring and adding a new unit test

* rolling back some changes

* fixing parameters

* fixing tests

* adding to main prysm ctl

* refactoring how wallet function works and ux to validator exit

* adding interop support

* fixing bazel build

* fixing if statement

* fixing beaconcha.in printout

* fixing web3signer bug, missing signing slot info

* fixing deep source issues

* fixing bazel package visibility for prysmctl

* gaz

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
2022-10-17 16:04:19 -05:00

41 lines
1.4 KiB
Go

package accounts
import (
"strings"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v3/validator/accounts"
"github.com/prysmaticlabs/prysm/v3/validator/accounts/iface"
"github.com/prysmaticlabs/prysm/v3/validator/accounts/wallet"
"github.com/prysmaticlabs/prysm/v3/validator/keymanager"
remote_web3signer "github.com/prysmaticlabs/prysm/v3/validator/keymanager/remote-web3signer"
"github.com/urfave/cli/v2"
)
func walletWithKeymanager(c *cli.Context) (*wallet.Wallet, keymanager.IKeymanager, error) {
w, err := wallet.OpenWalletOrElseCli(c, func(cliCtx *cli.Context) (*wallet.Wallet, error) {
return nil, wallet.ErrNoWalletFound
})
if err != nil {
return nil, nil, errors.Wrap(err, "could not open wallet")
}
km, err := w.InitializeKeymanager(c.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
if err != nil && strings.Contains(err.Error(), keymanager.IncorrectPasswordErrMsg) {
return nil, nil, errors.New("wrong wallet password entered")
}
if err != nil {
return nil, nil, errors.Wrap(err, accounts.ErrCouldNotInitializeKeymanager)
}
return w, km, nil
}
func walletWithWeb3SignerKeymanager(c *cli.Context, config *remote_web3signer.SetupConfig) (*wallet.Wallet, keymanager.IKeymanager, error) {
w := wallet.NewWalletForWeb3Signer()
km, err := w.InitializeKeymanager(c.Context, iface.InitKeymanagerConfig{ListenForChanges: false, Web3SignerConfig: config})
if err != nil {
return nil, nil, err
}
return w, km, nil
}