From 97229474696eab55e0b3bfa7dcbb07443e3d01a8 Mon Sep 17 00:00:00 2001 From: riyasng12 Date: Wed, 13 Dec 2023 16:57:09 +0530 Subject: [PATCH] fix: fix hardhat node and services_enclaveName.json output for all nodes --- cli/cmd/chains/archway/cmd.go | 4 +++- cli/cmd/chains/archway/run.go | 4 ++-- cli/cmd/chains/eth/cmd.go | 4 +++- cli/cmd/chains/eth/run.go | 2 +- cli/cmd/chains/hardhat/cmd.go | 3 ++- cli/cmd/chains/hardhat/run.go | 23 +++++++++++++++++++---- cli/cmd/chains/icon/cmd.go | 4 +++- cli/cmd/chains/icon/run.go | 6 +++--- cli/cmd/chains/neutron/cmd.go | 3 ++- cli/cmd/chains/neutron/run.go | 4 ++-- cli/cmd/chains/utils/types.go | 28 ++++++++++++++++++++++++++++ 11 files changed, 68 insertions(+), 17 deletions(-) diff --git a/cli/cmd/chains/archway/cmd.go b/cli/cmd/chains/archway/cmd.go index 751d3c1b..b8a4491a 100644 --- a/cli/cmd/chains/archway/cmd.go +++ b/cli/cmd/chains/archway/cmd.go @@ -49,6 +49,8 @@ func archway(cmd *cobra.Command, args []string) { cliContext.Fatal(err) } - cliContext.StopSpinnerIfNotVerbose("Archway Node Started. Please find service details in current working directory(services.json)", common.DiveLogs) + + stopMessage := fmt.Sprintf("Archway Node Started. Please find service details in current working directory(%s)", serviceFileName) + cliContext.StopSpinnerIfNotVerbose(stopMessage, common.DiveLogs) } diff --git a/cli/cmd/chains/archway/run.go b/cli/cmd/chains/archway/run.go index 43e7692e..b5c6e2fd 100644 --- a/cli/cmd/chains/archway/run.go +++ b/cli/cmd/chains/archway/run.go @@ -40,7 +40,7 @@ func RunArchway(cli *common.Cli) (*common.DiveServiceResponse, error) { if err != nil { - errRemove := cli.Context().RemoveServicesByServiceNames(services, common.DiveEnclave) + errRemove := cli.Context().RemoveServicesByServiceNames(services, common.EnclaveName) if errRemove != nil { return nil, common.WrapMessageToError(errRemove, "Archway Run Failed.") } @@ -57,7 +57,7 @@ func RunArchway(cli *common.Cli) (*common.DiveServiceResponse, error) { if err != nil { - errRemove := cli.Context().RemoveServicesByServiceNames(services, common.DiveEnclave) + errRemove := cli.Context().RemoveServicesByServiceNames(services, common.EnclaveName) if errRemove != nil { return nil, common.WrapMessageToError(errRemove, "Archway Run Failed ") } diff --git a/cli/cmd/chains/eth/cmd.go b/cli/cmd/chains/eth/cmd.go index 743068ab..a5e65d93 100644 --- a/cli/cmd/chains/eth/cmd.go +++ b/cli/cmd/chains/eth/cmd.go @@ -44,5 +44,7 @@ func eth(cmd *cobra.Command, args []string) { cliContext.Fatal(err) } - cliContext.Spinner().StopWithMessage("ETH Node Started. Please find service details in current working directory(services.json)") + stopMessage := fmt.Sprintf("ETH Node Started. Please find service details in current working directory(%s)", serviceFileName) + cliContext.Spinner().StopWithMessage(stopMessage) + } diff --git a/cli/cmd/chains/eth/run.go b/cli/cmd/chains/eth/run.go index 57a1d3f4..066d80f8 100644 --- a/cli/cmd/chains/eth/run.go +++ b/cli/cmd/chains/eth/run.go @@ -39,7 +39,7 @@ func RunEth(cli *common.Cli) (*common.DiveServiceResponse, error) { result, err := ethResponseData.Decode([]byte(responseData)) if err != nil { - errRemove := cli.Context().RemoveServicesByServiceNames(services, common.DiveEnclave) + errRemove := cli.Context().RemoveServicesByServiceNames(services, common.EnclaveName) if err != nil { return nil, common.WrapMessageToError(errRemove, "Eth Run Failed ") } diff --git a/cli/cmd/chains/hardhat/cmd.go b/cli/cmd/chains/hardhat/cmd.go index bf707301..36b8d4c1 100644 --- a/cli/cmd/chains/hardhat/cmd.go +++ b/cli/cmd/chains/hardhat/cmd.go @@ -43,6 +43,7 @@ func hardhat(cmd *cobra.Command, args []string) { cliContext.Fatal(err) } - cliContext.Spinner().StopWithMessage("Hardhat Node Started. Please find service details in current working directory(services.json)") + stopMessage := fmt.Sprintf("Hardhat Node Started. Please find service details in current working directory(%s)", serviceFileName) + cliContext.Spinner().StopWithMessage(stopMessage) } diff --git a/cli/cmd/chains/hardhat/run.go b/cli/cmd/chains/hardhat/run.go index 7fa65f84..ee1da56f 100644 --- a/cli/cmd/chains/hardhat/run.go +++ b/cli/cmd/chains/hardhat/run.go @@ -1,6 +1,9 @@ package hardhat -import "github.com/hugobyte/dive-core/cli/common" +import ( + "github.com/hugobyte/dive-core/cli/cmd/chains/utils" + "github.com/hugobyte/dive-core/cli/common" +) func RunHardhat(cli *common.Cli) (*common.DiveServiceResponse, error) { @@ -10,7 +13,19 @@ func RunHardhat(cli *common.Cli) (*common.DiveServiceResponse, error) { return nil, common.WrapMessageToError(err, "Hardhat Run Failed While Getting Enclave Context") } - runConfig := common.GetStarlarkRunConfig(`{}`, common.DiveEthHardhatNodeScript, "start_hardhat_node") + var serviceConfig = &utils.HardhatServiceConfig{} + err = serviceConfig.LoadDefaultConfig() + if err != nil { + return nil, err + } + + encodedServiceConfigDataString, err := serviceConfig.EncodeToString() + + if err != nil { + return nil, common.WrapMessageToError(common.ErrDataMarshall, err.Error()) + } + + runConfig := common.GetStarlarkRunConfig(encodedServiceConfigDataString, common.DiveEthHardhatNodeScript, "start_hardhat_node") response, _, err := enclaveContext.RunStarlarkRemotePackage(cli.Context().GetContext(), common.DiveRemotePackagePath, runConfig) @@ -22,7 +37,7 @@ func RunHardhat(cli *common.Cli) (*common.DiveServiceResponse, error) { if err != nil { errRemove := cli.Context().RemoveServicesByServiceNames(services, common.EnclaveName) if errRemove != nil { - return nil, common.WrapMessageToError(errRemove, "Hardhat Run Failed .Services Removed") + return nil, common.WrapMessageToError(errRemove, "Hardhat Run Failed. Services Removed") } return nil, common.WrapMessageToError(err, "Hardhat Run Failed ") @@ -37,7 +52,7 @@ func RunHardhat(cli *common.Cli) (*common.DiveServiceResponse, error) { result, err := hardhatResponseData.Decode([]byte(responseData)) if err != nil { - errRemove := cli.Context().RemoveServicesByServiceNames(services, common.DiveEnclave) + errRemove := cli.Context().RemoveServicesByServiceNames(services, common.EnclaveName) if err != nil { return nil, common.WrapMessageToError(errRemove, "Hardhat Run Failed ") } diff --git a/cli/cmd/chains/icon/cmd.go b/cli/cmd/chains/icon/cmd.go index b3f95537..7186fe58 100644 --- a/cli/cmd/chains/icon/cmd.go +++ b/cli/cmd/chains/icon/cmd.go @@ -92,7 +92,9 @@ func icon(cmd *cobra.Command, args []string) { } - cliContext.Spinner().StopWithMessage("Icon Node Started. Please find service details in current working directory(services.json)") + stopMessage := fmt.Sprintf("Icon Node Started. Please find service details in current working directory(%s)", serviceFileName) + cliContext.Spinner().StopWithMessage(stopMessage) + } func iconDecentralization(cmd *cobra.Command, args []string) { diff --git a/cli/cmd/chains/icon/run.go b/cli/cmd/chains/icon/run.go index ffe6f166..54d45020 100644 --- a/cli/cmd/chains/icon/run.go +++ b/cli/cmd/chains/icon/run.go @@ -40,7 +40,7 @@ func RunIconNode(cli *common.Cli) (*common.DiveServiceResponse, error) { if err != nil { - errRemove := cli.Context().RemoveServicesByServiceNames(services, common.DiveEnclave) + errRemove := cli.Context().RemoveServicesByServiceNames(services, common.EnclaveName) if errRemove != nil { return nil, common.WrapMessageToError(errRemove, "Icon Run Failed ") } @@ -58,7 +58,7 @@ func RunIconNode(cli *common.Cli) (*common.DiveServiceResponse, error) { if err != nil { - errRemove := cli.Context().RemoveServicesByServiceNames(services, common.DiveEnclave) + errRemove := cli.Context().RemoveServicesByServiceNames(services, common.EnclaveName) if errRemove != nil { return nil, common.WrapMessageToError(errRemove, "Icon Run Failed ") } @@ -87,7 +87,7 @@ func RunDecentralization(cli *common.Cli, params string) error { _, services, skippedInstructions, err := common.GetSerializedData(cli, data) if err != nil { - errRemove := cli.Context().RemoveServicesByServiceNames(services, common.DiveEnclave) + errRemove := cli.Context().RemoveServicesByServiceNames(services, common.EnclaveName) if errRemove != nil { return common.WrapMessageToError(errRemove, "Icon Decentralization Failed ") } diff --git a/cli/cmd/chains/neutron/cmd.go b/cli/cmd/chains/neutron/cmd.go index 993d457d..cf0bc34c 100644 --- a/cli/cmd/chains/neutron/cmd.go +++ b/cli/cmd/chains/neutron/cmd.go @@ -45,6 +45,7 @@ func neutron(cmd *cobra.Command, args []string) { if err != nil { cliContext.Fatal(err) } + stopMessage := fmt.Sprintf("Neutron Node Started. Please find service details in current working directory(%s)", serviceFileName) + cliContext.Spinner().StopWithMessage(stopMessage) - cliContext.Spinner().StopWithMessage("Neutron Node Started. Please find service details in current working directory(services.json)") } diff --git a/cli/cmd/chains/neutron/run.go b/cli/cmd/chains/neutron/run.go index 9851e7da..e45f33b9 100644 --- a/cli/cmd/chains/neutron/run.go +++ b/cli/cmd/chains/neutron/run.go @@ -41,7 +41,7 @@ func RunNeutron(cli *common.Cli) (*common.DiveServiceResponse, error) { if err != nil { - errRemove := cli.Context().RemoveServicesByServiceNames(services, common.DiveEnclave) + errRemove := cli.Context().RemoveServicesByServiceNames(services, common.EnclaveName) if errRemove != nil { return nil, common.WrapMessageToError(errRemove, "Neutron Run Failed ") } @@ -58,7 +58,7 @@ func RunNeutron(cli *common.Cli) (*common.DiveServiceResponse, error) { if err != nil { - errRemove := cli.Context().RemoveServicesByServiceNames(services, common.DiveEnclave) + errRemove := cli.Context().RemoveServicesByServiceNames(services, common.EnclaveName) if errRemove != nil { return nil, common.WrapMessageToErrorf(errRemove, "%s.%s", errRemove, "Neutron Run Failed ") } diff --git a/cli/cmd/chains/utils/types.go b/cli/cmd/chains/utils/types.go index 64059ffe..b36dfc4f 100644 --- a/cli/cmd/chains/utils/types.go +++ b/cli/cmd/chains/utils/types.go @@ -111,3 +111,31 @@ func (sc *IconServiceConfig) LoadConfigFromFile(cliContext *common.Cli, filePath } return nil } + +type HardhatServiceConfig struct { + PublicPort int `json:"public_port"` +} + +func (sc *HardhatServiceConfig) LoadDefaultConfig() error { + sc.PublicPort = 8545 + if common.CheckPort(8545) { + sc.PublicPort = 8545 + } else { + availablePort, err := common.GetAvailablePort() + if err != nil { + return err + } + sc.PublicPort = availablePort + } + + return nil +} + +func (sc *HardhatServiceConfig) EncodeToString() (string, error) { + encodedBytes, err := json.Marshal(sc) + if err != nil { + return "", common.WrapMessageToError(common.ErrDataMarshall, err.Error()) + } + + return string(encodedBytes), nil +}