prysm-pulse/validator/accounts/cli_manager.go
Sammy Rosso a15e0797e4
Support non english mnemonics for wallet creation (#11543)
* add option to log rejected gossip message

* add bip39 supported mnemonic languages

* Revert "add option to log rejected gossip message"

This reverts commit 9a3d4486f6c8a623d9eb6b3af1a5a89aa62ecf2f.

* Add mnemonic language flag

* Update go.mod

* Simplify language mapping

* Add test for setBip39Lang

* Update go.mod

* Improve language matching

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>

* Run gazelle + fix maligned struct

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2022-10-26 21:04:00 +00:00

75 lines
2.4 KiB
Go

package accounts
import (
"context"
"github.com/pkg/errors"
grpcutil "github.com/prysmaticlabs/prysm/v3/api/grpc"
"github.com/prysmaticlabs/prysm/v3/crypto/bls"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/validator/accounts/wallet"
"github.com/prysmaticlabs/prysm/v3/validator/keymanager"
"github.com/prysmaticlabs/prysm/v3/validator/keymanager/remote"
"google.golang.org/grpc"
)
// NewCLIManager allows for managing validator accounts via CLI commands.
func NewCLIManager(opts ...Option) (*AccountsCLIManager, error) {
acc := &AccountsCLIManager{}
for _, opt := range opts {
if err := opt(acc); err != nil {
return nil, err
}
}
return acc, nil
}
// AccountsCLIManager defines a struct capable of performing various validator
// wallet & account operations via the command line.
type AccountsCLIManager struct {
wallet *wallet.Wallet
keymanager keymanager.IKeymanager
keymanagerKind keymanager.Kind
keymanagerOpts *remote.KeymanagerOpts
showDepositData bool
showPrivateKeys bool
listValidatorIndices bool
deletePublicKeys bool
importPrivateKeys bool
readPasswordFile bool
skipMnemonicConfirm bool
dialOpts []grpc.DialOption
grpcHeaders []string
beaconRPCProvider string
walletKeyCount int
privateKeyFile string
passwordFilePath string
keysDir string
mnemonicLanguage string
backupsDir string
backupsPassword string
filteredPubKeys []bls.PublicKey
rawPubKeys [][]byte
formattedPubKeys []string
walletDir string
walletPassword string
mnemonic string
numAccounts int
mnemonic25thWord string
}
func (acm *AccountsCLIManager) prepareBeaconClients(ctx context.Context) (*ethpb.BeaconNodeValidatorClient, *ethpb.NodeClient, error) {
if acm.dialOpts == nil {
return nil, nil, errors.New("failed to construct dial options for beacon clients")
}
ctx = grpcutil.AppendHeaders(ctx, acm.grpcHeaders)
conn, err := grpc.DialContext(ctx, acm.beaconRPCProvider, acm.dialOpts...)
if err != nil {
return nil, nil, errors.Wrapf(err, "could not dial endpoint %s", acm.beaconRPCProvider)
}
validatorClient := ethpb.NewBeaconNodeValidatorClient(conn)
nodeClient := ethpb.NewNodeClient(conn)
return &validatorClient, &nodeClient, nil
}