Skip to content

Commit

Permalink
add prompt check for minimum validator staking timr
Browse files Browse the repository at this point in the history
  • Loading branch information
arturrez committed Nov 14, 2024
1 parent 3b697ec commit c99cb2d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/blockchaincmd/add_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,8 @@ func PromptDuration(start time.Time, network models.Network) (time.Duration, err
d, err = app.Prompt.CaptureFujiDuration(txt)
case models.Mainnet:
d, err = app.Prompt.CaptureMainnetDuration(txt)
case models.Local:
d, err = app.Prompt.CaptureLocalDuration(txt)
default:
d, err = app.Prompt.CaptureDuration(txt)
}
Expand Down
8 changes: 8 additions & 0 deletions internal/mocks/prompter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/constants/etna.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package constants

import (
_ "embed"
"time"
)

//go:embed etnaDevnet/genesis.json
Expand Down Expand Up @@ -33,3 +34,5 @@ var (
"98.82.41.186:9651",
}
)

const StakingEtnaMinimumDuration = 100 * time.Second
15 changes: 15 additions & 0 deletions pkg/prompts/prompts.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ type Prompter interface {
CaptureIndex(promptStr string, options []any) (int, error)
CaptureVersion(promptStr string) (string, error)
CaptureDuration(promptStr string) (time.Duration, error)
CaptureLocalDuration(promptStr string) (time.Duration, error)
CaptureFujiDuration(promptStr string) (time.Duration, error)
CaptureMainnetDuration(promptStr string) (time.Duration, error)
CaptureDate(promptStr string) (time.Time, error)
Expand Down Expand Up @@ -204,6 +205,20 @@ func CaptureListDecision[T comparable](
}
}

func (*realPrompter) CaptureLocalDuration(promptStr string) (time.Duration, error) {
prompt := promptui.Prompt{
Label: promptStr,
Validate: validateLocalDuration,
}

durationStr, err := prompt.Run()
if err != nil {
return 0, err
}

return time.ParseDuration(durationStr)
}

func (*realPrompter) CaptureDuration(promptStr string) (time.Duration, error) {
prompt := promptui.Prompt{
Label: promptStr,
Expand Down
11 changes: 11 additions & 0 deletions pkg/prompts/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ func validateFujiStakingDuration(input string) error {
return nil
}

func validateLocalDuration(input string) error {
d, err := time.ParseDuration(input)
if err != nil {
return err
}
if d < constants.StakingEtnaMinimumDuration {
return fmt.Errorf("below the minimum staking duration of %s", ux.FormatDuration(constants.StakingEtnaMinimumDuration))
}
return nil
}

func validateDuration(input string) error {
_, err := time.ParseDuration(input)
return err
Expand Down

0 comments on commit c99cb2d

Please sign in to comment.