Skip to content

Commit

Permalink
fix: fix hardhat node and services_enclaveName.json output for all nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
riyasng12 committed Dec 13, 2023
1 parent 1845adf commit 9722947
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 17 deletions.
4 changes: 3 additions & 1 deletion cli/cmd/chains/archway/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}
4 changes: 2 additions & 2 deletions cli/cmd/chains/archway/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
Expand All @@ -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 ")
}
Expand Down
4 changes: 3 additions & 1 deletion cli/cmd/chains/eth/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}
2 changes: 1 addition & 1 deletion cli/cmd/chains/eth/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ")
}
Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/chains/hardhat/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}
23 changes: 19 additions & 4 deletions cli/cmd/chains/hardhat/run.go
Original file line number Diff line number Diff line change
@@ -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) {

Expand All @@ -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)

Expand All @@ -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 ")
Expand All @@ -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 ")
}
Expand Down
4 changes: 3 additions & 1 deletion cli/cmd/chains/icon/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions cli/cmd/chains/icon/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ")
}
Expand All @@ -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 ")
}
Expand Down Expand Up @@ -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 ")
}
Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/chains/neutron/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}
4 changes: 2 additions & 2 deletions cli/cmd/chains/neutron/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ")
}
Expand All @@ -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 ")
}
Expand Down
28 changes: 28 additions & 0 deletions cli/cmd/chains/utils/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 9722947

Please sign in to comment.