Skip to content

Commit

Permalink
Check max balance on add validator (#2278)
Browse files Browse the repository at this point in the history
* regen mocks

* addres PR comment

* address PR comment
  • Loading branch information
felipemadero authored Oct 18, 2024
1 parent 1e7e91e commit 4708121
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 39 deletions.
15 changes: 12 additions & 3 deletions cmd/blockchaincmd/add_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ func addValidator(_ *cobra.Command, args []string) error {
return CallAddValidator(deployer, network, kc, blockchainName, nodeIDStr, publicKey, pop)
}

func promptValidatorBalance() (uint64, error) {
func promptValidatorBalance(availableBalance uint64) (uint64, error) {
ux.Logger.PrintToUser("Validator's balance is used to pay for continuous fee to the P-Chain")
ux.Logger.PrintToUser("When this Balance reaches 0, the validator will be considered inactive and will no longer participate in validating the L1")
txt := "What balance would you like to assign to the bootstrap validator (in AVAX)?"
return app.Prompt.CaptureValidatorBalance(txt)
return app.Prompt.CaptureValidatorBalance(txt, availableBalance)
}

func CallAddValidator(
Expand Down Expand Up @@ -254,8 +254,17 @@ func CallAddValidator(
}
}

ctx, cancel := utils.GetAPIContext()
defer cancel()
pClient := platformvm.NewClient(network.Endpoint)
bal, err := pClient.GetBalance(ctx, kc.Addresses().List())
if err != nil {
return err
}
availableBalance := uint64(bal.Balance) / units.Avax

if balance == 0 {
balanceAVAX, err := promptValidatorBalance()
balanceAVAX, err := promptValidatorBalance(availableBalance)
if err != nil {
return err
}
Expand Down
18 changes: 9 additions & 9 deletions internal/mocks/process_checker.go

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

Loading

0 comments on commit 4708121

Please sign in to comment.