2022-04-28 14:46:46 +00:00
|
|
|
package accounts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-11-11 17:33:48 +00:00
|
|
|
"time"
|
2022-04-28 14:46:46 +00:00
|
|
|
|
|
|
|
"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"
|
2022-11-07 10:29:27 +00:00
|
|
|
iface "github.com/prysmaticlabs/prysm/v3/validator/client/iface"
|
|
|
|
validatorClientFactory "github.com/prysmaticlabs/prysm/v3/validator/client/validator-client-factory"
|
2022-11-11 17:33:48 +00:00
|
|
|
validatorHelpers "github.com/prysmaticlabs/prysm/v3/validator/helpers"
|
2022-08-16 12:20:13 +00:00
|
|
|
"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-11-11 17:33:48 +00:00
|
|
|
beaconApiEndpoint string
|
|
|
|
beaconApiTimeout time.Duration
|
2022-04-28 14:46:46 +00:00
|
|
|
}
|
|
|
|
|
2022-11-07 10:29:27 +00:00
|
|
|
func (acm *AccountsCLIManager) prepareBeaconClients(ctx context.Context) (*iface.ValidatorClient, *ethpb.NodeClient, error) {
|
2022-04-28 14:46:46 +00:00
|
|
|
if acm.dialOpts == nil {
|
|
|
|
return nil, nil, errors.New("failed to construct dial options for beacon clients")
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx = grpcutil.AppendHeaders(ctx, acm.grpcHeaders)
|
2022-11-11 17:33:48 +00:00
|
|
|
grpcConn, err := grpc.DialContext(ctx, acm.beaconRPCProvider, acm.dialOpts...)
|
2022-04-28 14:46:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, errors.Wrapf(err, "could not dial endpoint %s", acm.beaconRPCProvider)
|
|
|
|
}
|
2022-11-11 17:33:48 +00:00
|
|
|
|
|
|
|
conn := validatorHelpers.NewNodeConnection(
|
|
|
|
grpcConn,
|
|
|
|
acm.beaconApiEndpoint,
|
|
|
|
acm.beaconApiTimeout,
|
|
|
|
)
|
|
|
|
|
2022-11-07 10:29:27 +00:00
|
|
|
validatorClient := validatorClientFactory.NewValidatorClient(conn)
|
2022-11-11 17:33:48 +00:00
|
|
|
nodeClient := ethpb.NewNodeClient(grpcConn)
|
2022-04-28 14:46:46 +00:00
|
|
|
return &validatorClient, &nodeClient, nil
|
|
|
|
}
|