mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
a81c863ddb
* rename accounts v2 * rename keymanager and fix imports * rename accounts-v2 instances * imports * build * build fix * deepsource * fix up broken aliases * imports * gaz * Update validator/accounts/accounts_import_test.go Co-authored-by: Ivan Martinez <ivanthegreatdev@gmail.com> * fmt Co-authored-by: Ivan Martinez <ivanthegreatdev@gmail.com>
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package accounts
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/shared/bls"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
func filterPublicKeysFromUserInput(
|
|
cliCtx *cli.Context,
|
|
publicKeysFlag *cli.StringFlag,
|
|
validatingPublicKeys [][48]byte,
|
|
selectionPrompt string,
|
|
) ([]bls.PublicKey, error) {
|
|
var filteredPubKeys []bls.PublicKey
|
|
if cliCtx.IsSet(publicKeysFlag.Name) {
|
|
pubKeyStrings := strings.Split(cliCtx.String(publicKeysFlag.Name), ",")
|
|
if len(pubKeyStrings) == 0 {
|
|
return nil, fmt.Errorf(
|
|
"could not parse %s. It must be a string of comma-separated hex strings",
|
|
publicKeysFlag.Name,
|
|
)
|
|
}
|
|
for _, str := range pubKeyStrings {
|
|
pkString := str
|
|
if strings.Contains(pkString, "0x") {
|
|
pkString = pkString[2:]
|
|
}
|
|
pubKeyBytes, err := hex.DecodeString(pkString)
|
|
if err != nil {
|
|
return nil, errors.Wrapf(err, "could not decode string %s as hex", pkString)
|
|
}
|
|
blsPublicKey, err := bls.PublicKeyFromBytes(pubKeyBytes)
|
|
if err != nil {
|
|
return nil, errors.Wrapf(err, "%#x is not a valid BLS public key", pubKeyBytes)
|
|
}
|
|
filteredPubKeys = append(filteredPubKeys, blsPublicKey)
|
|
}
|
|
return filteredPubKeys, nil
|
|
}
|
|
return selectAccounts(selectionPrompt, validatingPublicKeys)
|
|
}
|