Skip to content

Commit d36296b

Browse files
Fix convert (#2625)
* fix convert * Fix assignment mismatch (#2627) Signed-off-by: Martin Eckardt <[email protected]> --------- Signed-off-by: Martin Eckardt <[email protected]> Co-authored-by: Martin Eckardt <[email protected]>
1 parent 394ce8e commit d36296b

File tree

1 file changed

+67
-62
lines changed

1 file changed

+67
-62
lines changed

cmd/blockchaincmd/convert.go

Lines changed: 67 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ func convertBlockchain(_ *cobra.Command, args []string) error {
481481
globalNetworkFlags,
482482
true,
483483
false,
484-
networkoptions.DefaultSupportedNetworkOptions,
484+
networkoptions.GetNetworkFromSidecar(sidecar, networkoptions.DefaultSupportedNetworkOptions),
485485
"",
486486
)
487487
if err != nil {
@@ -492,21 +492,24 @@ func convertBlockchain(_ *cobra.Command, args []string) error {
492492
subnetID := sidecar.Networks[network.Name()].SubnetID
493493
blockchainID := sidecar.Networks[network.Name()].BlockchainID
494494

495-
if validatorManagerAddress == "" {
496-
validatorManagerAddressAddrFmt, err := app.Prompt.CaptureAddress("What is the address of the Validator Manager?")
497-
if err != nil {
495+
if !convertOnly {
496+
if validatorManagerAddress == "" {
497+
validatorManagerAddressAddrFmt, err := app.Prompt.CaptureAddress("What is the address of the Validator Manager?")
498+
if err != nil {
499+
return err
500+
}
501+
validatorManagerAddress = validatorManagerAddressAddrFmt.String()
502+
}
503+
504+
if err = promptValidatorManagementType(app, &sidecar); err != nil {
498505
return err
499506
}
500-
validatorManagerAddress = validatorManagerAddressAddrFmt.String()
507+
if err := setSidecarValidatorManageOwner(&sidecar, createFlags); err != nil {
508+
return err
509+
}
510+
sidecar.UpdateValidatorManagerAddress(network.Name(), validatorManagerAddress)
501511
}
502512

503-
if err = promptValidatorManagementType(app, &sidecar); err != nil {
504-
return err
505-
}
506-
if err := setSidecarValidatorManageOwner(&sidecar, createFlags); err != nil {
507-
return err
508-
}
509-
sidecar.UpdateValidatorManagerAddress(network.Name(), validatorManagerAddress)
510513
sidecar.Sovereign = true
511514
fee := uint64(0)
512515

@@ -531,63 +534,65 @@ func convertBlockchain(_ *cobra.Command, args []string) error {
531534

532535
deployBalance := uint64(deployBalanceAVAX * float64(units.Avax))
533536

534-
if changeOwnerAddress == "" {
535-
// use provided key as change owner unless already set
536-
if pAddr, err := kc.PChainFormattedStrAddresses(); err == nil && len(pAddr) > 0 {
537-
changeOwnerAddress = pAddr[0]
538-
ux.Logger.PrintToUser("Using [%s] to be set as a change owner for leftover AVAX", changeOwnerAddress)
539-
}
540-
}
541-
if !generateNodeID {
542-
if err = StartLocalMachine(network, sidecar, blockchainName, deployBalance, availableBalance); err != nil {
543-
return err
544-
}
545-
}
546-
switch {
547-
case len(bootstrapEndpoints) > 0:
537+
if len(bootstrapValidators) == 0 {
548538
if changeOwnerAddress == "" {
549-
changeOwnerAddress, err = blockchain.GetKeyForChangeOwner(app, network)
550-
if err != nil {
551-
return err
539+
// use provided key as change owner unless already set
540+
if pAddr, err := kc.PChainFormattedStrAddresses(); err == nil && len(pAddr) > 0 {
541+
changeOwnerAddress = pAddr[0]
542+
ux.Logger.PrintToUser("Using [%s] to be set as a change owner for leftover AVAX", changeOwnerAddress)
552543
}
553544
}
554-
for _, endpoint := range bootstrapEndpoints {
555-
infoClient := info.NewClient(endpoint)
556-
ctx, cancel := utils.GetAPILargeContext()
557-
defer cancel()
558-
nodeID, proofOfPossession, err := infoClient.GetNodeID(ctx)
559-
if err != nil {
545+
if !generateNodeID {
546+
if err = StartLocalMachine(network, sidecar, blockchainName, deployBalance, availableBalance); err != nil {
560547
return err
561548
}
562-
publicKey = "0x" + hex.EncodeToString(proofOfPossession.PublicKey[:])
563-
pop = "0x" + hex.EncodeToString(proofOfPossession.ProofOfPossession[:])
564-
565-
bootstrapValidators = append(bootstrapValidators, models.SubnetValidator{
566-
NodeID: nodeID.String(),
567-
Weight: constants.BootstrapValidatorWeight,
568-
Balance: deployBalance,
569-
BLSPublicKey: publicKey,
570-
BLSProofOfPossession: pop,
571-
ChangeOwnerAddr: changeOwnerAddress,
572-
})
573-
}
574-
case clusterNameFlagValue != "":
575-
// for remote clusters we don't need to ask for bootstrap validators and can read it from filesystem
576-
bootstrapValidators, err = getClusterBootstrapValidators(clusterNameFlagValue, network, deployBalance)
577-
if err != nil {
578-
return fmt.Errorf("error getting bootstrap validators from cluster %s: %w", clusterNameFlagValue, err)
579549
}
550+
switch {
551+
case len(bootstrapEndpoints) > 0:
552+
if changeOwnerAddress == "" {
553+
changeOwnerAddress, err = blockchain.GetKeyForChangeOwner(app, network)
554+
if err != nil {
555+
return err
556+
}
557+
}
558+
for _, endpoint := range bootstrapEndpoints {
559+
infoClient := info.NewClient(endpoint)
560+
ctx, cancel := utils.GetAPILargeContext()
561+
defer cancel()
562+
nodeID, proofOfPossession, err := infoClient.GetNodeID(ctx)
563+
if err != nil {
564+
return err
565+
}
566+
publicKey = "0x" + hex.EncodeToString(proofOfPossession.PublicKey[:])
567+
pop = "0x" + hex.EncodeToString(proofOfPossession.ProofOfPossession[:])
568+
569+
bootstrapValidators = append(bootstrapValidators, models.SubnetValidator{
570+
NodeID: nodeID.String(),
571+
Weight: constants.BootstrapValidatorWeight,
572+
Balance: deployBalance,
573+
BLSPublicKey: publicKey,
574+
BLSProofOfPossession: pop,
575+
ChangeOwnerAddr: changeOwnerAddress,
576+
})
577+
}
578+
case clusterNameFlagValue != "":
579+
// for remote clusters we don't need to ask for bootstrap validators and can read it from filesystem
580+
bootstrapValidators, err = getClusterBootstrapValidators(clusterNameFlagValue, network, deployBalance)
581+
if err != nil {
582+
return fmt.Errorf("error getting bootstrap validators from cluster %s: %w", clusterNameFlagValue, err)
583+
}
580584

581-
default:
582-
bootstrapValidators, err = promptBootstrapValidators(
583-
network,
584-
changeOwnerAddress,
585-
numBootstrapValidators,
586-
deployBalance,
587-
availableBalance,
588-
)
589-
if err != nil {
590-
return err
585+
default:
586+
bootstrapValidators, err = promptBootstrapValidators(
587+
network,
588+
changeOwnerAddress,
589+
numBootstrapValidators,
590+
deployBalance,
591+
availableBalance,
592+
)
593+
if err != nil {
594+
return err
595+
}
591596
}
592597
}
593598

0 commit comments

Comments
 (0)