diff --git a/cli/commands/bridge/bridge.go b/cli/commands/bridge/bridge.go index d3461edf..2b3bd593 100644 --- a/cli/commands/bridge/bridge.go +++ b/cli/commands/bridge/bridge.go @@ -10,7 +10,6 @@ import ( "github.com/hugobyte/dive/common" "github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -48,10 +47,11 @@ func btpBridgeCmd(diveContext *common.DiveContext) *cobra.Command { Run: func(cmd *cobra.Command, args []string) { common.ValidateCmdArgs(args, cmd.UsageString()) + diveContext.InitKurtosisContext() enclaveCtx, err := diveContext.GetEnclaveContext() if err != nil { - logrus.Errorln(err) + diveContext.Error(err.Error()) } diveContext.StartSpinner(fmt.Sprintf(" Starting BTP Bridge for %s,%s", chainA, chainB)) @@ -66,9 +66,16 @@ func btpBridgeCmd(diveContext *common.DiveContext) *cobra.Command { data, _, err := enclaveCtx.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveBridgeScript, bridgeMainFunction, params, common.DiveDryRun, common.DiveDefaultParallelism, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) if err != nil { - fmt.Println(err) + diveContext.FatalError("Starlark Run Failed", err.Error()) + } + response, services, skippedInstructions, err := diveContext.GetSerializedData(data) + if err != nil { + diveContext.StopServices(services) + diveContext.FatalError("Starlark Run Failed", err.Error()) + } - response := diveContext.GetSerializedData(data) + + diveContext.CheckInstructionSkipped(skippedInstructions, "Bridge Already Running") common.WriteToFile(response) @@ -77,10 +84,15 @@ func btpBridgeCmd(diveContext *common.DiveContext) *cobra.Command { data, _, err := enclaveCtx.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveBridgeScript, bridgeMainFunction, params, common.DiveDryRun, common.DiveDefaultParallelism, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) if err != nil { - fmt.Println(err) + diveContext.FatalError("Starlark Run Failed", err.Error()) } - response := diveContext.GetSerializedData(data) + response, services, skippedInstructions, err := diveContext.GetSerializedData(data) + if err != nil { + diveContext.StopServices(services) + diveContext.FatalError("Starlark Run Failed", err.Error()) + } + diveContext.CheckInstructionSkipped(skippedInstructions, "Bridge Already Running") common.WriteToFile(response) } else { @@ -91,8 +103,8 @@ func btpBridgeCmd(diveContext *common.DiveContext) *cobra.Command { }, } - btpbridgeCmd.Flags().StringVar(&chainA, "chainA", "", "Metion Name of Supported Chain") - btpbridgeCmd.Flags().StringVar(&chainB, "chainB", "", "Metion Name of Supported Chain") + btpbridgeCmd.Flags().StringVar(&chainA, "chainA", "", "Mention Name of Supported Chain") + btpbridgeCmd.Flags().StringVar(&chainB, "chainB", "", "Mention Name of Supported Chain") btpbridgeCmd.Flags().Bool("bridge", false, "Mention Bridge ENV") btpbridgeCmd.MarkFlagRequired("chainA") diff --git a/cli/commands/chain/types/eth.go b/cli/commands/chain/types/eth.go index 2b765c68..048c04f2 100644 --- a/cli/commands/chain/types/eth.go +++ b/cli/commands/chain/types/eth.go @@ -1,6 +1,9 @@ package types import ( + "os" + "strings" + "github.com/hugobyte/dive/common" "github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings" "github.com/spf13/cobra" @@ -17,13 +20,10 @@ It establishes a connection to the Ethereum network and allows the node in execu common.ValidateCmdArgs(args, cmd.UsageString()) - data, err := RunEthNode(diveContext) + data := RunEthNode(diveContext) - if err != nil { - diveContext.FatalError("Fail to Start ETH Node", err.Error()) - } diveContext.SetSpinnerMessage("Execution Completed") - err = data.WriteDiveResponse(diveContext) + err := data.WriteDiveResponse(diveContext) if err != nil { diveContext.FatalError("Failed To Write To File", err.Error()) } @@ -35,30 +35,47 @@ It establishes a connection to the Ethereum network and allows the node in execu } -func RunEthNode(diveContext *common.DiveContext) (*common.DiveserviceResponse, error) { - diveContext.StartSpinner(" Starting ETH Node") +func RunEthNode(diveContext *common.DiveContext) *common.DiveserviceResponse { + + diveContext.InitKurtosisContext() kurtosisEnclaveContext, err := diveContext.GetEnclaveContext() if err != nil { - return nil, err + diveContext.FatalError("Failed To Retrive Enclave Context", err.Error()) } + diveContext.StartSpinner(" Starting ETH Node") data, _, err := kurtosisEnclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveEthHardhatNodeScript, "start_eth_node", `{"args":{}}`, common.DiveDryRun, common.DiveDefaultParallelism, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) if err != nil { - return nil, err + + diveContext.FatalError("Starlark Run Failed", err.Error()) + } - responseData := diveContext.GetSerializedData(data) + responseData, services, skippedInstructions, err := diveContext.GetSerializedData(data) + + if err != nil { + if strings.Contains(err.Error(), "already exists") { + diveContext.StopSpinner("Eth Node Already Running") + os.Exit(0) + } else { + diveContext.StopServices(services) + diveContext.FatalError("Starlark Run Failed", err.Error()) + } + + } + diveContext.CheckInstructionSkipped(skippedInstructions, common.DiveEthNodeAlreadyRunning) ethResponseData := &common.DiveserviceResponse{} result, err := ethResponseData.Decode([]byte(responseData)) if err != nil { - return nil, err + diveContext.StopServices(services) + diveContext.FatalError("Fail to Start ETH Node", err.Error()) } - return result, nil + return result } diff --git a/cli/commands/chain/types/hardhat.go b/cli/commands/chain/types/hardhat.go index 11267763..1c70c1df 100644 --- a/cli/commands/chain/types/hardhat.go +++ b/cli/commands/chain/types/hardhat.go @@ -17,14 +17,11 @@ It establishes a connection to the hardhat network and allows the node in execut common.ValidateCmdArgs(args, cmd.UsageString()) - data, err := RunHardhatNode(diveContext) + data := RunHardhatNode(diveContext) - if err != nil { - diveContext.FatalError("Fail to Start Hardhat Node", err.Error()) - } diveContext.SetSpinnerMessage("Execution Completed") - err = data.WriteDiveResponse(diveContext) + err := data.WriteDiveResponse(diveContext) if err != nil { diveContext.FatalError("Failed To Write To File", err.Error()) } @@ -36,32 +33,38 @@ It establishes a connection to the hardhat network and allows the node in execut } -func RunHardhatNode(diveContext *common.DiveContext) (*common.DiveserviceResponse, error) { +func RunHardhatNode(diveContext *common.DiveContext) *common.DiveserviceResponse { - diveContext.StartSpinner(" Starting Hardhat Node") + diveContext.InitKurtosisContext() kurtosisEnclaveContext, err := diveContext.GetEnclaveContext() if err != nil { - return nil, err + diveContext.FatalError("Failed To Retrive Enclave Context", err.Error()) } - + diveContext.StartSpinner(" Starting Hardhat Node") data, _, err := kurtosisEnclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveEthHardhatNodeScript, "start_hardhat_node", "{}", common.DiveDryRun, common.DiveDefaultParallelism, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) if err != nil { - return nil, err + diveContext.FatalError("Starlark Run Failed", err.Error()) } - responseData := diveContext.GetSerializedData(data) + responseData, services, skippedInstructions, err := diveContext.GetSerializedData(data) + if err != nil { + diveContext.StopServices(services) + diveContext.FatalError("Starlark Run Failed", err.Error()) + } + diveContext.CheckInstructionSkipped(skippedInstructions, common.DiveHardhatNodeAlreadyRuning) hardhatResponseData := &common.DiveserviceResponse{} result, err := hardhatResponseData.Decode([]byte(responseData)) if err != nil { - return nil, err + diveContext.StopServices(services) + diveContext.FatalError("Failed To Unmarshall Data", err.Error()) } - return result, nil + return result } diff --git a/cli/commands/chain/types/icon.go b/cli/commands/chain/types/icon.go index 0b9f9424..790bf653 100644 --- a/cli/commands/chain/types/icon.go +++ b/cli/commands/chain/types/icon.go @@ -3,15 +3,16 @@ package types import ( "encoding/json" "fmt" + "os" "path/filepath" "github.com/hugobyte/dive/common" "github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings" - "github.com/sirupsen/logrus" + "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" "github.com/spf13/cobra" ) -const genesisIcon = "github.com/hugobyte/dive/services/jvm/icon/static-files/config/genesis-icon-0.zip" +const DefaultIconGenesisFile = "github.com/hugobyte/dive/services/jvm/icon/static-files/config/genesis-icon-0.zip" var ( id = "" @@ -44,17 +45,6 @@ func (sc *IconServiceConfig) GetDefaultConfigIconNode0() { } -func (sc *IconServiceConfig) GetDefaultConfigIconNode1() { - - sc.Id = "1" - sc.Port = 9081 - sc.PublicPort = 8091 - sc.P2PListenAddress = "7081" - sc.P2PAddress = "8081" - sc.Cid = "0x42f1f3" - -} - func (sc *IconServiceConfig) EncodeToString() (string, error) { encodedBytes, err := json.Marshal(sc) if err != nil { @@ -76,44 +66,16 @@ It establishes a connection to the Icon network and allows the node in executing decentralisation, _ := cmd.Flags().GetBool("decentralisation") - serviceConfig := &IconServiceConfig{} - - if configFilePath == "" { - serviceConfig.GetDefaultConfigIconNode0() - } else { - data, err := common.ReadConfigFile(configFilePath) - if err != nil { - serviceConfig.GetDefaultConfigIconNode0() - } - - err = json.Unmarshal(data, serviceConfig) - - if err != nil { - logrus.Fatalln(err) - } - - } - if decentralisation { - nodeResponse, err := RunIconNode(diveContext, serviceConfig, genesis) - if err != nil { - diveContext.StopSpinner("Failed") - diveContext.FatalError("Run Icon Node Failed", err.Error()) - } + nodeResponse := RunIconNode(diveContext) params := GetDecentralizeParms(nodeResponse.ServiceName, nodeResponse.PrivateEndpoint, nodeResponse.KeystorePath, nodeResponse.KeyPassword, nodeResponse.NetworkId) diveContext.SetSpinnerMessage("Starting Decentralisation") - response, err := Decentralisation(diveContext, params) + Decentralisation(diveContext, params) - if err != nil { - diveContext.FatalError("Icon Node Decentralisation Failed", err.Error()) - } - - diveContext.Info(response) - - err = nodeResponse.WriteDiveResponse(diveContext) + err := nodeResponse.WriteDiveResponse(diveContext) if err != nil { diveContext.FatalError("Failed To Write To File", err.Error()) @@ -123,12 +85,9 @@ It establishes a connection to the Icon network and allows the node in executing } else { - nodeResponse, err := RunIconNode(diveContext, serviceConfig, genesis) - if err != nil { - diveContext.FatalError("Run Icon Node Failed", err.Error()) - } + nodeResponse := RunIconNode(diveContext) - err = nodeResponse.WriteDiveResponse(diveContext) + err := nodeResponse.WriteDiveResponse(diveContext) if err != nil { diveContext.FatalError("Failed To Write To File", err.Error()) @@ -162,13 +121,9 @@ func IconDecentralisationCmd(diveContext *common.DiveContext) *cobra.Command { params := GetDecentralizeParms(serviceName, nodeEndpoint, keystorePath, keystorepassword, networkID) - response, err := Decentralisation(diveContext, params) + Decentralisation(diveContext, params) - if err != nil { - diveContext.FatalError("Icon Node Decentralisation Failed", err.Error()) - } - - diveContext.StopSpinner(fmt.Sprintln("Decentralisation Completed.Please find service details in dive.json", response)) + diveContext.StopSpinner(fmt.Sprintln("Decentralisation Completed.Please find service details in dive.json")) }, } decentralisationCmd.Flags().StringVarP(&serviceName, "serviceName", "s", "", "service name") @@ -187,86 +142,109 @@ func IconDecentralisationCmd(diveContext *common.DiveContext) *cobra.Command { } -func RunIconNode(diveContext *common.DiveContext, serviceConfig *IconServiceConfig, genesisFilePath string) (*common.DiveserviceResponse, error) { - diveContext.StartSpinner(" Starting Icon Node") +func RunIconNode(diveContext *common.DiveContext) *common.DiveserviceResponse { + + // Initialse Kurtosis Context + + diveContext.InitKurtosisContext() + + serviceConfig, err := getConfig() + if err != nil { + diveContext.FatalError("Failed To Get Node Service Config", err.Error()) + } + paramData, err := serviceConfig.EncodeToString() if err != nil { - return nil, err + diveContext.FatalError("Encoding Failed", err.Error()) } + diveContext.StartSpinner(" Starting Icon Node") kurtosisEnclaveContext, err := diveContext.GetEnclaveContext() if err != nil { - return nil, err + diveContext.FatalError("Failed To Retrive Enclave Context", err.Error()) } data, _, err := kurtosisEnclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveIconNodeScript, "get_service_config", paramData, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) if err != nil { - return nil, err + diveContext.FatalError("Starlark Run Failed", err.Error()) } - responseData := diveContext.GetSerializedData(data) - var genesisFile = "" - var uploadedFiles = "" - var genesisPath = "" + responseData, services, skippedInstructions, err := diveContext.GetSerializedData(data) - if genesisFilePath != "" { - genesisFileName := filepath.Base(genesisFilePath) - r, d, err := kurtosisEnclaveContext.UploadFiles(genesisFilePath, genesisFileName) - diveContext.SetSpinnerMessage(fmt.Sprintf("File Uploaded sucessfully : UUID %s", r)) - uploadedFiles = fmt.Sprintf(`{"file_path":"%s","file_name":"%s"}`, d, genesisFileName) + if err != nil { + diveContext.StopServices(services) + diveContext.FatalError("Starlark Run Failed", err.Error()) - if err != nil { - return nil, err - } - } else { - genesisFile = filepath.Base(genesisIcon) - genesisPath = genesisIcon - uploadedFiles = `{}` + } + genesisHandler, err := genesismanager(kurtosisEnclaveContext) + if err != nil { + diveContext.FatalError("Failed To Get Genesis", err.Error()) } - params := fmt.Sprintf(`{"service_config":%s,"id":"%s","uploaded_genesis":%s,"genesis_file_path":"%s","genesis_file_name":"%s"}`, responseData, serviceConfig.Id, uploadedFiles, genesisPath, genesisFile) + diveContext.CheckInstructionSkipped(skippedInstructions, "Instruction Executed Already") + + params := fmt.Sprintf(`{"service_config":%s,"id":"%s","uploaded_genesis":%s,"genesis_file_path":"%s","genesis_file_name":"%s"}`, responseData, serviceConfig.Id, genesisHandler.uploadedFiles, genesisHandler.genesisPath, genesisHandler.genesisFile) icon_data, _, err := kurtosisEnclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveIconNodeScript, "start_icon_node", params, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) if err != nil { - return nil, err + + diveContext.StopServices(services) + + diveContext.FatalError("Starlark Run Failed", err.Error()) } - diveContext.SetSpinnerMessage("Finailsing Icon Node") + diveContext.SetSpinnerMessage(" Finalizing Icon Node") - response := diveContext.GetSerializedData(icon_data) + response, services, skippedInstructions, err := diveContext.GetSerializedData(icon_data) + + if err != nil { + + diveContext.StopServices(services) + diveContext.FatalError("Starlark Run Failed", err.Error()) + + } + diveContext.CheckInstructionSkipped(skippedInstructions, common.DiveIconNodeAlreadyRunning) iconResponseData := &common.DiveserviceResponse{} result, err := iconResponseData.Decode([]byte(response)) if err != nil { - return nil, err + + diveContext.StopServices(services) + + diveContext.FatalError("Failed To Unmarshall", err.Error()) } - return result, nil + return result } -func Decentralisation(diveContext *common.DiveContext, params string) (string, error) { +func Decentralisation(diveContext *common.DiveContext, params string) { diveContext.StartSpinner(" Starting Icon Node Decentralisation") kurtosisEnclaveContext, err := diveContext.GetEnclaveContext() if err != nil { - return "", err + diveContext.FatalError("Failed To Retrieve Enclave Context", err.Error()) } data, _, err := kurtosisEnclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveIconDecentraliseScript, "configure_node", params, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) if err != nil { - return "", err + diveContext.FatalError("Starlark Run Failed", err.Error()) } - response := diveContext.GetSerializedData(data) + _, services, skippedInstructions, err := diveContext.GetSerializedData(data) + if err != nil { + + diveContext.StopServices(services) + diveContext.FatalError("Starlark Run Failed", err.Error()) - return response, nil + } + diveContext.CheckInstructionSkipped(skippedInstructions, "Decntralization Already Completed") } @@ -275,3 +253,61 @@ func GetDecentralizeParms(serviceName, nodeEndpoint, keystorePath, keystorepassw return fmt.Sprintf(`{"args":{"service_name":"%s","endpoint":"%s","keystore_path":"%s","keypassword":"%s","nid":"%s"}}`, serviceName, nodeEndpoint, keystorePath, keystorepassword, networkID) } + +func getConfig() (*IconServiceConfig, error) { + // Init Icon Node Service Config + + serviceConfig := &IconServiceConfig{} + + if configFilePath == "" { + serviceConfig.GetDefaultConfigIconNode0() + } else { + data, err := common.ReadConfigFile(configFilePath) + if err != nil { + return nil, err + } + + err = json.Unmarshal(data, serviceConfig) + + if err != nil { + return nil, err + } + + } + + return serviceConfig, 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 +} diff --git a/cli/commands/clean/clean.go b/cli/commands/clean/clean.go index a19ad650..8b0f1462 100644 --- a/cli/commands/clean/clean.go +++ b/cli/commands/clean/clean.go @@ -4,10 +4,10 @@ Copyright © 2023 Hugobyte AI Labs package clean import ( + "fmt" "os" "github.com/hugobyte/dive/common" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -19,22 +19,28 @@ func NewCleanCmd(diveContext *common.DiveContext) *cobra.Command { Long: `Destroys and removes any running encalves. If no enclaves running to remove it will throw an error`, Run: func(cmd *cobra.Command, args []string) { common.ValidateCmdArgs(args, cmd.UsageString()) + + diveContext.InitKurtosisContext() pwd, err := os.Getwd() if err != nil { diveContext.FatalError("Failed cleaning with error: %v", err.Error()) } - _, err = os.Stat(pwd + "/dive.json") + diveOutPath := fmt.Sprintf("%s/%s", pwd, common.DiveOutFile) + + _, err = os.Stat(diveOutPath) if err == nil { - os.Remove(pwd + "/dive.json") + os.Remove(diveOutPath) } - enclaveName := diveContext.GetEnclaves() if enclaveName == "" { - logrus.Errorf("No enclaves running to clean !!") + diveContext.Log.SetOutput(os.Stderr) + diveContext.Error("No enclaves running to clean !!") + } else { + diveContext.Log.SetOutput(os.Stdout) diveContext.Clean() } }, diff --git a/cli/commands/discord/discord.go b/cli/commands/discord/discord.go index b8e84750..edab1389 100644 --- a/cli/commands/discord/discord.go +++ b/cli/commands/discord/discord.go @@ -4,25 +4,30 @@ Copyright © 2023 Hugobyte AI Labs package discord import ( + "os" + "github.com/hugobyte/dive/common" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) const diveURL = "https://discord.gg/2rH5B7Ck9P" // discordCmd redirects users to DIVE discord channel -var DiscordCmd = &cobra.Command{ - Use: "discord", - Short: "Opens DIVE discord channel", - Long: `The command opens the Discord channel for DIVE, providing a direct link or launching the Discord application +func NewDiscordCmd(diveContext *common.DiveContext) *cobra.Command { + return &cobra.Command{ + Use: "discord", + Short: "Opens DIVE discord channel", + Long: `The command opens the Discord channel for DIVE, providing a direct link or launching the Discord application to access the dedicated DIVE community. It allows users to engage in discussions, seek support, share insights, and collaborate with other members of the DIVE community within the Discord platform.`, - Run: func(cmd *cobra.Command, args []string) { - common.ValidateCmdArgs(args, cmd.UsageString()) - logrus.Info("Redirecting to DIVE discord channel...") - if err := common.OpenFile(diveURL); err != nil { - logrus.Errorf("Failed to open Dive discord channel with error %v", err) - } - }, + Run: func(cmd *cobra.Command, args []string) { + diveContext.Log.SetOutput(os.Stdout) + common.ValidateCmdArgs(args, cmd.UsageString()) + diveContext.Log.Info("Redirecting to DIVE discord channel...") + if err := common.OpenFile(diveURL); err != nil { + diveContext.Log.Errorf("Failed to open Dive discord channel with error %v", err) + } + }, + } + } diff --git a/cli/commands/root.go b/cli/commands/root.go index 1d9cb98e..ea320a55 100644 --- a/cli/commands/root.go +++ b/cli/commands/root.go @@ -8,41 +8,29 @@ import ( "github.com/hugobyte/dive/commands/bridge" "github.com/hugobyte/dive/commands/chain" - "github.com/hugobyte/dive/common" - "github.com/hugobyte/dive/commands/clean" "github.com/hugobyte/dive/commands/discord" "github.com/hugobyte/dive/commands/tutorial" "github.com/hugobyte/dive/commands/twitter" "github.com/hugobyte/dive/commands/version" + "github.com/hugobyte/dive/common" + "github.com/hugobyte/dive/styles" "github.com/spf13/cobra" ) -// rootCmd represents the base command when called without any subcommands -var rootCmd = &cobra.Command{ - Use: "dive", - Short: "Deployable Infrastructure for Virtually Effortless blockchain integration", - Long: ``, - Run: func(cmd *cobra.Command, args []string) { - styles.RenderBanner() - cmd.Help() - }, -} - -// Execute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. -func Execute() { - - err := rootCmd.Execute() - if err != nil { - os.Exit(1) - } -} - -func init() { - +func RootCmd() *cobra.Command { diveContext := common.NewDiveContext() + var rootCmd = &cobra.Command{ + Use: "dive", + Short: "Deployable Infrastructure for Virtually Effortless blockchain integration", + Long: ``, + Run: func(cmd *cobra.Command, args []string) { + styles.RenderBanner() + cmd.Help() + + }, + } rootCmd.CompletionOptions.DisableDefaultCmd = true rootCmd.CompletionOptions.DisableNoDescFlag = true @@ -51,8 +39,21 @@ func init() { rootCmd.AddCommand(chain.NewChainCmd(diveContext)) rootCmd.AddCommand(bridge.NewBridgeCmd(diveContext)) rootCmd.AddCommand(clean.NewCleanCmd(diveContext)) - rootCmd.AddCommand(version.VersionCmd) - rootCmd.AddCommand(discord.DiscordCmd) - rootCmd.AddCommand(twitter.TwitterCmd) - rootCmd.AddCommand(tutorial.TutorialCmd) + rootCmd.AddCommand(version.NewVersionCmd(diveContext)) + rootCmd.AddCommand(discord.NewDiscordCmd(diveContext)) + rootCmd.AddCommand(twitter.NewtwitterCmd(diveContext)) + rootCmd.AddCommand(tutorial.NewTutorialCmd(diveContext)) + + rootCmd.PersistentFlags().BoolVarP(&common.DiveLogs, "logs", "l", false, "Prints out logs to Stdout") + + return rootCmd + +} + +func Execute() { + err := RootCmd().Execute() + + if err != nil { + os.Exit(1) + } } diff --git a/cli/commands/tutorial/tutorial.go b/cli/commands/tutorial/tutorial.go index 2b8670f0..7585d477 100644 --- a/cli/commands/tutorial/tutorial.go +++ b/cli/commands/tutorial/tutorial.go @@ -4,25 +4,30 @@ Copyright © 2023 Hugobyte AI Labs package tutorial import ( + "os" + "github.com/hugobyte/dive/common" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) const tutorialURL = "https://www.youtube.com/playlist?list=PL5Xd9z-fRL1vKtRlOzIlkhROspSSDeGyG" // tutorilaCmd redirects users to DIVE youtube playlist -var TutorialCmd = &cobra.Command{ - Use: "tutorial", - Short: "Opens DIVE tutorial youtube playlist", - Long: `The command opens the YouTube playlist containing DIVE tutorials. It launches a web browser or the YouTube application, +func NewTutorialCmd(diveContext *common.DiveContext) *cobra.Command { + + return &cobra.Command{ + Use: "tutorial", + Short: "Opens DIVE tutorial youtube playlist", + Long: `The command opens the YouTube playlist containing DIVE tutorials. It launches a web browser or the YouTube application, directing users to a curated collection of tutorial videos specifically designed to guide and educate users about DIVE. The playlist offers step-by-step instructions, tips, and demonstrations to help users better understand and utilize the features and functionalities of DIVE.`, - Run: func(cmd *cobra.Command, args []string) { - common.ValidateCmdArgs(args, cmd.UsageString()) - logrus.Info("Redirecting to YouTube...") - if err := common.OpenFile(tutorialURL); err != nil { - logrus.Errorf("Failed to open Dive YouTube chanel with error %v", err) - } - }, + Run: func(cmd *cobra.Command, args []string) { + diveContext.Log.SetOutput(os.Stdout) + common.ValidateCmdArgs(args, cmd.UsageString()) + diveContext.Log.Info("Redirecting to YouTube...") + if err := common.OpenFile(tutorialURL); err != nil { + diveContext.Log.Errorf("Failed to open Dive YouTube chanel with error %v", err) + } + }, + } } diff --git a/cli/commands/twitter/twitter.go b/cli/commands/twitter/twitter.go index 1c74c27e..822e7016 100644 --- a/cli/commands/twitter/twitter.go +++ b/cli/commands/twitter/twitter.go @@ -4,26 +4,30 @@ Copyright © 2023 Hugobyte AI Labs package twitter import ( + "os" + "github.com/hugobyte/dive/common" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) const twitterURL = "https://twitter.com/hugobyte" // twitterCmd redirects users to twitter home page -var TwitterCmd = &cobra.Command{ - Use: "twitter", - Short: "Opens official HugoByte twitter home page", - Long: `The command opens the official HugoByte Twitter homepage. It launches a web browser and directs users +func NewtwitterCmd(diveContext *common.DiveContext) *cobra.Command { + return &cobra.Command{ + Use: "twitter", + Short: "Opens official HugoByte twitter home page", + Long: `The command opens the official HugoByte Twitter homepage. It launches a web browser and directs users to the designated Twitter profile of HugoByte, providing access to the latest updates, announcements, news, and insights shared by the official HugoByte Twitter account. Users can stay informed about HugoByte's activities, engage with the community, and follow our social media presence directly from the Twitter homepage.`, - Run: func(cmd *cobra.Command, args []string) { - common.ValidateCmdArgs(args, cmd.UsageString()) - logrus.Info("Redirecting to twitter...") - if err := common.OpenFile(twitterURL); err != nil { - logrus.Errorf("Failed to open HugoByte twitter with error %v", err) - } - }, + Run: func(cmd *cobra.Command, args []string) { + diveContext.Log.SetOutput(os.Stdout) + common.ValidateCmdArgs(args, cmd.UsageString()) + diveContext.Log.Info("Redirecting to twitter...") + if err := common.OpenFile(twitterURL); err != nil { + diveContext.Log.Errorf("Failed to open HugoByte twitter with error %v", err) + } + }, + } } diff --git a/cli/commands/version/version.go b/cli/commands/version/version.go index 65c2b2b5..5a0b7092 100644 --- a/cli/commands/version/version.go +++ b/cli/commands/version/version.go @@ -5,28 +5,31 @@ package version import ( "fmt" + "os" "github.com/fatih/color" "github.com/hugobyte/dive/common" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) // versionCmd represents the version command -var VersionCmd = &cobra.Command{ - Use: "version", - 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) { - common.ValidateCmdArgs(args, cmd.UsageString()) +func NewVersionCmd(diveContext *common.DiveContext) *cobra.Command { + return &cobra.Command{ + Use: "version", + 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) { + common.ValidateCmdArgs(args, cmd.UsageString()) + diveContext.Log.SetOutput(os.Stdout) + // Checks for latest Version + latestVersion := common.GetLatestVersion() + if common.DiveVersion != latestVersion { + diveContext.Log.Warnf("Update available '%s'. Get the latest version of our DIVE CLI for bug fixes, performance improvements, and new features.", latestVersion) + } + version := color.New(color.Bold).Sprintf("CLI version - %s", common.DiveVersion) + fmt.Println(version) - // Checks for latest Version - latestVersion := common.GetLatestVersion() - if common.DiveVersion != latestVersion { - logrus.Warnf("Update available '%s'. Get the latest version of our DIVE CLI for bug fixes, performance improvements, and new features.", latestVersion) - } - version := color.New(color.Bold).Sprintf("CLI version - %s", common.DiveVersion) - fmt.Println(version) + }, + } - }, } diff --git a/cli/common/constants.go b/cli/common/constants.go index b54b5104..d1e194f7 100644 --- a/cli/common/constants.go +++ b/cli/common/constants.go @@ -1,14 +1,31 @@ package common +var DiveLogs bool + +// !!!!!!!!!!! DO NOT UPDATE! WILL BE UPDATED DURING THE RELEASE PROCESS !!!!!!!!!!!!!!!!!!!!!! +var DiveVersion = "v0.0.1-beta" + const ( - DiveEnclave = "dive" - DiveRemotePackagePath = "github.com/hugobyte/dive" - DiveIconNodeScript = "services/jvm/icon/src/node-setup/start_icon_node.star" - DiveIconDecentraliseScript = "services/jvm/icon/src/node-setup/setup_icon_node.star" - DiveEthHardhatNodeScript = "services/evm/eth/src/node-setup/start-eth-node.star" - DiveBridgeScript = "main.star" - DiveDryRun = false - DiveDefaultParallelism = 4 + DiveEnclave = "dive" + DiveRemotePackagePath = "github.com/hugobyte/dive" + DiveIconNodeScript = "services/jvm/icon/src/node-setup/start_icon_node.star" + DiveIconDecentraliseScript = "services/jvm/icon/src/node-setup/setup_icon_node.star" + DiveEthHardhatNodeScript = "services/evm/eth/src/node-setup/start-eth-node.star" + DiveBridgeScript = "main.star" + DiveDryRun = false + DiveDefaultParallelism = 4 + DiveEthNodeAlreadyRunning = "Eth Node Already Running" + DiveHardhatNodeAlreadyRuning = "Hardhat Node Already Running" + DiveIconNodeAlreadyRunning = "Icon Node Already Running" + DiveLogDirectory = "/logs/" + DiveDitLogFile = "divelog.log" + DiveErorLogFile = "error.log" + DiveOutFile = "dive.json" + starlarkScript = ` +def run(plan, args): + plan.stop_service(name=args["service_name"]) + plan.print(args["uuid"]) # we add this print of a random UUID to make sure the single stop_service above won't get cached +` ) const ( @@ -22,6 +39,3 @@ const ( openFileWindowsCommandFirstArgumentDefault = "url.dll,FileProtocolHandler" ) - -// !!!!!!!!!!! DO NOT UPDATE! WILL BE UPDATED DURING THE RELEASE PROCESS !!!!!!!!!!!!!!!!!!!!!! -var DiveVersion = "v0.0.1-beta" diff --git a/cli/common/context.go b/cli/common/context.go new file mode 100644 index 00000000..842c6223 --- /dev/null +++ b/cli/common/context.go @@ -0,0 +1,218 @@ +package common + +import ( + "context" + "errors" + "fmt" + "os" + "strings" + "time" + + "github.com/briandowns/spinner" + "github.com/fatih/color" + "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/kurtosis-tech/kurtosis/api/golang/engine/lib/kurtosis_context" + + log "github.com/sirupsen/logrus" +) + +type DiveContext struct { + Ctx context.Context + KurtosisContext *kurtosis_context.KurtosisContext + Log *log.Logger + spinner *spinner.Spinner +} + +func NewDiveContext() *DiveContext { + + ctx := context.Background() + log := setupLogger() + + spinner := spinner.New(spinner.CharSets[80], 100*time.Millisecond, spinner.WithWriter(os.Stderr)) + + return &DiveContext{Ctx: ctx, Log: log, spinner: spinner} +} + +func (diveContext *DiveContext) GetEnclaveContext() (*enclaves.EnclaveContext, error) { + + _, err := diveContext.KurtosisContext.GetEnclave(diveContext.Ctx, DiveEnclave) + if err != nil { + enclaveCtx, err := diveContext.KurtosisContext.CreateEnclave(diveContext.Ctx, DiveEnclave, false) + if err != nil { + return nil, err + + } + return enclaveCtx, nil + } + enclaveCtx, err := diveContext.KurtosisContext.GetEnclaveContext(diveContext.Ctx, DiveEnclave) + + if err != nil { + return nil, err + } + return enclaveCtx, nil +} + +// To get names of running enclaves, returns empty string if no enclaves +func (diveContext *DiveContext) GetEnclaves() string { + enclaves, err := diveContext.KurtosisContext.GetEnclaves(diveContext.Ctx) + if err != nil { + diveContext.Log.Errorf("Getting Enclaves failed with error: %v", err) + } + enclaveMap := enclaves.GetEnclavesByName() + for _, enclaveInfoList := range enclaveMap { + for _, enclaveInfo := range enclaveInfoList { + return enclaveInfo.GetName() + } + } + return "" +} + +// Funstionality to clean the enclaves +func (diveContext *DiveContext) Clean() { + diveContext.Log.SetOutput(os.Stdout) + diveContext.Log.Info("Successfully connected to kurtosis engine...") + diveContext.Log.Info("Initializing cleaning process...") + // shouldCleanAll set to true as default for beta release. + enclaves, err := diveContext.KurtosisContext.Clean(diveContext.Ctx, true) + if err != nil { + diveContext.Log.SetOutput(os.Stderr) + diveContext.Log.Errorf("Failed cleaning with error: %v", err) + } + + // Assuming only one enclave is running for beta release + diveContext.Log.Infof("Successfully destroyed and cleaned enclave %s", enclaves[0].Name) +} + +func (diveContext *DiveContext) FatalError(message, errorMessage string) { + + diveContext.Log.SetOutput(os.Stderr) + diveContext.spinner.Stop() + diveContext.Log.Fatalf("%s : %s", message, errorMessage) +} + +func (diveContext *DiveContext) Info(message string) { + + diveContext.Log.Infoln(message) +} + +func (diveContext *DiveContext) StartSpinner(message string) { + + diveContext.spinner.Suffix = message + diveContext.spinner.Color("green") + + diveContext.spinner.Start() +} + +func (diveContext *DiveContext) SetSpinnerMessage(message string) { + + diveContext.spinner.Suffix = message +} + +func (diveContext *DiveContext) StopSpinner(message string) { + c := color.New(color.FgCyan).Add(color.Underline) + diveContext.spinner.FinalMSG = c.Sprintln(message) + diveContext.spinner.Stop() + +} + +func (diveContext *DiveContext) GetSerializedData(response chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine) (string, map[string]string, map[string]bool, error) { + if DiveLogs { + diveContext.spinner.Stop() + diveContext.Log.SetOutput(os.Stdout) + } + var serializedOutputObj string + services := map[string]string{} + + skippedInstruction := map[string]bool{} + for executionResponse := range response { + + if strings.Contains(executionResponse.GetInstructionResult().GetSerializedInstructionResult(), "added with service") { + res1 := strings.Split(executionResponse.GetInstructionResult().GetSerializedInstructionResult(), " ") + serviceName := res1[1][1 : len(res1[1])-1] + serviceUUID := res1[len(res1)-1][1 : len(res1[len(res1)-1])-1] + services[serviceName] = serviceUUID + } + + diveContext.Log.Info(executionResponse.String()) + + if executionResponse.GetInstruction().GetIsSkipped() { + skippedInstruction[executionResponse.GetInstruction().GetExecutableInstruction()] = executionResponse.GetInstruction().GetIsSkipped() + break + } + + if executionResponse.GetError() != nil { + + return "", services, nil, errors.New(executionResponse.GetError().String()) + + } + + runFinishedEvent := executionResponse.GetRunFinishedEvent() + + if runFinishedEvent != nil { + + if runFinishedEvent.GetIsRunSuccessful() { + serializedOutputObj = runFinishedEvent.GetSerializedOutput() + + } else { + return "", services, nil, errors.New(executionResponse.GetError().String()) + } + + } else { + diveContext.spinner.Color("blue") + if executionResponse.GetProgressInfo() != nil { + c := color.New(color.FgGreen) + diveContext.spinner.Suffix = c.Sprintf(strings.ReplaceAll(executionResponse.GetProgressInfo().String(), "current_step_info:", " ")) + + } + } + + } + + return serializedOutputObj, services, skippedInstruction, nil + +} + +func (diveContext *DiveContext) Error(err string) { + diveContext.Log.Error(err) +} + +func (diveContext *DiveContext) InitKurtosisContext() { + kurtosisContext, err := kurtosis_context.NewKurtosisContextFromLocalEngine() + if err != nil { + diveContext.Log.SetOutput(os.Stderr) + diveContext.Log.Fatal("The Kurtosis Engine Server is unavailable and is probably not running; you will need to start it using the Kurtosis CLI before you can create a connection to it") + + } + diveContext.KurtosisContext = kurtosisContext +} + +func (diveContext *DiveContext) CheckInstructionSkipped(instuctions map[string]bool, message string) { + + if len(instuctions) != 0 { + + diveContext.StopSpinner(message) + os.Exit(0) + } +} + +func (diveContext *DiveContext) StopServices(services map[string]string) { + if len(services) != 0 { + enclaveContext, err := diveContext.KurtosisContext.GetEnclaveContext(diveContext.Ctx, DiveEnclave) + + if err != nil { + diveContext.Log.Fatal("Failed To Retrieve Enclave Context", err) + } + + for serviceName, serviceUUID := range services { + params := fmt.Sprintf(`{"service_name": "%s", "uuid": "%s"}`, serviceName, serviceUUID) + _, err := enclaveContext.RunStarlarkScriptBlocking(diveContext.Ctx, "", starlarkScript, params, DiveDryRun, DiveDefaultParallelism, nil) + if err != nil { + diveContext.Log.Fatal("Failed To Stop Services", err) + } + + } + + } + +} diff --git a/cli/common/types.go b/cli/common/types.go index 0656729d..182f4a9d 100644 --- a/cli/common/types.go +++ b/cli/common/types.go @@ -4,19 +4,17 @@ import ( "context" "encoding/json" "fmt" + "io" + "log" "os" "os/exec" + "path/filepath" "runtime" - "strings" - "time" - "github.com/briandowns/spinner" - "github.com/fatih/color" "github.com/google/go-github/github" - "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/kurtosis-tech/kurtosis/api/golang/engine/lib/kurtosis_context" "github.com/kurtosis-tech/stacktrace" + "github.com/natefinch/lumberjack" + "github.com/rifflock/lfshook" "github.com/sirupsen/logrus" ) @@ -96,51 +94,6 @@ func GetLatestVersion() string { return release.GetName() } -type DiveContext struct { - Ctx context.Context - KurtosisContext *kurtosis_context.KurtosisContext - log *logrus.Logger - spinner *spinner.Spinner -} - -func NewDiveContext() *DiveContext { - - ctx := context.Background() - log := logrus.New() - log.SetFormatter(&logrus.TextFormatter{ - FullTimestamp: true, - TimestampFormat: "2006-01-02 15:04:05", - }) - - kurtosisContext, err := kurtosis_context.NewKurtosisContextFromLocalEngine() - if err != nil { - log.Fatal("The Kurtosis Engine Server is unavailable and is probably not running; you will need to start it using the Kurtosis CLI before you can create a connection to it") - - } - spinner := spinner.New(spinner.CharSets[80], 100*time.Millisecond, spinner.WithWriter(os.Stderr)) - - return &DiveContext{Ctx: ctx, KurtosisContext: kurtosisContext, log: log, spinner: spinner} -} - -func (diveContext *DiveContext) GetEnclaveContext() (*enclaves.EnclaveContext, error) { - - _, err := diveContext.KurtosisContext.GetEnclave(diveContext.Ctx, DiveEnclave) - if err != nil { - enclaveCtx, err := diveContext.KurtosisContext.CreateEnclave(diveContext.Ctx, DiveEnclave, false) - if err != nil { - return nil, err - - } - return enclaveCtx, nil - } - enclaveCtx, err := diveContext.KurtosisContext.GetEnclaveContext(diveContext.Ctx, DiveEnclave) - - if err != nil { - return nil, err - } - return enclaveCtx, nil -} - func ReadConfigFile(filePath string) ([]byte, error) { file, err := os.ReadFile(filePath) @@ -178,102 +131,62 @@ func WriteToFile(data string) error { return nil } -// To get names of running enclaves, returns empty string if no enclaves -func (diveContext *DiveContext) GetEnclaves() string { - enclaves, err := diveContext.KurtosisContext.GetEnclaves(diveContext.Ctx) - if err != nil { - logrus.Errorf("Getting Enclaves failed with error: %v", err) - } - enclaveMap := enclaves.GetEnclavesByName() - for _, enclaveInfoList := range enclaveMap { - for _, enclaveInfo := range enclaveInfoList { - return enclaveInfo.GetName() - } - } - return "" -} +func ValidateCmdArgs(args []string, cmd string) { + if len(args) != 0 { + logrus.Fatalf("Invalid Usage of command. Find cmd %s", cmd) -// Funstionality to clean the enclaves -func (diveContext *DiveContext) Clean() { - diveContext.log.Info("Successfully connected to kurtosis engine...") - diveContext.log.Info("Initializing cleaning process...") - // shouldCleanAll set to true as default for beta release. - enclaves, err := diveContext.KurtosisContext.Clean(diveContext.Ctx, true) - if err != nil { - diveContext.log.Errorf("Failed cleaning with error: %v", err) } - - // Assuming only one enclave is running for beta release - diveContext.log.Infof("Successfully destroyed and cleaned enclave %s", enclaves[0].Name) } -func (diveContext *DiveContext) FatalError(message, err string) { - - diveContext.log.Fatalf("%s : %s", message, err) -} - -func (diveContext *DiveContext) Info(message string) { - - diveContext.log.Infoln(message) -} - -func (diveContext *DiveContext) StartSpinner(message string) { - - diveContext.spinner.Suffix = message - diveContext.spinner.Color("green") - - diveContext.spinner.Start() -} - -func (diveContext *DiveContext) SetSpinnerMessage(message string) { - - diveContext.spinner.Suffix = message -} - -func (diveContext *DiveContext) StopSpinner(message string) { - c := color.New(color.FgCyan).Add(color.Underline) - diveContext.spinner.FinalMSG = c.Sprintln(message) - diveContext.spinner.Stop() - -} - -func (diveContext *DiveContext) GetSerializedData(response chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine) string { - - var serializedOutputObj string - - for executionResponseLine := range response { - - runFinishedEvent := executionResponseLine.GetRunFinishedEvent() +func setupLogger() *logrus.Logger { + pwd, err := os.Getwd() - if runFinishedEvent == nil { + if err != nil { + log.Fatalln(err) + } - diveContext.spinner.Color("blue") - if executionResponseLine.GetProgressInfo() != nil { - c := color.New(color.FgGreen) + log := logrus.New() - diveContext.spinner.Suffix = c.Sprintf(strings.ReplaceAll(executionResponseLine.GetProgressInfo().String(), "current_step_info:", " ")) + log.SetOutput(io.Discard) + log.SetFormatter(&logrus.TextFormatter{ + TimestampFormat: "2006-01-02 15:04:05", + FullTimestamp: true, + ForceColors: true, + }) - } - } else { + ditFilePath := pwd + DiveLogDirectory + DiveDitLogFile + errorFilePath := pwd + DiveLogDirectory + DiveErorLogFile - if runFinishedEvent.GetIsRunSuccessful() { + ditLogger := &lumberjack.Logger{ + // Log file abbsolute path, os agnostic + Filename: filepath.ToSlash(ditFilePath), + LocalTime: true, + } - serializedOutputObj = runFinishedEvent.GetSerializedOutput() + // Fork writing into two outputs + ditWriter := io.MultiWriter(ditLogger) - } else { - diveContext.spinner.Stop() - diveContext.log.Fatalln("Starlark Run Failed") - } - } + errorLogger := &lumberjack.Logger{ + Filename: filepath.ToSlash(errorFilePath), + LocalTime: true, } - return serializedOutputObj - -} + // Fork writing into two outputs + errorWriter := io.MultiWriter(errorLogger) -func ValidateCmdArgs(args []string, cmd string) { - if len(args) != 0 { - logrus.Fatalf("Invalid Usage of command. Find cmd %s", cmd) + log.AddHook(lfshook.NewHook( + lfshook.WriterMap{ + logrus.InfoLevel: ditWriter, + logrus.DebugLevel: ditWriter, + logrus.TraceLevel: ditWriter, + logrus.ErrorLevel: errorWriter, + logrus.FatalLevel: errorWriter, + logrus.WarnLevel: errorWriter, + }, + &logrus.JSONFormatter{ + TimestampFormat: "2006-01-02 15:04:05", + }, + )) - } + return log } diff --git a/cli/dive.json b/cli/dive.json new file mode 100644 index 00000000..ec6547b9 --- /dev/null +++ b/cli/dive.json @@ -0,0 +1,49 @@ +{ + "bridge": "true", + "chains": { + "eth": { + "block_number": "33", + "endpoint": "http://172.16.0.6:8545", + "endpoint_public": "http://", + "keypassword": "password", + "keystore_path": "keystores/eth_keystore.json", + "network": "0x301824.eth", + "network_name": "eth", + "nid": "0x301824", + "service_name": "el-1-geth-lighthouse" + }, + "icon": { + "block_number": "255", + "endpoint": "http://172.16.0.3:9080/api/v3/icon_dex", + "endpoint_public": "http://127.0.0.1:8090/api/v3/icon_dex", + "keypassword": "gochain", + "keystore_path": "keystores/keystore.json", + "network": "0x3.icon", + "networkId": "0x1", + "networkTypeId": "0x1", + "network_name": "icon-0", + "nid": "0x3", + "service_name": "icon-node-0" + } + }, + "contracts": { + "eth": { + "bmc": "0xB9D7a3554F221B34f49d7d3C61375E603aFb699e", + "bmcm": "0xAb2A01BC351770D09611Ac80f1DE076D56E0487d", + "bmcs": "0xBFF5cD0aA560e1d1C6B1E2C347860aDAe1bd8235", + "bmv": "0x765E6b67C589A4b40184AEd9D9ae7ba40E32F8d4", + "dapp": "0x9bE03fF3E1888A216f9e48c68B587A89c5b94CD6", + "xcall": "0x5911A6541729C227fAda7D5187ee7518B47fB237" + }, + "icon": { + "bmc": "cx66268c6fa24639717007915847425921325bf431", + "bmv": "cx5e0ce6d14e5ff60518b12470d1749a66c1aed138", + "dapp": "cx9f94b7c96d33a286e15404d3248a90682c77904d", + "xcall": "cx180667267388b4dccf9db4ec63e0f34cd55b7290" + } + }, + "links": { + "dst": "eth", + "src": "icon" + } +} \ No newline at end of file diff --git a/cli/go.mod b/cli/go.mod index 6a9bafd1..9be25b9e 100644 --- a/cli/go.mod +++ b/cli/go.mod @@ -6,36 +6,46 @@ require ( github.com/briandowns/spinner v1.23.0 github.com/fatih/color v1.15.0 github.com/google/go-github v17.0.0+incompatible - github.com/kurtosis-tech/kurtosis/api/golang v0.80.8 + github.com/kurtosis-tech/kurtosis/api/golang v0.80.19 github.com/kurtosis-tech/stacktrace v0.0.0-20211028211901-1c67a77b5409 + github.com/natefinch/lumberjack v2.0.0+incompatible github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.7.0 ) +require github.com/BurntSushi/toml v1.3.2 // indirect + require ( github.com/Masterminds/semver/v3 v3.1.1 // indirect - github.com/dsnet/compress v0.0.1 // indirect + github.com/andybalholm/brotli v1.0.1 // indirect + github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect github.com/go-yaml/yaml v2.1.0+incompatible // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/klauspost/compress v1.11.4 // indirect + github.com/klauspost/pgzip v1.2.5 // indirect github.com/kr/text v0.2.0 // indirect - github.com/kurtosis-tech/kurtosis-portal/api/golang v0.0.0-20230328194643-b4dea3081e25 // indirect + github.com/kurtosis-tech/kurtosis-portal/api/golang v0.0.0-20230712110324-ce92904bb514 // indirect github.com/kurtosis-tech/kurtosis/grpc-file-transfer/golang v0.0.0-20230427135111-ee2492059d06 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect - github.com/mholt/archiver v3.1.1+incompatible // indirect + github.com/mholt/archiver/v3 v3.5.1 // indirect github.com/nwaples/rardecode v1.1.3 // indirect - github.com/pierrec/lz4 v2.6.1+incompatible // indirect + github.com/pierrec/lz4/v4 v4.1.2 // indirect + github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 github.com/spf13/pflag v1.0.5 // indirect github.com/ulikunitz/xz v0.5.10 // indirect github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect - golang.org/x/net v0.8.0 // indirect + golang.org/x/net v0.12.0 // indirect golang.org/x/sys v0.10.0 // indirect golang.org/x/term v0.10.0 // indirect - golang.org/x/text v0.8.0 // indirect - google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect - google.golang.org/grpc v1.41.0 // indirect - google.golang.org/protobuf v1.29.1 // indirect -) \ No newline at end of file + golang.org/x/text v0.11.0 // indirect + google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230706204954-ccb25ca9f130 // indirect + google.golang.org/grpc v1.56.2 // indirect + google.golang.org/protobuf v1.31.0 // indirect + gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect +) diff --git a/cli/main.go b/cli/main.go index 4a7ac27b..849ba1e3 100644 --- a/cli/main.go +++ b/cli/main.go @@ -5,16 +5,10 @@ package main import ( "github.com/hugobyte/dive/commands" - "github.com/sirupsen/logrus" ) func main() { - logrus.SetFormatter(&logrus.TextFormatter{ - FullTimestamp: true, - TimestampFormat: "2006-01-02 15:04:05", - }) - commands.Execute() } diff --git a/cli/sample-jsons/config-jsons/config1.json b/cli/sample-jsons/config-jsons/config1.json deleted file mode 100644 index f3d14bf1..00000000 --- a/cli/sample-jsons/config-jsons/config1.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "id": "1", - "private_port": 9081, - "public_port": 8091, - "p2p_listen_address": "7081", - "p2p_address": "8081", - "cid": "0xacbc4e" - } \ No newline at end of file diff --git a/cli/sample-jsons/config-jsons/config0.json b/cli/sample-jsons/config0.json similarity index 100% rename from cli/sample-jsons/config-jsons/config0.json rename to cli/sample-jsons/config0.json diff --git a/cli/sample-jsons/config1.json b/cli/sample-jsons/config1.json new file mode 100644 index 00000000..334efe08 --- /dev/null +++ b/cli/sample-jsons/config1.json @@ -0,0 +1,8 @@ +{ + "id": "1", + "private_port": 9081, + "public_port": 8091, + "p2p_listen_address": "7081", + "p2p_address": "8081", + "cid": "0x42f1f3" +} \ No newline at end of file