Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Check max balance on add validator #2278

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading