Compare commits

...

1 Commits

Author SHA1 Message Date
Daniel Van Der Maden ed1b42c454
[staking] Verify BLS key input 4 years ago
  1. 27
      cmd/subcommands/staking.go

@ -1,7 +1,6 @@
package cmd
import (
"errors"
"fmt"
"math/big"
"strconv"
@ -27,6 +26,7 @@ import (
"github.com/harmony-one/harmony/shard"
"github.com/harmony-one/harmony/staking/effective"
staking "github.com/harmony-one/harmony/staking/types"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@ -284,10 +284,31 @@ func ensureLength(d staking.Description) (staking.Description, error) {
if len(d.Details) > MaxDetailsLength {
return d, errInvalidDescFieldDetails
}
return d, nil
}
func assertValidOptionStringInputForNonNumbers(input string) error {
if input != "" && strings.HasPrefix(input, "-") {
return fmt.Errorf("invalid or missing option")
}
return nil
}
func validateBlsKeyInput(cmd *cobra.Command, args []string) error {
if err := assertValidOptionStringInputForNonNumbers(slotKeyToAdd); err != nil {
return errors.WithMessage(err, "BLS key to add error")
}
if err := assertValidOptionStringInputForNonNumbers(slotKeyToRemove); err != nil {
return errors.WithMessage(err, "BLS key to remove error")
}
for _, str := range stakingBlsPubKeys {
if err := assertValidOptionStringInputForNonNumbers(str); err != nil {
return errors.WithMessage(err, "BLS key to create validator error")
}
}
return nil
}
func stakingSubCommands() []*cobra.Command {
subCmdNewValidator := &cobra.Command{
@ -297,6 +318,7 @@ func stakingSubCommands() []*cobra.Command {
Long: `
Create a new validator"
`,
PreRunE: validateBlsKeyInput,
RunE: func(cmd *cobra.Command, args []string) error {
networkHandler, err := handlerForShard(0, node)
if err != nil {
@ -459,6 +481,7 @@ Create a new validator"
Short: "edit a validator",
Long: "Edit an existing validator",
Args: cobra.ExactArgs(0),
PreRunE: validateBlsKeyInput,
RunE: func(cmd *cobra.Command, args []string) error {
networkHandler, err := handlerForShard(shard.BeaconChainShardID, node)
if err != nil {

Loading…
Cancel
Save