diff --git a/cli/commands/bridge/bridge.go b/cli/commands/bridge/bridge.go deleted file mode 100644 index cae630fd..00000000 --- a/cli/commands/bridge/bridge.go +++ /dev/null @@ -1,50 +0,0 @@ -/* -Copyright © 2023 Hugobyte AI Labs -*/ -package bridge - -import ( - "fmt" - "os" - - "github.com/hugobyte/dive/cli/commands/bridge/relays" - "github.com/hugobyte/dive/cli/common" - "github.com/spf13/cobra" - "golang.org/x/exp/slices" -) - -func NewBridgeCmd(diveContext *common.DiveContext) *cobra.Command { - - var bridgeCmd = &cobra.Command{ - Use: "bridge", - Short: "Command for cross chain communication between two different chains", - Long: `To connect two different chains using any of the supported cross chain communication protocols. -This will create an relay to connect two different chains and pass any messages between them.`, - Run: func(cmd *cobra.Command, args []string) { - - validArgs := cmd.ValidArgs - for _, c := range cmd.Commands() { - validArgs = append(validArgs, c.Name()) - } - cmd.ValidArgs = validArgs - - if len(args) == 0 { - cmd.Help() - - } else if !slices.Contains(cmd.ValidArgs, args[0]) { - - diveContext.Log.SetOutput(os.Stderr) - diveContext.Error(fmt.Sprintf("Invalid Subcommand: %v", args)) - - cmd.Usage() - os.Exit(1) - } - }, - } - - bridgeCmd.AddCommand(relays.BtpRelayCmd(diveContext)) - - bridgeCmd.AddCommand(relays.IbcRelayCmd(diveContext)) - - return bridgeCmd -} diff --git a/cli/commands/bridge/relays/btp.go b/cli/commands/bridge/relays/btp.go deleted file mode 100644 index 824d1672..00000000 --- a/cli/commands/bridge/relays/btp.go +++ /dev/null @@ -1,234 +0,0 @@ -package relays - -import ( - "fmt" - "strconv" - - "github.com/hugobyte/dive/cli/commands/chain/types" - "github.com/hugobyte/dive/cli/common" - "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" - "github.com/spf13/cobra" -) - -const bridgeMainFunction = "run_btp_setup" -const runbridgeicon2icon = "start_btp_for_already_running_icon_nodes" -const runbridgeicon2ethhardhat = "start_btp_icon_to_eth_for_already_running_nodes" - -var ( - chainA string - chainB string - serviceA string - serviceB string -) - -var runChain = map[string]func(diveContext *common.DiveContext) *common.DiveserviceResponse{ - "icon": func(diveContext *common.DiveContext) *common.DiveserviceResponse { - nodeResponse := types.RunIconNode(diveContext) - params := types.GetDecentralizeParms(nodeResponse.ServiceName, nodeResponse.PrivateEndpoint, nodeResponse.KeystorePath, nodeResponse.KeyPassword, nodeResponse.NetworkId) - - diveContext.SetSpinnerMessage("Starting Decentralisation") - types.Decentralisation(diveContext, params) - - return nodeResponse - - }, - "eth": func(diveContext *common.DiveContext) *common.DiveserviceResponse { - return types.RunEthNode(diveContext) - - }, - "hardhat": func(diveContext *common.DiveContext) *common.DiveserviceResponse { - - return types.RunHardhatNode(diveContext) - }, -} - -func BtpRelayCmd(diveContext *common.DiveContext) *cobra.Command { - - var btpbridgeCmd = &cobra.Command{ - Use: "btp", - Short: "Starts BTP Bridge between ChainA and ChainB", - Long: ``, - Run: func(cmd *cobra.Command, args []string) { - common.ValidateCmdArgs(diveContext, args, cmd.UsageString()) - - diveContext.InitKurtosisContext() - enclaveCtx, err := diveContext.GetEnclaveContext() - - if err != nil { - diveContext.Error(err.Error()) - } - - bridge, _ := cmd.Flags().GetBool("bmvbridge") // To Specify Which Type of BMV to be used in btp setup(if true BMV bridge is used else BMV-BTP Block is used) - - chains := initChains(chainA, chainB, serviceA, serviceB, bridge) - - if err := chains.checkForBtpSupportedChains(); err != nil { - diveContext.FatalError(err.Error(), fmt.Sprintf("Supported Chains for BTP: %v", supportedChainsForBtp)) - } - - diveContext.StartSpinner(fmt.Sprintf(" Starting BTP Bridge for %s,%s", chains.chainA, chains.chainB)) - - if chains.areChainsIcon() { - - if chains.chainAServiceName != "" && chains.chainBServiceName != "" { - - srcChainServiceResponse, dstChainServiceResponse, err := chains.getServicesResponse() - - if err != nil { - diveContext.FatalError("Failed To read ServiceFile", err.Error()) - } - - runBtpSetupForAlreadyRunningNodes(diveContext, enclaveCtx, runbridgeicon2icon, chains.chainA, chains.chainB, chains.chainAServiceName, chains.chainBServiceName, bridge, srcChainServiceResponse, dstChainServiceResponse) - - } else { - - params := chains.getParams() - - runBtpSetupByRunningNodes(diveContext, enclaveCtx, params) - - } - - } else { - if chains.chainAServiceName != "" && chains.chainBServiceName != "" { - - srcChainServiceResponse, dstChainServiceResponse, err := chains.getServicesResponse() - - if err != nil { - diveContext.FatalError("failed to get service data", err.Error()) - } - - if chains.chainB == "icon" { - runBtpSetupForAlreadyRunningNodes(diveContext, enclaveCtx, runbridgeicon2ethhardhat, chains.chainB, chains.chainA, chains.chainBServiceName, chains.chainAServiceName, bridge, dstChainServiceResponse, srcChainServiceResponse) - } else { - - runBtpSetupForAlreadyRunningNodes(diveContext, enclaveCtx, runbridgeicon2ethhardhat, chains.chainA, chains.chainB, chains.chainAServiceName, chains.chainBServiceName, bridge, srcChainServiceResponse, dstChainServiceResponse) - - } - } else if (chains.chainAServiceName == "" && chains.chainBServiceName != "") || (chains.chainAServiceName != "" && chains.chainBServiceName == "") { - - var chainAServiceResponse string - var chainBServiceResponse string - var chainAServiceName string - var chainBServiceName string - - serviceConfig, err := common.ReadServiceJsonFile() - if err != nil { - diveContext.FatalError("failed to get service data", err.Error()) - } - - if chains.chainAServiceName == "" { - - chainBserviceresponse, OK := serviceConfig[chains.chainBServiceName] - if !OK { - diveContext.FatalError("failed to get service data", fmt.Sprint("service name not found:", chains.chainBServiceName)) - } - chainBServiceName = chainBserviceresponse.ServiceName - - chainBServiceResponse, err = chainBserviceresponse.EncodeToString() - - if err != nil { - diveContext.FatalError("failed to get service data", err.Error()) - } - - response := runChain[chains.chainA](diveContext) - chainAServiceName = response.ServiceName - chainAServiceResponse, err = response.EncodeToString() - if err != nil { - diveContext.FatalError("failed to get service data", err.Error()) - } - - } else if chains.chainBServiceName == "" { - - chainAserviceresponse, OK := serviceConfig[chains.chainAServiceName] - if !OK { - diveContext.FatalError("failed to get service data", fmt.Sprint("service name not found:", chains.chainAServiceName)) - } - - chainAServiceName = chainAserviceresponse.ServiceName - - chainAServiceResponse, err = chainAserviceresponse.EncodeToString() - - if err != nil { - diveContext.FatalError("failed to get service data", err.Error()) - } - - response := runChain[chains.chainB](diveContext) - chainBServiceName = response.ServiceName - chainBServiceResponse, err = response.EncodeToString() - if err != nil { - diveContext.FatalError("failed to get service data", err.Error()) - - } - } - if chains.chainB == "icon" { - runBtpSetupForAlreadyRunningNodes(diveContext, enclaveCtx, runbridgeicon2ethhardhat, chains.chainB, chains.chainA, chainBServiceName, chainAServiceName, bridge, chainBServiceResponse, chainAServiceResponse) - } else { - - runBtpSetupForAlreadyRunningNodes(diveContext, enclaveCtx, runbridgeicon2ethhardhat, chains.chainA, chains.chainB, chainAServiceName, chainBServiceName, bridge, chainAServiceResponse, chainBServiceResponse) - - } - - } else { - params := chains.getParams() - - runBtpSetupByRunningNodes(diveContext, enclaveCtx, params) - } - - } - - diveContext.StopSpinner(fmt.Sprintf("BTP Bridge Setup Completed between %s and %s. Please find service details in current working directory(dive.json)", chainA, chainB)) - }, - } - - btpbridgeCmd.Flags().StringVar(&chainA, "chainA", "", "Mention Name of Supported Chain") - btpbridgeCmd.Flags().StringVar(&chainB, "chainB", "", "Mention Name of Supported Chain") - btpbridgeCmd.Flags().BoolP("bmvbridge", "b", false, "To Specify Which Type of BMV to be used in btp setup(if true BMV bridge is used else BMV-BTP Block is used)") - - btpbridgeCmd.Flags().StringVar(&serviceA, "chainAServiceName", "", "Service Name of Chain A from services.json") - btpbridgeCmd.Flags().StringVar(&serviceB, "chainBServiceName", "", "Service Name of Chain B from services.json") - btpbridgeCmd.MarkFlagRequired("chainA") - btpbridgeCmd.MarkFlagRequired("chainB") - - return btpbridgeCmd -} - -func runBtpSetupByRunningNodes(diveContext *common.DiveContext, enclaveCtx *enclaves.EnclaveContext, params string) { - diveContext.SetSpinnerMessage(" Executing BTP Starlark Package") - starlarkConfig := diveContext.GetStarlarkRunConfig(params, common.DiveBridgeBtpScript, bridgeMainFunction) - data, _, err := enclaveCtx.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) - - if err != nil { - 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()) - - } - diveContext.CheckInstructionSkipped(skippedInstructions, "Bridge Already Running") - common.WriteToFile(response) - -} - -func runBtpSetupForAlreadyRunningNodes(diveContext *common.DiveContext, enclaveCtx *enclaves.EnclaveContext, mainFunctionName string, srcChain string, dstChain string, srcChainServiceName string, dstChainServiceName string, bridge bool, srcChainServiceResponse string, dstChainServiceResponse string) { - - params := fmt.Sprintf(`{"src_chain":"%s","dst_chain":"%s", "src_chain_config":%s, "dst_chain_config":%s, "bridge":%s}`, chainA, chainB, srcChainServiceResponse, dstChainServiceResponse, strconv.FormatBool(bridge)) - starlarkConfig := diveContext.GetStarlarkRunConfig(params, common.DiveBridgeBtpScript, mainFunctionName) - data, _, err := enclaveCtx.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) - - if err != nil { - 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()) - - } - - diveContext.CheckInstructionSkipped(skippedInstructions, "Bridge Already Running") - - common.WriteToFile(response) - -} diff --git a/cli/commands/bridge/relays/common.go b/cli/commands/bridge/relays/common.go deleted file mode 100644 index 9f97cb69..00000000 --- a/cli/commands/bridge/relays/common.go +++ /dev/null @@ -1,95 +0,0 @@ -package relays - -import ( - "fmt" - "strconv" - "strings" - - "slices" - - "github.com/hugobyte/dive/cli/common" -) - -var supportedChainsForBtp = []string{"icon", "eth", "hardhat"} -var supportedChainsForIbc = []string{"archway", "neutron", "icon"} - -type Chains struct { - chainA string - chainB string - chainAServiceName string - chainBServiceName string - bridge string -} - -func initChains(chainA, chainB, serviceA, serviceB string, bridge bool) *Chains { - return &Chains{ - - chainA: strings.ToLower(chainA), - chainB: strings.ToLower(chainB), - chainAServiceName: serviceA, - chainBServiceName: serviceB, - bridge: strconv.FormatBool(bridge), - } -} - -func (c *Chains) areChainsIcon() bool { - return (c.chainA == "icon" && c.chainB == "icon") -} - -func (chains *Chains) getParams() string { - return fmt.Sprintf(`{"src_chain": "%s", "dst_chain": "%s", "bridge":"%s"}`, chains.chainA, chains.chainB, chains.bridge) -} -func (chains *Chains) getIbcRelayParams() string { - - return fmt.Sprintf(`{"src_chain": "%s", "dst_chain": "%s"}`, chains.chainA, chains.chainB) -} - -func (chains *Chains) getServicesResponse() (string, string, error) { - - serviceConfig, err := common.ReadServiceJsonFile() - - if err != nil { - return "", "", err - } - - chainAServiceResponse, OK := serviceConfig[chains.chainAServiceName] - if !OK { - return "", "", fmt.Errorf("service name not found") - } - chainBServiceResponse, OK := serviceConfig[chains.chainBServiceName] - if !OK { - return "", "", fmt.Errorf("service name not found") - } - - srcChainServiceResponse, err := chainAServiceResponse.EncodeToString() - if err != nil { - return "", "", err - } - dstChainServiceResponse, err := chainBServiceResponse.EncodeToString() - - if err != nil { - return "", "", err - } - - return srcChainServiceResponse, dstChainServiceResponse, nil -} - -func (chains *Chains) checkForBtpSupportedChains() error { - if !slices.Contains(supportedChainsForBtp, chains.chainA) { - return fmt.Errorf("invalid Chain: %s", chains.chainA) - } - if !slices.Contains(supportedChainsForBtp, chains.chainB) { - return fmt.Errorf("invalid Chain: %s", chains.chainB) - } - return nil -} - -func (chains *Chains) checkForIbcSupportedChains() error { - if !slices.Contains(supportedChainsForIbc, chains.chainA) { - return fmt.Errorf("invalid Chain: %s", chains.chainA) - } - if !slices.Contains(supportedChainsForIbc, chains.chainB) { - return fmt.Errorf("invalid Chain: %s", chains.chainB) - } - return nil -} diff --git a/cli/commands/bridge/relays/ibc.go b/cli/commands/bridge/relays/ibc.go deleted file mode 100644 index 9655b3a8..00000000 --- a/cli/commands/bridge/relays/ibc.go +++ /dev/null @@ -1,159 +0,0 @@ -package relays - -import ( - "fmt" - - "github.com/hugobyte/dive/cli/common" - "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" - "github.com/spf13/cobra" -) - -func IbcRelayCmd(diveContext *common.DiveContext) *cobra.Command { - - ibcRelayCommand := &cobra.Command{ - Use: "ibc", - Short: "Start connection between Cosmos based chainA and ChainB and initiate communication between them", - Long: "", - Run: func(cmd *cobra.Command, args []string) { - - common.ValidateCmdArgs(diveContext, args, cmd.UsageString()) - diveContext.InitKurtosisContext() - - enclaveCtx, err := diveContext.GetEnclaveContext() - - if err != nil { - diveContext.Error(err.Error()) - } - - result := startIbcRelay(diveContext, enclaveCtx) - - err = common.WriteToFile(result) - - if err != nil { - diveContext.Error(err.Error()) - } - - diveContext.StopSpinner(fmt.Sprintf("IBC Setup Completed between %s and %s. Please find service details in current working directory(dive.json)", chainA, chainB)) - }, - } - - ibcRelayCommand.Flags().StringVar(&chainA, "chainA", "", "Mention Name of Supported Chain") - ibcRelayCommand.Flags().StringVar(&chainB, "chainB", "", "Mention Name of Supported Chain") - - ibcRelayCommand.Flags().StringVar(&serviceA, "chainAServiceName", "", "Service Name of Chain A from services.json") - ibcRelayCommand.Flags().StringVar(&serviceB, "chainBServiceName", "", "Service Name of Chain B from services.json") - ibcRelayCommand.MarkFlagRequired("chainA") - ibcRelayCommand.MarkFlagRequired("chainB") - - return ibcRelayCommand -} - -func startIbcRelay(diveContext *common.DiveContext, enclaveContext *enclaves.EnclaveContext) string { - diveContext.StartSpinner(" Starting IBC Setup") - chains := initChains(chainA, chainB, serviceA, serviceB, false) - var starlarkExecutionResponse string - var err error - - err = chains.checkForIbcSupportedChains() - if err != nil { - diveContext.FatalError(err.Error(), fmt.Sprintf("Supported chains are %v", supportedChainsForIbc)) - } - - if chains.chainAServiceName != "" && chains.chainBServiceName != "" { - - srcChainServiceResponse, dstChainServiceResponse, err := chains.getServicesResponse() - - if err != nil { - diveContext.FatalError("Failed To read ServiceFile", err.Error()) - } - starlarkExecutionResponse, err = setupIbcRelayforAlreadyRunningCosmosChain(diveContext, enclaveContext, chains.chainA, chains.chainB, srcChainServiceResponse, dstChainServiceResponse) - - if err != nil { - diveContext.FatalError("Starlark Run Failed", err.Error()) - } - - } else { - starlarkExecutionResponse, err = startCosmosChainsAndSetupIbcRelay(diveContext, enclaveContext, chains) - - if err != nil { - diveContext.FatalError("Starlark Run Failed", err.Error()) - } - - } - - if chainA == "icon" { - _, err := startIbcRelayIconToCosmos(diveContext, enclaveContext, common.RelayServiceNameIconToCosmos) - if err != nil { - diveContext.FatalError("Starlark Run Failed", err.Error()) - } - } - - return starlarkExecutionResponse -} - -func startIbcRelayIconToCosmos(diveContext *common.DiveContext, enclaveContext *enclaves.EnclaveContext, serviceName string) (string, error) { - params := fmt.Sprintf(`{"service_name": "%s"}`, serviceName) - starlarkConfig := diveContext.GetStarlarkRunConfig(params, "services/bridges/ibc/src/bridge.star", "start_relay") - executionData, _, err := enclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) - - if err != nil { - return "", err - } - - executionSerializedData, services, _, err := diveContext.GetSerializedData(executionData) - - if err != nil { - diveContext.StopServices(services) - return "", err - - } - - return executionSerializedData, nil -} - -func startCosmosChainsAndSetupIbcRelay(diveContext *common.DiveContext, enclaveCtx *enclaves.EnclaveContext, chains *Chains) (string, error) { - - params := chains.getIbcRelayParams() - - executionResult, err := runStarlarkPackage(diveContext, enclaveCtx, params, "run_cosmos_ibc_setup") - - if err != nil { - return "", err - } - - return executionResult, nil -} - -func setupIbcRelayforAlreadyRunningCosmosChain(diveContext *common.DiveContext, enclaveCtx *enclaves.EnclaveContext, chainA, chainB, chainAServiceResponse, chainBServiceResponse string) (string, error) { - - params := fmt.Sprintf(`{"src_chain":"%s","dst_chain":"%s", "src_chain_config":%s, "dst_chain_config":%s}`, chainA, chainB, chainAServiceResponse, chainBServiceResponse) - - executionResult, err := runStarlarkPackage(diveContext, enclaveCtx, params, "run_cosmos_ibc_relay_for_already_running_chains") - - if err != nil { - return "", err - } - - return executionResult, nil -} - -func runStarlarkPackage(diveContext *common.DiveContext, enclaveContext *enclaves.EnclaveContext, params, functionName string) (string, error) { - starlarkConfig := diveContext.GetStarlarkRunConfig(params, common.DiveBridgeIbcScript, functionName) - executionData, _, err := enclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) - - if err != nil { - return "", err - } - - executionSerializedData, services, skippedInstructions, err := diveContext.GetSerializedData(executionData) - - if err != nil { - diveContext.StopServices(services) - return "", err - - } - - diveContext.CheckInstructionSkipped(skippedInstructions, "Instruction Executed Already") - - return executionSerializedData, nil -} diff --git a/cli/commands/chain/chains.go b/cli/commands/chain/chains.go deleted file mode 100644 index 8f017bef..00000000 --- a/cli/commands/chain/chains.go +++ /dev/null @@ -1,65 +0,0 @@ -/* -Copyright © 2023 Hugobyte AI Labs -*/ -package chain - -import ( - "fmt" - "os" - "slices" - - "github.com/hugobyte/dive/cli/commands/chain/types" - "github.com/hugobyte/dive/cli/common" - "github.com/spf13/cobra" -) - -// chainCmd represents the chain command -func NewChainCmd(diveContext *common.DiveContext) *cobra.Command { - var chainCmd = &cobra.Command{ - - Use: "chain", - Short: "Build, initialize and start a given blockchain node", - Long: `The command builds, initializes, and starts a specified blockchain node, providing a seamless setup process. -It encompasses compiling and configuring the necessary dependencies and components required for the blockchain network. -By executing this command, the node is launched, enabling network participation, transaction processing, and ledger -maintenance within the specified blockchain ecosystem.`, - - Run: func(cmd *cobra.Command, args []string) { - validArgs := cmd.ValidArgs - for _, c := range cmd.Commands() { - validArgs = append(validArgs, c.Name()) - } - cmd.ValidArgs = validArgs - - if len(args) == 0 { - cmd.Help() - - } else if !slices.Contains(cmd.ValidArgs, args[0]) { - - diveContext.Log.SetOutput(os.Stderr) - diveContext.Error(fmt.Sprintf("Invalid Subcommand: %v", args)) - - cmd.Usage() - os.Exit(1) - } - - }, - } - - chainCmd.AddCommand(types.NewIconCmd(diveContext)) - chainCmd.AddCommand(types.NewEthCmd(diveContext)) - chainCmd.AddCommand(types.NewHardhatCmd(diveContext)) - chainCmd.AddCommand(types.NewArchwayCmd(diveContext)) - chainCmd.AddCommand(types.NewNeutronCmd(diveContext)) - - return chainCmd - -} - -func addSubcommandsToValidArgs(cmd *cobra.Command) { - validArgs := cmd.ValidArgs - for _, c := range cmd.Commands() { - validArgs = append(validArgs, c.Name()) - } - cmd.ValidArgs = validArgs -} diff --git a/cli/commands/chain/types/archway.go b/cli/commands/chain/types/archway.go deleted file mode 100644 index 3961329b..00000000 --- a/cli/commands/chain/types/archway.go +++ /dev/null @@ -1,143 +0,0 @@ -package types - -import ( - "encoding/json" - - "github.com/hugobyte/dive/cli/common" - "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" - "github.com/spf13/cobra" -) - -const ( - constructServiceConfigFunctionName = "get_service_config" - runArchwayNodeWithCustomServiceFunctionName = "start_cosmos_node" - runArchwayNodeWithDefaultConfigFunctionName = "start_node_service" -) - -var ( - config string -) - -type ArchwayServiceConfig struct { - Cid *string `json:"chain_id"` - Key *string `json:"key"` - PublicGrpcPort *int `json:"public_grpc"` - PublicHttpPort *int `json:"public_http"` - PublicTcpPort *int `json:"public_tcp"` - PublicRpcPort *int `json:"public_rpc"` - Password *string `json:"password"` -} - -func (as *ArchwayServiceConfig) EncodeToString() (string, error) { - - data, err := json.Marshal(as) - if err != nil { - return "", err - } - - return string(data), nil -} -func (as *ArchwayServiceConfig) ReadServiceConfig(path string) error { - configData, err := common.ReadConfigFile(config) - if err != nil { - return err - } - - err = json.Unmarshal(configData, as) - - if err != nil { - return err - } - return nil -} - -func NewArchwayCmd(diveContext *common.DiveContext) *cobra.Command { - - archwayCmd := &cobra.Command{ - Use: "archway", - Short: "Build, initialize and start a archway node", - Long: "The command starts the archway network and allows node in executing contracts", - Run: func(cmd *cobra.Command, args []string) { - common.ValidateCmdArgs(diveContext, args, cmd.UsageString()) - runResponse := RunArchwayNode(diveContext) - - common.WriteToServiceFile(runResponse.ServiceName, *runResponse) - - diveContext.StopSpinner("Archway Node Started. Please find service details in current working directory(services.json)") - }, - } - archwayCmd.Flags().StringVarP(&config, "config", "c", "", "path to custom config json file to start archway node ") - - return archwayCmd -} - -func RunArchwayNode(diveContext *common.DiveContext) *common.DiveserviceResponse { - diveContext.InitKurtosisContext() - kurtosisEnclaveContext, err := diveContext.GetEnclaveContext() - - if err != nil { - diveContext.FatalError("Failed To Retrive Enclave Context", err.Error()) - } - - diveContext.StartSpinner(" Starting Archway Node") - var serviceConfig = &ArchwayServiceConfig{} - var archwayResponse = &common.DiveserviceResponse{} - var starlarkExecutionData = "" - - if config != "" { - - err := serviceConfig.ReadServiceConfig(config) - - if err != nil { - diveContext.FatalError("Failed read service config", err.Error()) - } - encodedServiceConfigDataString, err := serviceConfig.EncodeToString() - - if err != nil { - diveContext.FatalError("Failed encode service config", err.Error()) - } - - starlarkExecutionData, err = RunArchwayNodeWithConfig(diveContext, kurtosisEnclaveContext, encodedServiceConfigDataString) - if err != nil { - diveContext.FatalError("Starlark Run Failed", err.Error()) - } - - } else { - - encodedServiceConfigDataString, err := serviceConfig.EncodeToString() - - if err != nil { - diveContext.FatalError("Failed encode service config", err.Error()) - } - starlarkExecutionData, err = RunArchwayNodeWithConfig(diveContext, kurtosisEnclaveContext, encodedServiceConfigDataString) - if err != nil { - diveContext.FatalError("Starlark Run Failed", err.Error()) - } - } - - err = json.Unmarshal([]byte(starlarkExecutionData), archwayResponse) - if err != nil { - diveContext.FatalError("Failed to Unmarshall Service Response", err.Error()) - } - - return archwayResponse -} - -func RunArchwayNodeWithConfig(diveContext *common.DiveContext, enclaveContext *enclaves.EnclaveContext, config string) (string, error) { - starlarkConfig := diveContext.GetStarlarkRunConfig(config, common.DiveArchwayDefaultNodeScript, runArchwayNodeWithDefaultConfigFunctionName) - nodeServiceResponse, _, err := enclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) - - if err != nil { - return "", err - } - - nodeServiceResponseData, services, skippedInstructions, err := diveContext.GetSerializedData(nodeServiceResponse) - if err != nil { - diveContext.StopServices(services) - diveContext.FatalError("Starlark Run Failed", err.Error()) - - } - diveContext.CheckInstructionSkipped(skippedInstructions, "Archway Node Already Running") - - return nodeServiceResponseData, nil -} diff --git a/cli/commands/chain/types/eth.go b/cli/commands/chain/types/eth.go deleted file mode 100644 index 4995b955..00000000 --- a/cli/commands/chain/types/eth.go +++ /dev/null @@ -1,81 +0,0 @@ -package types - -import ( - "os" - "strings" - - "github.com/hugobyte/dive/cli/common" - "github.com/spf13/cobra" -) - -func NewEthCmd(diveContext *common.DiveContext) *cobra.Command { - - var ethCmd = &cobra.Command{ - Use: "eth", - Short: "Build, initialize and start a eth node.", - Long: `The command starts an Ethereum node, initiating the process of setting up and launching a local Ethereum network. -It establishes a connection to the Ethereum network and allows the node in executing smart contracts and maintaining the decentralized ledger.`, - Run: func(cmd *cobra.Command, args []string) { - - common.ValidateCmdArgs(diveContext, args, cmd.UsageString()) - - data := RunEthNode(diveContext) - - diveContext.SetSpinnerMessage("Execution Completed") - err := common.WriteToServiceFile(data.ServiceName, *data) - if err != nil { - diveContext.FatalError("Failed To Write To File", err.Error()) - } - diveContext.StopSpinner("ETH Node Started. Please find service details in current working directory(services.json)") - - }, - } - - return ethCmd - -} - -func RunEthNode(diveContext *common.DiveContext) *common.DiveserviceResponse { - - diveContext.InitKurtosisContext() - kurtosisEnclaveContext, err := diveContext.GetEnclaveContext() - - if err != nil { - diveContext.FatalError("Failed To Retrive Enclave Context", err.Error()) - } - diveContext.StartSpinner(" Starting ETH Node") - starlarkConfig := diveContext.GetStarlarkRunConfig(`{}`, common.DiveEthHardhatNodeScript, "start_eth_node") - data, _, err := kurtosisEnclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) - - if err != nil { - - diveContext.FatalError("Starlark Run Failed", err.Error()) - - } - - 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 { - diveContext.StopServices(services) - diveContext.FatalError("Fail to Start ETH Node", err.Error()) - } - - return result - -} diff --git a/cli/commands/chain/types/hardhat.go b/cli/commands/chain/types/hardhat.go deleted file mode 100644 index b9db37c6..00000000 --- a/cli/commands/chain/types/hardhat.go +++ /dev/null @@ -1,70 +0,0 @@ -package types - -import ( - "github.com/hugobyte/dive/cli/common" - "github.com/spf13/cobra" -) - -func NewHardhatCmd(diveContext *common.DiveContext) *cobra.Command { - - var ethCmd = &cobra.Command{ - Use: "hardhat", - Short: "Build, initialize and start a hardhat node.", - Long: `The command starts an hardhat node, initiating the process of setting up and launching a local hardhat network. -It establishes a connection to the hardhat network and allows the node in executing smart contracts and maintaining the decentralized ledger.`, - Run: func(cmd *cobra.Command, args []string) { - - common.ValidateCmdArgs(diveContext, args, cmd.UsageString()) - - data := RunHardhatNode(diveContext) - - diveContext.SetSpinnerMessage("Execution Completed") - - err := common.WriteToServiceFile(data.ServiceName, *data) - if err != nil { - diveContext.FatalError("Failed To Write To File", err.Error()) - } - diveContext.StopSpinner("Hardhat Node Started. Please find service details in current working directory(services.json)") - }, - } - - return ethCmd - -} - -func RunHardhatNode(diveContext *common.DiveContext) *common.DiveserviceResponse { - - diveContext.InitKurtosisContext() - - kurtosisEnclaveContext, err := diveContext.GetEnclaveContext() - - if err != nil { - diveContext.FatalError("Failed To Retrive Enclave Context", err.Error()) - } - diveContext.StartSpinner(" Starting Hardhat Node") - starlarkConfig := diveContext.GetStarlarkRunConfig("{}", common.DiveEthHardhatNodeScript, "start_hardhat_node") - data, _, err := kurtosisEnclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) - - if err != nil { - diveContext.FatalError("Starlark Run Failed", err.Error()) - } - - 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 { - diveContext.StopServices(services) - diveContext.FatalError("Failed To Unmarshall Data", err.Error()) - } - - return result - -} diff --git a/cli/commands/chain/types/icon.go b/cli/commands/chain/types/icon.go deleted file mode 100644 index 9e304a0b..00000000 --- a/cli/commands/chain/types/icon.go +++ /dev/null @@ -1,282 +0,0 @@ -package types - -import ( - "encoding/json" - "fmt" - "os" - "path/filepath" - - "github.com/hugobyte/dive/cli/common" - "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" - "github.com/spf13/cobra" -) - -const DefaultIconGenesisFile = "../../static-files/config/genesis-icon-0.zip" - -var ( - genesis = "" - serviceName = "" - keystorePath = "" - keystorepassword = "" - networkID = "" - nodeEndpoint = "" - configFilePath = "" -) - -type IconServiceConfig struct { - 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) GetDefaultConfigIconNode0() { - 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(diveContext *common.DiveContext) *cobra.Command { - var iconCmd = &cobra.Command{ - Use: "icon", - Short: "Build, initialize and start a icon node.", - Long: `The command starts an Icon node, initiating the process of setting up and launching a local Icon network. -It establishes a connection to the Icon network and allows the node in executing smart contracts and maintaining the decentralized ledger.`, - Run: func(cmd *cobra.Command, args []string) { - - common.ValidateCmdArgs(diveContext, args, cmd.UsageString()) - - decentralisation, _ := cmd.Flags().GetBool("decentralisation") - - if decentralisation { - - nodeResponse := RunIconNode(diveContext) - - params := GetDecentralizeParms(nodeResponse.ServiceName, nodeResponse.PrivateEndpoint, nodeResponse.KeystorePath, nodeResponse.KeyPassword, nodeResponse.NetworkId) - - diveContext.SetSpinnerMessage("Starting Decentralisation") - Decentralisation(diveContext, params) - - err := common.WriteToServiceFile(nodeResponse.ServiceName, *nodeResponse) - - if err != nil { - diveContext.FatalError("Failed To Write To File", err.Error()) - } - - diveContext.StopSpinner("Icon Node Started. Please find service details in current working directory(services.json)") - - } else { - - nodeResponse := RunIconNode(diveContext) - - err := common.WriteToServiceFile(nodeResponse.ServiceName, *nodeResponse) - - if err != nil { - diveContext.FatalError("Failed To Write To File", err.Error()) - } - - diveContext.StopSpinner("Icon Node Started. Please find service details in current working directory(services.json)") - } - - }, - } - - iconCmd.Flags().StringVarP(&genesis, "genesis", "g", "", "path to custom genesis file") - iconCmd.Flags().StringVarP(&configFilePath, "config", "c", "", "path to custom config json file") - iconCmd.Flags().BoolP("decentralisation", "d", false, "decentralise Icon Node") - - decentralisationCmd := IconDecentralisationCmd(diveContext) - - iconCmd.AddCommand(decentralisationCmd) - - return iconCmd -} - -func IconDecentralisationCmd(diveContext *common.DiveContext) *cobra.Command { - - var decentralisationCmd = &cobra.Command{ - Use: "decentralize", - Short: "Decentralize already running Icon Node", - Long: `Decentralize Icon Node is necessary if you want to connect your local icon node to BTP network`, - Run: func(cmd *cobra.Command, args []string) { - - params := GetDecentralizeParms(serviceName, nodeEndpoint, keystorePath, keystorepassword, networkID) - diveContext.InitKurtosisContext() - Decentralisation(diveContext, params) - - diveContext.StopSpinner(fmt.Sprintln("Decentralisation Completed.Please find service details in services.json")) - }, - } - 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(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()) - } - - diveContext.StartSpinner(" Starting Icon Node") - kurtosisEnclaveContext, err := diveContext.GetEnclaveContext() - - if err != nil { - diveContext.FatalError("Failed To Retrive Enclave Context", err.Error()) - } - - genesisHandler, err := genesismanager(kurtosisEnclaveContext) - if err != nil { - diveContext.FatalError("Failed To Get Genesis", err.Error()) - } - - params := fmt.Sprintf(`{"private_port":%d, "public_port":%d, "p2p_listen_address": %s, "p2p_address":%s, "cid": "%s","uploaded_genesis":%s,"genesis_file_path":"%s","genesis_file_name":"%s"}`, serviceConfig.Port, serviceConfig.PublicPort, serviceConfig.P2PListenAddress, serviceConfig.P2PAddress, serviceConfig.Cid, genesisHandler.uploadedFiles, genesisHandler.genesisPath, genesisHandler.genesisFile) - starlarkConfig := diveContext.GetStarlarkRunConfig(params, common.DiveIconNodeScript, "start_icon_node") - icon_data, _, err := kurtosisEnclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) - - if err != nil { - diveContext.FatalError("Error while running kurtosis package to run icon node", err.Error()) - } - - diveContext.SetSpinnerMessage(" Finalizing Icon Node") - - 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 { - - diveContext.StopServices(services) - - diveContext.FatalError("Failed To Unmarshall", err.Error()) - } - - return result -} - -func Decentralisation(diveContext *common.DiveContext, params string) { - - diveContext.StartSpinner(" Starting Icon Node Decentralisation") - kurtosisEnclaveContext, err := diveContext.GetEnclaveContext() - - if err != nil { - diveContext.FatalError("Failed To Retrieve Enclave Context", err.Error()) - } - starlarkConfig := diveContext.GetStarlarkRunConfig(params, common.DiveIconDecentraliseScript, "configure_node") - data, _, err := kurtosisEnclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) - - if err != nil { - diveContext.FatalError("Starlark Run Failed", err.Error()) - } - - _, services, skippedInstructions, err := diveContext.GetSerializedData(data) - if err != nil { - - diveContext.StopServices(services) - diveContext.FatalError("Starlark Run Failed", err.Error()) - - } - diveContext.CheckInstructionSkipped(skippedInstructions, "Decntralization Already Completed") - -} - -func GetDecentralizeParms(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) -} - -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/chain/types/neutron.go b/cli/commands/chain/types/neutron.go deleted file mode 100644 index 50851fbc..00000000 --- a/cli/commands/chain/types/neutron.go +++ /dev/null @@ -1,140 +0,0 @@ -package types - -import ( - "encoding/json" - - "github.com/hugobyte/dive/cli/common" - "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" - "github.com/spf13/cobra" -) - -// Constants for function names -const ( - runNeutronNodeWithDefaultConfigFunctionName = "start_node_service" - runNeutronNodeWithCustomServiceFunctionName = "start_neutron_node" - constructNeutronServiceConfigFunctionName = "get_service_config" -) - -// Variable to store the Neutron node configuration file path -var ( - neutron_node_config string -) - -// NeutronServiceConfig stores configuration parameters for the Neutron service. -type NeutronServiceConfig struct { - ChainID *string `json:"chain_id"` - Key *string `json:"key"` - Password *string `json:"password"` - PublicGrpc *int `json:"public_grpc"` - PublicTCP *int `json:"public_tcp"` - PublicHTTP *int `json:"public_http"` - PublicRPC *int `json:"public_rpc"` -} - -// EncodeToString encodes the NeutronServiceConfig struct to a JSON string. -func (as *NeutronServiceConfig) EncodeToString() (string, error) { - data, err := json.Marshal(as) - if err != nil { - return "", err - } - return string(data), nil -} - -// ReadServiceConfig reads the Neutron service configuration from a JSON file. -func (as *NeutronServiceConfig) ReadServiceConfig(path string) error { - configData, err := common.ReadConfigFile(neutron_node_config) - if err != nil { - return err - } - err = json.Unmarshal(configData, as) - if err != nil { - return err - } - return nil -} - -// NewNeutronCmd creates a new Cobra command for the Neutron service. -func NewNeutronCmd(diveContext *common.DiveContext) *cobra.Command { - neutronCmd := &cobra.Command{ - Use: "neutron", - Short: "Build, initialize and start a neutron node", - Long: "The command starts the neutron network and allows node in executing contracts", - Run: func(cmd *cobra.Command, args []string) { - common.ValidateCmdArgs(diveContext, args, cmd.UsageString()) - runResponse := RunNeutronNode(diveContext) - common.WriteToServiceFile(runResponse.ServiceName, *runResponse) - diveContext.StopSpinner("Neutron Node Started. Please find service details in current working directory(services.json)") - }, - } - neutronCmd.Flags().StringVarP(&neutron_node_config, "config", "c", "", "path to custom config json file to start neutron node ") - return neutronCmd -} - -// RunNeutronNode starts the Neutron node. -func RunNeutronNode(diveContext *common.DiveContext) *common.DiveserviceResponse { - diveContext.InitKurtosisContext() - kurtosisEnclaveContext, err := diveContext.GetEnclaveContext() - if err != nil { - diveContext.FatalError("Failed To Retrieve Enclave Context", err.Error()) - } - - diveContext.StartSpinner("Starting Neutron Node") - var serviceConfig = &NeutronServiceConfig{} - var neutronResponse = &common.DiveserviceResponse{} - var starlarkExecutionData = "" - - if neutron_node_config != "" { - err := serviceConfig.ReadServiceConfig(neutron_node_config) - if err != nil { - diveContext.FatalError("Failed read service config", err.Error()) - } - - encodedServiceConfigDataString, err := serviceConfig.EncodeToString() - if err != nil { - diveContext.FatalError("Failed to encode service config", err.Error()) - } - - // Run Neutron Node with custom service config - starlarkExecutionData, err = RunNeutronWithServiceConfig(diveContext, kurtosisEnclaveContext, encodedServiceConfigDataString) - if err != nil { - diveContext.FatalError("Starlark Run Failed", err.Error()) - } - - } else { - // Run Neutron Node with default service config - encodedServiceConfigDataString, err := serviceConfig.EncodeToString() - if err != nil { - diveContext.FatalError("Failed to encode service config", err.Error()) - } - starlarkExecutionData, err = RunNeutronWithServiceConfig(diveContext, kurtosisEnclaveContext, encodedServiceConfigDataString) - if err != nil { - diveContext.FatalError("Starlark Run Failed", err.Error()) - } - } - - err = json.Unmarshal([]byte(starlarkExecutionData), neutronResponse) - if err != nil { - diveContext.FatalError("Failed to Unmarshal Service Response", err.Error()) - } - - return neutronResponse -} - -// RunNeutronWithServiceConfig runs the Neutron service with the provided configuration data. -func RunNeutronWithServiceConfig(diveContext *common.DiveContext, enclaveContext *enclaves.EnclaveContext, config string) (string, error) { - - starlarkConfig := diveContext.GetStarlarkRunConfig(config, common.DiveNeutronDefaultNodeScript, runNeutronNodeWithDefaultConfigFunctionName) - nodeServiceResponse, _, err := enclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) - if err != nil { - return "", err - } - - nodeServiceResponseData, services, skippedInstructions, err := diveContext.GetSerializedData(nodeServiceResponse) - if err != nil { - diveContext.StopServices(services) - diveContext.FatalError("Starlark Run Failed", err.Error()) - } - - diveContext.CheckInstructionSkipped(skippedInstructions, "Neutron Node Already Running") - return nodeServiceResponseData, nil -} diff --git a/cli/commands/clean/clean.go b/cli/commands/clean/clean.go deleted file mode 100644 index 8644d2a4..00000000 --- a/cli/commands/clean/clean.go +++ /dev/null @@ -1,58 +0,0 @@ -/* -Copyright © 2023 Hugobyte AI Labs -*/ -package clean - -import ( - "fmt" - "os" - - "github.com/hugobyte/dive/cli/common" - "github.com/spf13/cobra" -) - -func NewCleanCmd(diveContext *common.DiveContext) *cobra.Command { - - cleanCmd := &cobra.Command{ - Use: "clean", - Short: "Cleans up Kurtosis leftover artifacts", - 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(diveContext, args, cmd.UsageString()) - - diveContext.InitKurtosisContext() - pwd, err := os.Getwd() - - if err != nil { - diveContext.FatalError("Failed cleaning with error: %v", err.Error()) - } - - diveOutPath := fmt.Sprintf("%s/%s", pwd, common.DiveOutFile) - - _, err = os.Stat(diveOutPath) - - if err == nil { - os.Remove(diveOutPath) - } - servicesOutPath := fmt.Sprintf("%s/%s", pwd, common.ServiceFilePath) - _, err = os.Stat(servicesOutPath) - - if err == nil { - os.Remove(servicesOutPath) - } - - enclaveName := diveContext.GetEnclaves() - if enclaveName == "" { - diveContext.Log.SetOutput(os.Stderr) - diveContext.Error("No enclaves running to clean !!") - - } else { - diveContext.Log.SetOutput(os.Stdout) - diveContext.Clean() - } - }, - } - - return cleanCmd - -} diff --git a/cli/commands/discord/discord.go b/cli/commands/discord/discord.go deleted file mode 100644 index 41885d26..00000000 --- a/cli/commands/discord/discord.go +++ /dev/null @@ -1,33 +0,0 @@ -/* -Copyright © 2023 Hugobyte AI Labs -*/ -package discord - -import ( - "os" - - "github.com/hugobyte/dive/cli/common" - "github.com/spf13/cobra" -) - -const diveURL = "https://discord.gg/GyRQSBN3Cu" - -// discordCmd redirects users to DIVE discord channel -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) { - diveContext.Log.SetOutput(os.Stdout) - common.ValidateCmdArgs(diveContext, 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 deleted file mode 100644 index c740bc8f..00000000 --- a/cli/commands/root.go +++ /dev/null @@ -1,59 +0,0 @@ -/* -Copyright © 2023 Hugobyte AI Labs -*/ -package commands - -import ( - "os" - - "github.com/hugobyte/dive/cli/commands/bridge" - "github.com/hugobyte/dive/cli/commands/chain" - "github.com/hugobyte/dive/cli/commands/clean" - "github.com/hugobyte/dive/cli/commands/discord" - "github.com/hugobyte/dive/cli/commands/tutorial" - "github.com/hugobyte/dive/cli/commands/twitter" - "github.com/hugobyte/dive/cli/commands/version" - "github.com/hugobyte/dive/cli/common" - - "github.com/hugobyte/dive/cli/styles" - "github.com/spf13/cobra" -) - -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 - rootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) - - rootCmd.AddCommand(chain.NewChainCmd(diveContext)) - rootCmd.AddCommand(bridge.NewBridgeCmd(diveContext)) - rootCmd.AddCommand(clean.NewCleanCmd(diveContext)) - rootCmd.AddCommand(version.NewVersionCmd(diveContext)) - rootCmd.AddCommand(discord.NewDiscordCmd(diveContext)) - rootCmd.AddCommand(twitter.NewtwitterCmd(diveContext)) - rootCmd.AddCommand(tutorial.NewTutorialCmd(diveContext)) - - rootCmd.PersistentFlags().BoolVar(&common.DiveLogs, "verbose", 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 deleted file mode 100644 index 04f463f4..00000000 --- a/cli/commands/tutorial/tutorial.go +++ /dev/null @@ -1,33 +0,0 @@ -/* -Copyright © 2023 Hugobyte AI Labs -*/ -package tutorial - -import ( - "os" - - "github.com/hugobyte/dive/cli/common" - "github.com/spf13/cobra" -) - -const tutorialURL = "https://www.youtube.com/playlist?list=PL5Xd9z-fRL1vKtRlOzIlkhROspSSDeGyG" - -// tutorilaCmd redirects users to DIVE youtube playlist -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) { - diveContext.Log.SetOutput(os.Stdout) - common.ValidateCmdArgs(diveContext, 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 deleted file mode 100644 index 13d3d7bd..00000000 --- a/cli/commands/twitter/twitter.go +++ /dev/null @@ -1,33 +0,0 @@ -/* -Copyright © 2023 Hugobyte AI Labs -*/ -package twitter - -import ( - "os" - - "github.com/hugobyte/dive/cli/common" - "github.com/spf13/cobra" -) - -const twitterURL = "https://twitter.com/hugobyte" - -// twitterCmd redirects users to twitter home page -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) { - diveContext.Log.SetOutput(os.Stdout) - common.ValidateCmdArgs(diveContext, 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 deleted file mode 100644 index d898fd6e..00000000 --- a/cli/commands/version/version.go +++ /dev/null @@ -1,35 +0,0 @@ -/* -Copyright © 2023 Hugobyte AI Labs -*/ -package version - -import ( - "fmt" - "os" - - "github.com/fatih/color" - "github.com/hugobyte/dive/cli/common" - "github.com/spf13/cobra" -) - -// versionCmd represents the version command -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(diveContext, 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) - - }, - } - -}