mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
8aa6057b60
* Wallet edit CLI Manager migration * TODO for code deduplication * s/walletEdit/remoteWalletEdit/g * s/walletEdit/remoteWalletEdit/g * remove unused struct field Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
67 lines
2.1 KiB
Go
67 lines
2.1 KiB
Go
package accounts
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/pkg/errors"
|
|
grpcutil "github.com/prysmaticlabs/prysm/api/grpc"
|
|
"github.com/prysmaticlabs/prysm/crypto/bls"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
|
"github.com/prysmaticlabs/prysm/validator/keymanager"
|
|
"github.com/prysmaticlabs/prysm/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
|
|
keymanagerOpts *remote.KeymanagerOpts
|
|
showDepositData bool
|
|
showPrivateKeys bool
|
|
listValidatorIndices bool
|
|
deletePublicKeys bool
|
|
importPrivateKeys bool
|
|
readPasswordFile bool
|
|
dialOpts []grpc.DialOption
|
|
grpcHeaders []string
|
|
beaconRPCProvider string
|
|
walletKeyCount int
|
|
privateKeyFile string
|
|
passwordFilePath string
|
|
keysDir string
|
|
backupsDir string
|
|
backupsPassword string
|
|
filteredPubKeys []bls.PublicKey
|
|
rawPubKeys [][]byte
|
|
formattedPubKeys []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
|
|
}
|