mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Add names to certain return values in accounts (#8159)
* add names to certain return values * remove redundant * rename selected public keys Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
@@ -120,7 +120,7 @@ func BackupAccountsCli(cliCtx *cli.Context) error {
|
||||
}
|
||||
|
||||
// Ask user to select accounts via an interactive prompt.
|
||||
func selectAccounts(selectionPrompt string, pubKeys [][48]byte) ([]bls.PublicKey, error) {
|
||||
func selectAccounts(selectionPrompt string, pubKeys [][48]byte) (filteredPubKeys []bls.PublicKey, err error) {
|
||||
pubKeyStrings := make([]string, len(pubKeys))
|
||||
for i, pk := range pubKeys {
|
||||
name := petnames.DeterministicName(pk[:], "-")
|
||||
@@ -138,7 +138,6 @@ func selectAccounts(selectionPrompt string, pubKeys [][48]byte) ([]bls.PublicKey
|
||||
{{ "Name:" | faint }} {{ .Name }}`,
|
||||
}
|
||||
var result string
|
||||
var err error
|
||||
exit := "Done selecting"
|
||||
results := make([]int, 0)
|
||||
au := aurora.NewAurora(true)
|
||||
@@ -184,7 +183,7 @@ func selectAccounts(selectionPrompt string, pubKeys [][48]byte) ([]bls.PublicKey
|
||||
}
|
||||
|
||||
// Filter the public keys based on user input.
|
||||
filteredPubKeys := make([]bls.PublicKey, 0)
|
||||
filteredPubKeys = make([]bls.PublicKey, 0)
|
||||
for selectedIndex := range seen {
|
||||
pk, err := bls.PublicKeyFromBytes(pubKeys[selectedIndex][:])
|
||||
if err != nil {
|
||||
|
||||
@@ -74,7 +74,7 @@ func ExitAccountsCli(cliCtx *cli.Context, r io.Reader) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func prepareWallet(cliCtx *cli.Context) ([][48]byte, keymanager.IKeymanager, error) {
|
||||
func prepareWallet(cliCtx *cli.Context) (validatingPublicKeys [][48]byte, km keymanager.IKeymanager, err error) {
|
||||
w, err := wallet.OpenWalletOrElseCli(cliCtx, func(cliCtx *cli.Context) (*wallet.Wallet, error) {
|
||||
return nil, wallet.ErrNoWalletFound
|
||||
})
|
||||
@@ -82,11 +82,11 @@ func prepareWallet(cliCtx *cli.Context) ([][48]byte, keymanager.IKeymanager, err
|
||||
return nil, nil, errors.Wrap(err, "could not open wallet")
|
||||
}
|
||||
|
||||
keymanager, err := w.InitializeKeymanager(cliCtx.Context)
|
||||
km, err = w.InitializeKeymanager(cliCtx.Context)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "could not initialize keymanager")
|
||||
}
|
||||
validatingPublicKeys, err := keymanager.FetchValidatingPublicKeys(cliCtx.Context)
|
||||
validatingPublicKeys, err = km.FetchValidatingPublicKeys(cliCtx.Context)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -94,10 +94,14 @@ func prepareWallet(cliCtx *cli.Context) ([][48]byte, keymanager.IKeymanager, err
|
||||
return nil, nil, errors.New("wallet is empty, no accounts to perform voluntary exit")
|
||||
}
|
||||
|
||||
return validatingPublicKeys, keymanager, nil
|
||||
return validatingPublicKeys, km, nil
|
||||
}
|
||||
|
||||
func interact(cliCtx *cli.Context, r io.Reader, validatingPublicKeys [][48]byte) ([][]byte, []string, error) {
|
||||
func interact(
|
||||
cliCtx *cli.Context,
|
||||
r io.Reader,
|
||||
validatingPublicKeys [][48]byte,
|
||||
) (rawPubKeys [][]byte, formattedPubKeys []string, err error) {
|
||||
// Allow the user to interactively select the accounts to exit or optionally
|
||||
// provide them via cli flags as a string of comma-separated, hex strings.
|
||||
filteredPubKeys, err := filterPublicKeysFromUserInput(
|
||||
@@ -109,8 +113,8 @@ func interact(cliCtx *cli.Context, r io.Reader, validatingPublicKeys [][48]byte)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "could not filter public keys for voluntary exit")
|
||||
}
|
||||
rawPubKeys := make([][]byte, len(filteredPubKeys))
|
||||
formattedPubKeys := make([]string, len(filteredPubKeys))
|
||||
rawPubKeys = make([][]byte, len(filteredPubKeys))
|
||||
formattedPubKeys = make([]string, len(filteredPubKeys))
|
||||
for i, pk := range filteredPubKeys {
|
||||
pubKeyBytes := pk.Marshal()
|
||||
rawPubKeys[i] = pubKeyBytes
|
||||
|
||||
@@ -144,7 +144,7 @@ func RecoverWallet(ctx context.Context, cfg *RecoverWalletConfig) (*wallet.Walle
|
||||
return w, nil
|
||||
}
|
||||
|
||||
func inputMnemonic(cliCtx *cli.Context) (string, error) {
|
||||
func inputMnemonic(cliCtx *cli.Context) (mnemonicPhrase string, err error) {
|
||||
if cliCtx.IsSet(flags.MnemonicFileFlag.Name) {
|
||||
mnemonicFilePath := cliCtx.String(flags.MnemonicFileFlag.Name)
|
||||
data, err := ioutil.ReadFile(mnemonicFilePath)
|
||||
@@ -186,7 +186,7 @@ func inputMnemonic(cliCtx *cli.Context) (string, error) {
|
||||
return "", fmt.Errorf("could not get mnemonic language: %w", err)
|
||||
}
|
||||
bip39.SetWordList(allowedLanguages[selectedLanguage])
|
||||
mnemonicPhrase, err := promptutil.ValidatePrompt(
|
||||
mnemonicPhrase, err = promptutil.ValidatePrompt(
|
||||
os.Stdin,
|
||||
"Enter the seed phrase for the wallet you would like to recover",
|
||||
validateMnemonic)
|
||||
|
||||
Reference in New Issue
Block a user