2022-04-28 14:46:46 +00:00
|
|
|
package accounts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2022-08-16 12:20:13 +00:00
|
|
|
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"
|
2022-04-28 14:46:46 +00:00
|
|
|
"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
|
2022-08-24 16:57:03 +00:00
|
|
|
// wallet & account operations via the command line.
|
2022-04-28 14:46:46 +00:00
|
|
|
type AccountsCLIManager struct {
|
|
|
|
wallet *wallet.Wallet
|
|
|
|
keymanager keymanager.IKeymanager
|
2022-09-02 14:56:47 +00:00
|
|
|
keymanagerKind keymanager.Kind
|
2022-08-03 19:44:37 +00:00
|
|
|
keymanagerOpts *remote.KeymanagerOpts
|
2022-04-28 14:46:46 +00:00
|
|
|
showDepositData bool
|
|
|
|
showPrivateKeys bool
|
|
|
|
listValidatorIndices bool
|
2022-05-17 23:13:36 +00:00
|
|
|
deletePublicKeys bool
|
2022-06-16 14:14:03 +00:00
|
|
|
importPrivateKeys bool
|
|
|
|
readPasswordFile bool
|
2022-09-02 14:56:47 +00:00
|
|
|
skipMnemonicConfirm bool
|
2022-04-28 14:46:46 +00:00
|
|
|
dialOpts []grpc.DialOption
|
|
|
|
grpcHeaders []string
|
|
|
|
beaconRPCProvider string
|
2022-05-17 23:13:36 +00:00
|
|
|
walletKeyCount int
|
2022-06-16 14:14:03 +00:00
|
|
|
privateKeyFile string
|
|
|
|
passwordFilePath string
|
|
|
|
keysDir string
|
2022-10-26 21:04:00 +00:00
|
|
|
mnemonicLanguage string
|
2022-06-07 15:19:12 +00:00
|
|
|
backupsDir string
|
|
|
|
backupsPassword string
|
2022-06-13 15:17:46 +00:00
|
|
|
filteredPubKeys []bls.PublicKey
|
|
|
|
rawPubKeys [][]byte
|
|
|
|
formattedPubKeys []string
|
2022-08-24 16:57:03 +00:00
|
|
|
walletDir string
|
|
|
|
walletPassword string
|
|
|
|
mnemonic string
|
|
|
|
numAccounts int
|
|
|
|
mnemonic25thWord string
|
2022-04-28 14:46:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|