prysm-pulse/validator/accounts/cli_manager.go
terencechain d17996f8b0
Update to V4 🚀 (#12134)
* Update V3 from V4

* Fix build v3 -> v4

* Update ssz

* Update beacon_chain.pb.go

* Fix formatter import

* Update update-mockgen.sh comment to v4

* Fix conflicts. Pass build and tests

* Fix test
2023-03-17 18:52:56 +00:00

89 lines
2.8 KiB
Go

package accounts
import (
"context"
"time"
"github.com/pkg/errors"
grpcutil "github.com/prysmaticlabs/prysm/v4/api/grpc"
"github.com/prysmaticlabs/prysm/v4/crypto/bls"
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v4/validator/accounts/wallet"
iface "github.com/prysmaticlabs/prysm/v4/validator/client/iface"
validatorClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/validator-client-factory"
validatorHelpers "github.com/prysmaticlabs/prysm/v4/validator/helpers"
"github.com/prysmaticlabs/prysm/v4/validator/keymanager"
"github.com/prysmaticlabs/prysm/v4/validator/keymanager/derived"
"google.golang.org/grpc"
)
// NewCLIManager allows for managing validator accounts via CLI commands.
func NewCLIManager(opts ...Option) (*AccountsCLIManager, error) {
acc := &AccountsCLIManager{
mnemonicLanguage: derived.DefaultMnemonicLanguage,
}
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
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
beaconApiEndpoint string
beaconApiTimeout time.Duration
}
func (acm *AccountsCLIManager) prepareBeaconClients(ctx context.Context) (*iface.ValidatorClient, *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)
grpcConn, err := grpc.DialContext(ctx, acm.beaconRPCProvider, acm.dialOpts...)
if err != nil {
return nil, nil, errors.Wrapf(err, "could not dial endpoint %s", acm.beaconRPCProvider)
}
conn := validatorHelpers.NewNodeConnection(
grpcConn,
acm.beaconApiEndpoint,
acm.beaconApiTimeout,
)
validatorClient := validatorClientFactory.NewValidatorClient(conn)
nodeClient := ethpb.NewNodeClient(grpcConn)
return &validatorClient, &nodeClient, nil
}