Skip to content

Commit

Permalink
Merge pull request #6 from HugoByte/DIVE-364-Refactor-Redundant-Code
Browse files Browse the repository at this point in the history
feat: implement chain commands with dive context manager
  • Loading branch information
shreyasbhat0 authored Dec 6, 2023
2 parents 4c15cc9 + 09afc3b commit 2c57d2c
Show file tree
Hide file tree
Showing 38 changed files with 1,344 additions and 571 deletions.
51 changes: 51 additions & 0 deletions cli/cmd/chains/archway/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package archway

import (
"github.com/hugobyte/dive-core/cli/common"
"github.com/spf13/cobra"
)

var (
configFilePath string
)

const (
constructServiceConfigFunctionName = "get_service_config"
runArchwayNodeWithCustomServiceFunctionName = "start_cosmos_node"
runArchwayNodeWithDefaultConfigFunctionName = "start_node_service"
)

var ArchwayCmd = common.NewDiveCommandBuilder().
SetUse("archway").
SetShort("Build, initialize and start a archway node").
SetLong("The command starts the archway network and allows node in executing contracts").
SetRun(archway).
AddStringFlagWithShortHand(&configFilePath, "config", "c", "", "path to custom config json file to start archway node ").
Build()

func archway(cmd *cobra.Command, args []string) {

cliContext := common.GetCliWithKurtosisContext()

err := common.ValidateArgs(args)
if err != nil {
cliContext.Fatalf("Error %s. %s", err, cmd.UsageString())
}

cliContext.Spinner().StartWithMessage("Starting Archway Node", "green")

response, err := RunArchway(cliContext)

if err != nil {
cliContext.Fatal(err)
}

err = common.WriteServiceResponseData(response.ServiceName, *response, cliContext)
if err != nil {
cliContext.Fatal(err)

}

cliContext.Spinner().StopWithMessage("Archway Node Started. Please find service details in current working directory(services.json)")

}
68 changes: 68 additions & 0 deletions cli/cmd/chains/archway/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package archway

import (
"github.com/hugobyte/dive-core/cli/cmd/chains/utils"
"github.com/hugobyte/dive-core/cli/common"
)

func RunArchway(cli *common.Cli) (*common.DiveServiceResponse, error) {

enclaveContext, err := cli.Context().GetEnclaveContext(common.DiveEnclave)

if err != nil {
return nil, common.WrapMessageToError(err, "Archway Run Failed")
}

var serviceConfig = &utils.CosmosServiceConfig{}

err = common.LoadConfig(cli, serviceConfig, configFilePath)
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.DiveArchwayDefaultNodeScript, runArchwayNodeWithDefaultConfigFunctionName)

response, _, err := enclaveContext.RunStarlarkRemotePackage(cli.Context().GetContext(), common.DiveRemotePackagePath, runConfig)

if err != nil {
return nil, common.WrapMessageToError(common.ErrStarlarkRunFailed, err.Error())
}

responseData, services, skippedInstructions, err := common.GetSerializedData(cli, response)

if err != nil {

errRemove := cli.Context().RemoveServicesByServiceNames(services, common.DiveEnclave)
if errRemove != nil {
return nil, common.WrapMessageToError(errRemove, "Archway Run Failed ")
}

return nil, common.WrapMessageToError(err, "Archway Run Failed ")
}

if cli.Context().CheckSkippedInstructions(skippedInstructions) {
return nil, common.WrapMessageToError(common.ErrStarlarkResponse, "Already Running")
}

archwayResponseData := &common.DiveServiceResponse{}
result, err := archwayResponseData.Decode([]byte(responseData))

if err != nil {

errRemove := cli.Context().RemoveServicesByServiceNames(services, common.DiveEnclave)
if errRemove != nil {
return nil, common.WrapMessageToError(errRemove, "Archway Run Failed ")
}

return nil, common.WrapMessageToErrorf(common.ErrDataUnMarshall, "%s.%s", err, "Archway Run Failed ")

}

return result, nil
}
15 changes: 0 additions & 15 deletions cli/cmd/chains/chain/archway.go

This file was deleted.

16 changes: 0 additions & 16 deletions cli/cmd/chains/chain/eth.go

This file was deleted.

16 changes: 0 additions & 16 deletions cli/cmd/chains/chain/hardhat.go

This file was deleted.

103 changes: 0 additions & 103 deletions cli/cmd/chains/chain/icon/run.go

This file was deleted.

52 changes: 0 additions & 52 deletions cli/cmd/chains/chain/icon/types.go

This file was deleted.

54 changes: 0 additions & 54 deletions cli/cmd/chains/chain/icon/utils.go

This file was deleted.

15 changes: 0 additions & 15 deletions cli/cmd/chains/chain/neutron.go

This file was deleted.

Loading

0 comments on commit 2c57d2c

Please sign in to comment.