2022-06-16 14:14:03 +00:00
|
|
|
package accounts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2024-02-15 05:46:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/cmd"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/cmd/validator/flags"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/validator/accounts"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/validator/accounts/iface"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/validator/accounts/userprompt"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/validator/accounts/wallet"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/validator/client"
|
2022-06-16 14:14:03 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func accountsImport(c *cli.Context) error {
|
|
|
|
w, err := walletImport(c)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not initialize wallet")
|
|
|
|
}
|
|
|
|
km, err := w.InitializeKeymanager(c.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
dialOpts := client.ConstructDialOptions(
|
|
|
|
c.Int(cmd.GrpcMaxCallRecvMsgSizeFlag.Name),
|
|
|
|
c.String(flags.CertFlag.Name),
|
|
|
|
c.Uint(flags.GrpcRetriesFlag.Name),
|
|
|
|
c.Duration(flags.GrpcRetryDelayFlag.Name),
|
|
|
|
)
|
|
|
|
grpcHeaders := strings.Split(c.String(flags.GrpcHeadersFlag.Name), ",")
|
|
|
|
|
|
|
|
opts := []accounts.Option{
|
|
|
|
accounts.WithWallet(w),
|
|
|
|
accounts.WithKeymanager(km),
|
|
|
|
accounts.WithGRPCDialOpts(dialOpts),
|
|
|
|
accounts.WithBeaconRPCProvider(c.String(flags.BeaconRPCProviderFlag.Name)),
|
2022-11-11 17:33:48 +00:00
|
|
|
accounts.WithBeaconRESTApiProvider(c.String(flags.BeaconRESTApiProviderFlag.Name)),
|
2022-06-16 14:14:03 +00:00
|
|
|
accounts.WithGRPCHeaders(grpcHeaders),
|
|
|
|
}
|
|
|
|
|
|
|
|
opts = append(opts, accounts.WithImportPrivateKeys(c.IsSet(flags.ImportPrivateKeyFileFlag.Name)))
|
|
|
|
opts = append(opts, accounts.WithPrivateKeyFile(c.String(flags.ImportPrivateKeyFileFlag.Name)))
|
|
|
|
opts = append(opts, accounts.WithReadPasswordFile(c.IsSet(flags.AccountPasswordFileFlag.Name)))
|
|
|
|
opts = append(opts, accounts.WithPasswordFilePath(c.String(flags.AccountPasswordFileFlag.Name)))
|
|
|
|
|
|
|
|
keysDir, err := userprompt.InputDirectory(c, userprompt.ImportKeysDirPromptText, flags.KeysDirFlag)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not parse keys directory")
|
|
|
|
}
|
|
|
|
opts = append(opts, accounts.WithKeysDir(keysDir))
|
|
|
|
|
|
|
|
acc, err := accounts.NewCLIManager(opts...)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return acc.Import(c.Context)
|
|
|
|
}
|
|
|
|
|
|
|
|
func walletImport(c *cli.Context) (*wallet.Wallet, error) {
|
2023-12-13 17:11:32 +00:00
|
|
|
return wallet.OpenWalletOrElseCli(c, wallet.OpenOrCreateNewWallet)
|
2022-09-02 14:56:47 +00:00
|
|
|
}
|