Skip to content

Commit

Permalink
feat: update neutron command
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyasbhat0 committed Dec 6, 2023
1 parent 17f7730 commit db1b570
Show file tree
Hide file tree
Showing 24 changed files with 247 additions and 166 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package archway

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 RunArchway(cli *common.Cli) (*common.DiveServiceResponse, error) {

Expand All @@ -10,7 +13,7 @@ func RunArchway(cli *common.Cli) (*common.DiveServiceResponse, error) {
return nil, err
}

var serviceConfig = &ArchwayServiceConfig{}
var serviceConfig = &utils.CosmosServiceConfig{}

err = common.LoadConfig(cli, serviceConfig, configFilePath)
if err != nil {
Expand Down
47 changes: 0 additions & 47 deletions cli/cmd/chains/chain/archway/types.go

This file was deleted.

1 change: 0 additions & 1 deletion cli/cmd/chains/chain/archway/utils.go

This file was deleted.

1 change: 0 additions & 1 deletion cli/cmd/chains/chain/eth/types.go

This file was deleted.

1 change: 0 additions & 1 deletion cli/cmd/chains/chain/eth/utils.go

This file was deleted.

1 change: 0 additions & 1 deletion cli/cmd/chains/chain/hardhat/types.go

This file was deleted.

1 change: 0 additions & 1 deletion cli/cmd/chains/chain/hardhat/utils.go

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

1 change: 0 additions & 1 deletion cli/cmd/chains/chain/neutron/run.go

This file was deleted.

1 change: 0 additions & 1 deletion cli/cmd/chains/chain/neutron/types.go

This file was deleted.

1 change: 0 additions & 1 deletion cli/cmd/chains/chain/neutron/utils.go

This file was deleted.

10 changes: 5 additions & 5 deletions cli/cmd/chains/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"os"
"slices"

"github.com/hugobyte/dive-core/cli/cmd/chains/chain/archway"
"github.com/hugobyte/dive-core/cli/cmd/chains/chain/eth"
"github.com/hugobyte/dive-core/cli/cmd/chains/chain/hardhat"
"github.com/hugobyte/dive-core/cli/cmd/chains/chain/icon"
"github.com/hugobyte/dive-core/cli/cmd/chains/chain/neutron"
"github.com/hugobyte/dive-core/cli/cmd/chains/archway"
"github.com/hugobyte/dive-core/cli/cmd/chains/eth"
"github.com/hugobyte/dive-core/cli/cmd/chains/hardhat"
"github.com/hugobyte/dive-core/cli/cmd/chains/icon"
"github.com/hugobyte/dive-core/cli/cmd/chains/neutron"
"github.com/hugobyte/dive-core/cli/common"
"github.com/spf13/cobra"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
44 changes: 43 additions & 1 deletion cli/cmd/chains/chain/icon/run.go → cli/cmd/chains/icon/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package icon

import (
"fmt"
"os"
"path/filepath"

"github.com/hugobyte/dive-core/cli/cmd/chains/utils"
"github.com/hugobyte/dive-core/cli/common"
"github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves"
)

func RunIconNode(cli *common.Cli) (*common.DiveServiceResponse, error) {
Expand All @@ -13,7 +17,7 @@ func RunIconNode(cli *common.Cli) (*common.DiveServiceResponse, error) {
if err != nil {
return nil, err
}
var serviceConfig = &IconServiceConfig{}
var serviceConfig = &utils.IconServiceConfig{}
err = common.LoadConfig(cli, serviceConfig, configFilePath)
if err != nil {
return nil, err
Expand Down Expand Up @@ -91,3 +95,41 @@ func RunDecentralization(cli *common.Cli, params string) error {
return nil

}

type genesisHandler struct {
genesisFile string
uploadedFiles string
genesisPath string
}

func genesismanager(enclaveContext *enclaves.EnclaveContext) (*genesisHandler, error) {

gm := genesisHandler{}

var genesisFilePath = genesis

if genesisFilePath != "" {
genesisFileName := filepath.Base(genesisFilePath)
if _, err := os.Stat(genesisFilePath); err != nil {
return nil, err
}

_, d, err := enclaveContext.UploadFiles(genesisFilePath, genesisFileName)
if err != nil {
return nil, err
}

gm.uploadedFiles = fmt.Sprintf(`{"file_path":"%s","file_name":"%s"}`, d, genesisFileName)
} else {
gm.genesisFile = filepath.Base(DefaultIconGenesisFile)
gm.genesisPath = DefaultIconGenesisFile
gm.uploadedFiles = `{}`

}

return &gm, nil
}

func GetDecentralizeParams(serviceName, nodeEndpoint, keystorePath, keystorepassword, networkID string) string {
return fmt.Sprintf(`{"service_name":"%s","uri":"%s","keystorepath":"%s","keypassword":"%s","nid":"%s"}`, serviceName, nodeEndpoint, keystorePath, keystorepassword, networkID)
}
50 changes: 50 additions & 0 deletions cli/cmd/chains/neutron/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package neutron

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

var (
configFilePath string
)

const (
runNeutronNodeWithDefaultConfigFunctionName = "start_node_service"
)

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

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

cliContext := common.GetCliWithKurtosisContext()

err := common.ValidateArgs(args)
if err != nil {
cliContext.Logger().Fatal(common.CodeOf(err), err.Error())
}

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

response, err := RunNeutron(cliContext)

if err != nil {
cliContext.Logger().Fatal(common.CodeOf(err), err.Error())
}

err = common.WriteServiceResponseData(response.ServiceName, *response, cliContext)
if err != nil {
cliContext.Spinner().Stop()
cliContext.Logger().SetErrorToStderr()
cliContext.Logger().Error(common.CodeOf(err), err.Error())

}

cliContext.Spinner().StopWithMessage("Neutron Node Started. Please find service details in current working directory(services.json)")
}
63 changes: 63 additions & 0 deletions cli/cmd/chains/neutron/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package neutron

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

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

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

if err != nil {
return nil, err
}

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.Errorc(common.InvalidEnclaveConfigError, err.Error())
}

runConfig := common.GetStarlarkRunConfig(encodedServiceConfigDataString, common.DiveNeutronDefaultNodeScript, runNeutronNodeWithDefaultConfigFunctionName)

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

if err != nil {
return nil, common.Errorc(common.FileError, err.Error())
}

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

if err != nil {

err = cli.Context().RemoveServicesByServiceNames(services, common.DiveEnclave)
if err != nil {
return nil, common.Errorc(common.InvalidEnclaveContextError, err.Error())
}

return nil, common.Errorc(common.KurtosisContextError, err.Error())
}

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

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

if err != nil {

return nil, common.Errorc(common.KurtosisContextError, err.Error())
}

return result, nil
}
Loading

0 comments on commit db1b570

Please sign in to comment.