diff --git a/cli/commands/chain/chain.go b/cli/commands/chain/chain.go deleted file mode 100644 index caf2a302..00000000 --- a/cli/commands/chain/chain.go +++ /dev/null @@ -1,55 +0,0 @@ -/* -Copyright © 2023 Hugobyte AI Labs -*/ -package chain - -import ( - "fmt" - - "github.com/spf13/cobra" -) - -// chainCmd represents the chain command -var ChainCmd = &cobra.Command{ - Use: "chain", - Short: "A brief description of your command", - Long: `A longer description that spans multiple lines and likely contains examples -and usage of using your command. For example: - -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, - Run: func(cmd *cobra.Command, args []string) { - - }, -} - -// chainCmd represents the chain command -var iconCmd = &cobra.Command{ - Use: "icon", - Short: "A brief description of your command", - Long: `A longer description that spans multiple lines and likely contains examples -and usage of using your command. For example: - -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, - Run: func(cmd *cobra.Command, args []string) { - fmt.Println("hello") - }, -} - -func init() { - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // chainCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // chainCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") - - ChainCmd.AddCommand(iconCmd) -} diff --git a/cli/commands/chain/chains.go b/cli/commands/chain/chains.go new file mode 100644 index 00000000..a48ecc1e --- /dev/null +++ b/cli/commands/chain/chains.go @@ -0,0 +1,68 @@ +/* +Copyright © 2023 Hugobyte AI Labs +*/ +package chain + +import ( + "context" + + "github.com/hugobyte/dive/commands/chain/types" + "github.com/hugobyte/dive/common" + "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" + "github.com/kurtosis-tech/kurtosis/api/golang/engine/lib/kurtosis_context" + "github.com/spf13/cobra" +) + +// chainCmd represents the chain command + +var ChainCmd = &cobra.Command{ + Use: "chain", + Short: "runs specfied chain", + Long: ``, + + Run: func(cmd *cobra.Command, args []string) { + cmd.Help() + + }, +} + +func init() { + + ctx := context.Background() + + kurtosisContext, err := kurtosis_context.NewKurtosisContextFromLocalEngine() + if err != nil { + panic(err) + + } + + enclaveCtx, err := getEnclaveContext(ctx, common.DiveEnclave, kurtosisContext) + if err != nil { + panic(err) + + } + + ChainCmd.AddCommand(types.NewIconCmd(ctx, enclaveCtx)) + ChainCmd.AddCommand(types.NewEthCmd(ctx, enclaveCtx)) + ChainCmd.AddCommand(types.NewHardhatCmd(ctx, enclaveCtx)) + +} + +func getEnclaveContext(ctx context.Context, identifier string, kurtosisContext *kurtosis_context.KurtosisContext) (*enclaves.EnclaveContext, error) { + + _, err := kurtosisContext.GetEnclave(ctx, common.DiveEnclave) + if err != nil { + enclaveCtx, err := kurtosisContext.CreateEnclave(ctx, identifier, false) + if err != nil { + return nil, err + + } + return enclaveCtx, nil + } + enclaveCtx, err := kurtosisContext.GetEnclaveContext(ctx, identifier) + + if err != nil { + return nil, err + } + return enclaveCtx, nil +} diff --git a/cli/commands/chain/types/eth.go b/cli/commands/chain/types/eth.go new file mode 100644 index 00000000..cc3425f7 --- /dev/null +++ b/cli/commands/chain/types/eth.go @@ -0,0 +1,49 @@ +package types + +import ( + "context" + "fmt" + + "github.com/hugobyte/dive/common" + "github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings" + "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" + "github.com/spf13/cobra" +) + +func NewEthCmd(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *cobra.Command { + + var ethCmd = &cobra.Command{ + Use: "eth", + Short: "Runs Eth Node", + Long: ``, + Run: func(cmd *cobra.Command, args []string) { + + fmt.Println(runEthNode(ctx, kurtosisEnclaveContext).EncodeToString()) + }, + } + + return ethCmd + +} + +func runEthNode(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *common.DiveserviceResponse { + + data, _, err := kurtosisEnclaveContext.RunStarlarkPackage(ctx, "../", "services/evm/eth/eth.star", "start_eth_node_serivce", `{"args":{},"node_type":"eth"}`, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) + + if err != nil { + fmt.Println(err) + } + + responseData := common.GetSerializedData(data) + + ethResponseData := &common.DiveserviceResponse{} + + result, err := ethResponseData.Decode([]byte(responseData)) + + if err != nil { + fmt.Println(err) + } + + return result + +} diff --git a/cli/commands/chain/types/hardhat.go b/cli/commands/chain/types/hardhat.go new file mode 100644 index 00000000..41c5cb49 --- /dev/null +++ b/cli/commands/chain/types/hardhat.go @@ -0,0 +1,49 @@ +package types + +import ( + "context" + "fmt" + + "github.com/hugobyte/dive/common" + "github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings" + "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" + "github.com/spf13/cobra" +) + +func NewHardhatCmd(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *cobra.Command { + + var ethCmd = &cobra.Command{ + Use: "hardhat", + Short: "Runs Hardhat Node", + Long: ``, + Run: func(cmd *cobra.Command, args []string) { + + fmt.Println(runHardhatNode(ctx, kurtosisEnclaveContext).EncodeToString()) + }, + } + + return ethCmd + +} + +func runHardhatNode(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *common.DiveserviceResponse { + + data, _, err := kurtosisEnclaveContext.RunStarlarkPackage(ctx, "../", "services/evm/eth/eth.star", "start_eth_node_serivce", `{"args":{},"node_type":"hardhat"}`, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) + + if err != nil { + fmt.Println(err) + } + + responseData := common.GetSerializedData(data) + + ethResponseData := &common.DiveserviceResponse{} + + result, err := ethResponseData.Decode([]byte(responseData)) + + if err != nil { + fmt.Println(err) + } + + return result + +} diff --git a/cli/commands/chain/types/icon.go b/cli/commands/chain/types/icon.go new file mode 100644 index 00000000..cb3ee25d --- /dev/null +++ b/cli/commands/chain/types/icon.go @@ -0,0 +1,218 @@ +package types + +import ( + "context" + "encoding/json" + "fmt" + "path/filepath" + + "os" + + "github.com/hugobyte/dive/common" + "github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings" + "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" + "github.com/sirupsen/logrus" + "github.com/spf13/cobra" +) + +var ( + id = "" + genesis = "" + serviceName = "" + keystorePath = "" + keystorepassword = "" + networkID = "" + nodeEndpoint = "" + configFilePath = "" +) + +type IconServiceConfig struct { + Id string `json:"id" default:"0"` + Port int `json:"private_port"` + PublicPort int `json:"public_port"` + P2PListenAddress string `json:"p2p_listen_address"` + P2PAddress string `json:"p2p_address"` + Cid string `json:"cid"` +} + +func (sc *IconServiceConfig) defaultServiceConfig() { + + sc.Id = "0" + sc.Port = 9080 + sc.PublicPort = 8090 + sc.P2PListenAddress = "7080" + sc.P2PAddress = "8080" + sc.Cid = "0xacbc4e" +} + +func (sc *IconServiceConfig) EncodeToString() (string, error) { + encodedBytes, err := json.Marshal(sc) + if err != nil { + return "", nil + } + + return string(encodedBytes), nil +} + +func NewIconCmd(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *cobra.Command { + var iconCmd = &cobra.Command{ + Use: "icon", + Short: "Runs Icon Node", + Long: ``, + Run: func(cmd *cobra.Command, args []string) { + + decentralisation, _ := cmd.Flags().GetBool("decentralisation") + + serviceConfig := &IconServiceConfig{} + + if configFilePath == "" { + serviceConfig.defaultServiceConfig() + } else { + data, err := readConfigFile(configFilePath) + if err != nil { + serviceConfig.defaultServiceConfig() + } + + err = json.Unmarshal(data, serviceConfig) + + if err != nil { + logrus.Fatalln(err) + } + + } + + if decentralisation { + + data := runIconNode(ctx, kurtosisEnclaveContext, serviceConfig) + + params := getDecentralizeParms(data.ServiceName, data.PrivateEndpoint, data.KeystorePath, data.KeyPassword, data.NetworkId) + + Decentralisation(ctx, kurtosisEnclaveContext, params) + + } else { + + data := runIconNode(ctx, kurtosisEnclaveContext, serviceConfig) + + fmt.Println(data.EncodeToString()) + + } + + }, + } + + iconCmd.Flags().StringVarP(&id, "id", "i", "", "chain id") + iconCmd.Flags().StringVarP(&genesis, "genesis", "g", "", "gen file") + iconCmd.Flags().StringVarP(&configFilePath, "config", "c", "", "gen file") + iconCmd.Flags().BoolP("decentralisation", "d", false, "Decentralise Icon Node") + + decentralisationCmd := IconDecentralisationCmd(ctx, kurtosisEnclaveContext) + + iconCmd.AddCommand(decentralisationCmd) + + return iconCmd +} + +func IconDecentralisationCmd(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *cobra.Command { + + var decentralisationCmd = &cobra.Command{ + Use: "decentralize", + Short: "Decentralise Icon Node", + Long: ``, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("Decentralisation") + + params := getDecentralizeParms(serviceName, nodeEndpoint, keystorePath, keystorepassword, networkID) + + Decentralisation(ctx, kurtosisEnclaveContext, params) + + }, + } + decentralisationCmd.Flags().StringVarP(&serviceName, "serviceName", "s", "", "service name") + decentralisationCmd.Flags().StringVarP(&nodeEndpoint, "nodeEndpoint", "e", "", "endpoint address") + decentralisationCmd.Flags().StringVarP(&keystorePath, "keystorePath", "k", "", "keystore path") + decentralisationCmd.Flags().StringVarP(&keystorepassword, "keyPassword", "p", "", "keypassword") + decentralisationCmd.Flags().StringVarP(&networkID, "nid", "n", "", "NetworkId of Icon Node") + + decentralisationCmd.MarkFlagRequired("serviceName") + decentralisationCmd.MarkFlagRequired("nodeEndpoint") + decentralisationCmd.MarkFlagRequired("keystorePath") + decentralisationCmd.MarkFlagRequired("keyPassword") + decentralisationCmd.MarkFlagRequired("nid") + + return decentralisationCmd + +} + +func runIconNode(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext, serviceConfig *IconServiceConfig) *common.DiveserviceResponse { + + paramData, err := serviceConfig.EncodeToString() + if err != nil { + logrus.Fatalln(err) + } + + data, _, err := kurtosisEnclaveContext.RunStarlarkPackage(ctx, "../", "services/jvm/icon/src/node-setup/start_icon_node.star", "get_service_config", paramData, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) + + if err != nil { + fmt.Println(err) + } + + responseData := common.GetSerializedData(data) + + genesis_file_name := filepath.Base(genesis) + r, d, err := kurtosisEnclaveContext.UploadFiles(genesis, genesis_file_name) + + if err != nil { + panic(err) + } + + logrus.Infof("File Uploaded sucessfully : UUID %s", r) + + params := fmt.Sprintf(`{"service_config":%s,"id":"%s","start_file_name":"start-icon.sh","genesis_file_path":"%s","genesis_file_name":"%s"}`, responseData, serviceConfig.Id, d, genesis_file_name) + icon_data, _, err := kurtosisEnclaveContext.RunStarlarkPackage(ctx, "../", "services/jvm/icon/src/node-setup/start_icon_node.star", "start_icon_node", params, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) + + if err != nil { + fmt.Println(err) + } + + response := common.GetSerializedData(icon_data) + + iconResponseData := &common.DiveserviceResponse{} + + result, err := iconResponseData.Decode([]byte(response)) + + if err != nil { + fmt.Println(err) + } + + return result +} + +func Decentralisation(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext, params string) { + data, _, err := kurtosisEnclaveContext.RunStarlarkPackage(ctx, "../", "services/jvm/icon/src/node-setup/setup_icon_node.star", "configure_node", params, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) + + if err != nil { + fmt.Println(err) + } + + response := common.GetSerializedData(data) + + fmt.Println(response) + +} + +func getDecentralizeParms(serviceName, nodeEndpoint, keystorePath, keystorepassword, networkID string) string { + + return fmt.Sprintf(`{"args":{"service_name":"%s","endpoint":"%s","keystore_path":"%s","keypassword":"%s","nid":"%s"}}`, serviceName, nodeEndpoint, keystorePath, keystorepassword, networkID) + +} + +func readConfigFile(filePath string) ([]byte, error) { + + file, err := os.ReadFile(filePath) + + if err != nil { + return nil, err + } + + return file, nil +} diff --git a/cli/commands/root.go b/cli/commands/root.go index 8b82a7a4..5b13caf1 100644 --- a/cli/commands/root.go +++ b/cli/commands/root.go @@ -8,6 +8,7 @@ import ( "github.com/hugobyte/dive/commands/bridge" "github.com/hugobyte/dive/commands/chain" + "github.com/hugobyte/dive/commands/clean" "github.com/hugobyte/dive/commands/version" "github.com/spf13/cobra" @@ -32,13 +33,27 @@ func Execute() { } } +// type DiveContext struct { +// Ctx context.Context +// KurtosisContext *kurtosis_context.KurtosisContext +// Log *logrus.Logger +// } + func init() { + // kurtosisContext, err := kurtosis_context.NewKurtosisContextFromLocalEngine() + // if err != nil { + // panic(err) + // } + // diveContext := DiveContext{ + // Ctx: context.Background(), + // KurtosisContext: kurtosisContext, + // Log: logrus.New(), + // } + rootCmd.CompletionOptions.DisableDefaultCmd = true rootCmd.CompletionOptions.DisableNoDescFlag = true - rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") - rootCmd.AddCommand(version.VersionCmd) rootCmd.AddCommand(chain.ChainCmd) rootCmd.AddCommand(bridge.BridgeCmd) diff --git a/cli/commands/version/version.go b/cli/commands/version/version.go index 562d2838..6bc2135e 100644 --- a/cli/commands/version/version.go +++ b/cli/commands/version/version.go @@ -19,7 +19,7 @@ var VersionCmd = &cobra.Command{ Short: "Prints the CLI version", Long: `Prints the current DIVE CLI version and warns if you are using an old version.`, Run: func(cmd *cobra.Command, args []string) { - version := color.New(color.Bold).Sprint("CLI version -") + DiveVersion + version := color.New(color.Bold).Sprint("CLI version - ") + DiveVersion latestVersion := getLatestVersion() if DiveVersion != latestVersion { logrus.Warnf("Update available '%s'. Get the latest version of our DIVE CLI for bug fixes, performance improvements, and new features.", latestVersion) diff --git a/cli/common/constants.go b/cli/common/constants.go new file mode 100644 index 00000000..9ffe994b --- /dev/null +++ b/cli/common/constants.go @@ -0,0 +1,7 @@ +package common + +const ( + DiveEnclave = "dive" + DiveRemotePackagePath = "github.com/hugobyte/dive" + DiveLocalPackagePath = "../" +) diff --git a/cli/common/types.go b/cli/common/types.go new file mode 100644 index 00000000..4e8c81ad --- /dev/null +++ b/cli/common/types.go @@ -0,0 +1,59 @@ +package common + +import ( + "encoding/json" + "fmt" + + "github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings" + "github.com/sirupsen/logrus" +) + +type DiveserviceResponse struct { + ServiceName string `json:"service_name"` + PublicEndpoint string `json:"endpoint_public"` + PrivateEndpoint string `json:"endpoint"` + KeyPassword string `json:"keypassword"` + KeystorePath string `json:"keystore_path"` + Network string `json:"network"` + NetworkName string `json:"network_name"` + NetworkId string `json:"nid"` +} + +func (dive *DiveserviceResponse) Decode(responseData []byte) (*DiveserviceResponse, error) { + + err := json.Unmarshal(responseData, &dive) + if err != nil { + return nil, err + } + return dive, nil +} +func (dive *DiveserviceResponse) EncodeToString() (string, error) { + encodedBytes, err := json.Marshal(dive) + if err != nil { + return "", nil + } + + return string(encodedBytes), nil +} + +func GetSerializedData(response chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine) string { + + var serializedOutputObj string + for executionResponseLine := range response { + fmt.Println(executionResponseLine) + runFinishedEvent := executionResponseLine.GetRunFinishedEvent() + if runFinishedEvent == nil { + logrus.Info("Execution in progress...") + } else { + logrus.Info("Execution finished successfully") + if runFinishedEvent.GetIsRunSuccessful() { + serializedOutputObj = runFinishedEvent.GetSerializedOutput() + } else { + panic("Starlark run failed") + } + } + } + + return serializedOutputObj + +} diff --git a/cli/config.json b/cli/config.json new file mode 100644 index 00000000..2dafeae7 --- /dev/null +++ b/cli/config.json @@ -0,0 +1,8 @@ +{ + "id": "0", + "private_port": 9080, + "public_port": 8090, + "p2p_listen_address": "7080", + "p2p_address": "8080", + "cid": "0xacbc4e" +} \ No newline at end of file diff --git a/cli/dive b/cli/dive new file mode 100755 index 00000000..7237617d Binary files /dev/null and b/cli/dive differ diff --git a/cli/go.mod b/cli/go.mod index 9e52db16..bdad2c1c 100644 --- a/cli/go.mod +++ b/cli/go.mod @@ -12,6 +12,7 @@ require ( require ( github.com/Masterminds/semver/v3 v3.1.1 // indirect + github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect github.com/dsnet/compress v0.0.1 // indirect github.com/go-yaml/yaml v2.1.0+incompatible // indirect github.com/golang/protobuf v1.5.3 // indirect diff --git a/cli/go.sum b/cli/go.sum index c64a09c2..ce33349d 100644 --- a/cli/go.sum +++ b/cli/go.sum @@ -6,6 +6,10 @@ github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0 github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= @@ -142,6 +146,7 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/cli/main.go b/cli/main.go index e7a4f1a5..d7f67942 100644 --- a/cli/main.go +++ b/cli/main.go @@ -11,76 +11,10 @@ import ( func main() { logrus.SetFormatter(&logrus.TextFormatter{ - FullTimestamp: true, + FullTimestamp: true, TimestampFormat: "2006-01-02 15:04:05", }) styles.RenderBanner() commands.Execute() } - -// ctx, cancelCtxFunc := context.WithCancel(context.Background()) -// defer cancelCtxFunc() - -// kurtosisCtx, err := kurtosis_context.NewKurtosisContextFromLocalEngine() - -// if err != nil { -// fmt.Println(err.Error()) -// } - -// fmt.Println(kurtosisCtx) - -// enclaveId := fmt.Sprintf("%s-%d", enclaveIdPrefix, time.Now().Unix()) - -// enclaveCtx, err := kurtosisCtx.CreateEnclave(ctx, enclaveId, isPartitioningEnabled) -// if err != nil { -// fmt.Println(err.Error()) -// } - -// data, _, err := enclaveCtx.RunStarlarkRemotePackage(ctx, divePackage, pathToMainFile, mainFunctionName, emptyPackageParams, noDryRun, defaultParallelism) -// if err != nil { -// fmt.Println(err.Error()) -// } - -// var serializedOutputObj string -// for executionResponseLine := range data { -// runFinishedEvent := executionResponseLine.GetRunFinishedEvent() -// if runFinishedEvent == nil { -// logrus.Info("Execution in progress...") -// } else { -// logrus.Info("Execution finished successfully") -// if runFinishedEvent.GetIsRunSuccessful() { -// serializedOutputObj = runFinishedEvent.GetSerializedOutput() -// } else { -// panic("Starlark run failed") -// } -// } -// } - -// fmt.Println(serializedOutputObj) - -// "github.com/sirupsen/logrus" - -// const ( -// solidityContractsGitPath = "" -// javaContractGitPath = "" -// ) - -// const ( -// enclaveIdPrefix = "quick-start-go-example" -// isPartitioningEnabled = false - -// divePackage = "github.com/hugobyte/dive" - -// defaultParallelism = 4 -// noDryRun = false - -// emptyPackageParams = `{"args":{},"node_name":"icon"}` - -// apiServiceName = "api" - -// contentType = "application/json" - -// pathToMainFile = "main.star" -// mainFunctionName = "run_node" -// ) diff --git a/package_io/constants.star b/package_io/constants.star index 3adb519a..60155350 100644 --- a/package_io/constants.star +++ b/package_io/constants.star @@ -9,7 +9,8 @@ ICON_NODE_CLIENT = struct( port_key = "rpc", public_ip_address = "127.0.0.1", rpc_endpoint_path = "api/v3/icon_dex", - service_name = "icon-node-" + service_name = "icon-node-", + genesis_file_path = "/goloop/genesis/" ) HARDHAT_NODE_CLIENT = struct( diff --git a/services/jvm/icon/src/node-setup/start_icon_node.star b/services/jvm/icon/src/node-setup/start_icon_node.star index ee29cdc7..33e40dc6 100644 --- a/services/jvm/icon/src/node-setup/start_icon_node.star +++ b/services/jvm/icon/src/node-setup/start_icon_node.star @@ -1,17 +1,17 @@ constants = import_module("github.com/hugobyte/dive/package_io/constants.star") # Starts The Icon Node -def start_icon_node(plan,service_config,id,start_file_name): +def start_icon_node(plan,service_config,id,start_file_name,genesis_file_path,genesis_file_name): icon_node_constants = constants.ICON_NODE_CLIENT - service_name = service_config.service_name - private_port = service_config.private_port - public_port = service_config.public_port - network_name = service_config.network_name - p2p_listen_address = service_config.p2p_listen_address - p2p_address = service_config.p2p_address - cid = service_config.cid + service_name = service_config["service_name"] + private_port = service_config["private_port"] + public_port = service_config["public_port"] + network_name = service_config["network_name"] + p2p_listen_address = service_config["p2p_listen_address"] + p2p_address = service_config["p2p_address"] + cid = service_config["cid"] plan.print("Launching "+service_name+" Service") @@ -33,7 +33,9 @@ def start_icon_node(plan,service_config,id,start_file_name): files={ icon_node_constants.config_files_directory : "config-files-{0}".format(id), icon_node_constants.contracts_directory : "contracts-{0}".format(id), - icon_node_constants.keystore_directory : "kesytore-{0}".format(id) + icon_node_constants.keystore_directory : "kesytore-{0}".format(id), + icon_node_constants.genesis_file_path : genesis_file_path + }, env_vars={ "GOLOOP_LOG_LEVEL": "trace", @@ -42,7 +44,7 @@ def start_icon_node(plan,service_config,id,start_file_name): "GOLOOP_P2P": ":%s" % p2p_address, "ICON_CONFIG": icon_node_constants.config_files_directory+"icon_config.json" }, - cmd= ["/bin/sh","-c",icon_node_constants.config_files_directory+"%s" % start_file_name] + cmd= ["/bin/sh","-c",icon_node_constants.config_files_directory+"%s %s %s" % (start_file_name,cid,genesis_file_name)] ) diff --git a/services/jvm/icon/static-files/config/start-icon-1.sh b/services/jvm/icon/static-files/config/start-icon.sh similarity index 84% rename from services/jvm/icon/static-files/config/start-icon-1.sh rename to services/jvm/icon/static-files/config/start-icon.sh index 7b71700d..caf6c0a7 100755 --- a/services/jvm/icon/static-files/config/start-icon-1.sh +++ b/services/jvm/icon/static-files/config/start-icon.sh @@ -10,10 +10,11 @@ start_chain() { done echo $RES - CID=42f1f3 + + CID=${1} if [ ! -e ${GOLOOP_NODE_DIR}/${CID} ]; then # join chain - GENESIS=/goloop/config/genesis-icon-1.zip + GENESIS=/goloop/genesis/${2} goloop chain join \ --platform icon \ --channel icon_dex \ @@ -24,11 +25,11 @@ start_chain() { --db_type rocksdb \ --role 3 fi - goloop chain start 0x${CID} + goloop chain start ${CID} } # start chain in backgound -start_chain & +start_chain "$1" "$2" & # start goloop server exec goloop server start