diff --git a/.gitignore b/.gitignore index 7bdd3ecd..a73c0cd2 100644 --- a/.gitignore +++ b/.gitignore @@ -92,3 +92,5 @@ tsconfig.tsbuildinfo # Generated files .docusaurus .cache-loader + +dist/ \ No newline at end of file diff --git a/cli/.goreleaser.yaml b/cli/.goreleaser.yaml new file mode 100644 index 00000000..a65edfee --- /dev/null +++ b/cli/.goreleaser.yaml @@ -0,0 +1,45 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + # you may remove this if you don't need go generate + - go generate ./... +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of uname. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + +# The lines beneath this are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj diff --git a/cli/commands/bridge/bridge.go b/cli/commands/bridge/bridge.go index 2a91a93d..5a786ec1 100644 --- a/cli/commands/bridge/bridge.go +++ b/cli/commands/bridge/bridge.go @@ -10,9 +10,12 @@ 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" ) +const bridgeMainFunction = "run_btp_setup" + var ( chainA string chainB string @@ -38,14 +41,14 @@ func btpBridgeCmd(diveContext *common.DiveContext) *cobra.Command { var btpbridgeCmd = &cobra.Command{ Use: "btp", - Short: "", - Long: `.`, + Short: "Starts Bridge BTP between ChainA and Chain B", + Long: ``, Run: func(cmd *cobra.Command, args []string) { enclaveCtx, err := diveContext.GetEnclaveContext() - if err != nil { - panic(err) + if err != nil { + logrus.Errorln(err) } bridge, _ := cmd.Flags().GetBool("bridge") @@ -54,7 +57,7 @@ func btpBridgeCmd(diveContext *common.DiveContext) *cobra.Command { if strings.ToLower(chainA) == "icon" && strings.ToLower(chainB) == "icon" { - data, _, err := enclaveCtx.RunStarlarkPackage(diveContext.Ctx, "../", "main.star", "run_btp_setup", params, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) + 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) @@ -63,7 +66,7 @@ func btpBridgeCmd(diveContext *common.DiveContext) *cobra.Command { common.WriteToFile(response) } else { - data, _, err := enclaveCtx.RunStarlarkPackage(diveContext.Ctx, "../", "main.star", "run_btp_setup", params, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) + data, _, err := enclaveCtx.RunStarlarkPackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveBridgeScript, bridgeMainFunction, params, common.DiveDryRun, common.DiveDefaultParallelism, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) if err != nil { fmt.Println(err) @@ -75,9 +78,9 @@ func btpBridgeCmd(diveContext *common.DiveContext) *cobra.Command { }, } - btpbridgeCmd.Flags().StringVar(&chainA, "chainA", "", "specify chain A") - btpbridgeCmd.Flags().StringVar(&chainB, "chainB", "", "specify chain B") - btpbridgeCmd.Flags().Bool("bridge", false, "sepcify bridge falg") + btpbridgeCmd.Flags().StringVar(&chainA, "chainA", "", "Metion Name of Supported Chain") + btpbridgeCmd.Flags().StringVar(&chainB, "chainB", "", "Metion Name of Supported Chain") + btpbridgeCmd.Flags().Bool("bridge", false, "Mention Bridge ENV") btpbridgeCmd.MarkFlagRequired("chainA") btpbridgeCmd.MarkFlagRequired("chainB") diff --git a/cli/commands/chain/chains.go b/cli/commands/chain/chains.go index 95cccd94..aeda3556 100644 --- a/cli/commands/chain/chains.go +++ b/cli/commands/chain/chains.go @@ -16,23 +16,17 @@ func NewChainCmd(diveContext *common.DiveContext) *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.`, + 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) { cmd.Help() }, } - enclaveCtx, err := diveContext.GetEnclaveContext() - if err != nil { - panic(err) - - } - - chainCmd.AddCommand(types.NewIconCmd(diveContext.Ctx, enclaveCtx)) - chainCmd.AddCommand(types.NewEthCmd(diveContext.Ctx, enclaveCtx)) - chainCmd.AddCommand(types.NewHardhatCmd(diveContext.Ctx, enclaveCtx)) + chainCmd.AddCommand(types.NewIconCmd(diveContext)) + chainCmd.AddCommand(types.NewEthCmd(diveContext)) + chainCmd.AddCommand(types.NewHardhatCmd(diveContext)) return chainCmd diff --git a/cli/commands/chain/types/eth.go b/cli/commands/chain/types/eth.go index 131a973b..e2ae4e10 100644 --- a/cli/commands/chain/types/eth.go +++ b/cli/commands/chain/types/eth.go @@ -1,16 +1,12 @@ package types import ( - "context" - "fmt" - "github.com/hugobyte/dive/common" "github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings" - "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" "github.com/spf13/cobra" ) -func NewEthCmd(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *cobra.Command { +func NewEthCmd(diveContext *common.DiveContext) *cobra.Command { var ethCmd = &cobra.Command{ Use: "eth", @@ -19,7 +15,12 @@ func NewEthCmd(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveCont network and allows the node in executing smart contracts and maintaining the decentralized ledger.`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println(RunEthNode(ctx, kurtosisEnclaveContext).EncodeToString()) + data, err := RunEthNode(diveContext) + + if err != nil { + diveContext.FatalError("Fail to Start ETH Node", err.Error()) + } + data.WriteDiveResponse(diveContext) }, } @@ -27,12 +28,18 @@ network and allows the node in executing smart contracts and maintaining the dec } -func RunEthNode(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *common.DiveserviceResponse { +func RunEthNode(diveContext *common.DiveContext) (*common.DiveserviceResponse, error) { + + kurtosisEnclaveContext, err := diveContext.GetEnclaveContext() + + if err != nil { + return nil, err + } - data, _, err := kurtosisEnclaveContext.RunStarlarkPackage(ctx, "../", "services/evm/eth/eth.star", "start_eth_node_serivce", `{"args":{},"node_type":"eth"}`, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) + 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 { - fmt.Println(err) + return nil, err } responseData := common.GetSerializedData(data) @@ -42,9 +49,9 @@ func RunEthNode(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveCon result, err := ethResponseData.Decode([]byte(responseData)) if err != nil { - fmt.Println(err) + return nil, err } - return result + return result, nil } diff --git a/cli/commands/chain/types/hardhat.go b/cli/commands/chain/types/hardhat.go index 65af0a9d..454ec46d 100644 --- a/cli/commands/chain/types/hardhat.go +++ b/cli/commands/chain/types/hardhat.go @@ -1,25 +1,27 @@ package types import ( - "context" - "fmt" - "github.com/hugobyte/dive/common" "github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings" - "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" "github.com/spf13/cobra" ) -func NewHardhatCmd(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *cobra.Command { +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 + 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) { - fmt.Println(RunHardhatNode(ctx, kurtosisEnclaveContext).EncodeToString()) + data, err := RunHardhatNode(diveContext) + + if err != nil { + diveContext.FatalError("Fail to Start Hardhat Node", err.Error()) + } + + data.WriteDiveResponse(diveContext) }, } @@ -27,24 +29,30 @@ network and allows the node in executing smart contracts and maintaining the dec } -func RunHardhatNode(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *common.DiveserviceResponse { +func RunHardhatNode(diveContext *common.DiveContext) (*common.DiveserviceResponse, error) { + + kurtosisEnclaveContext, err := diveContext.GetEnclaveContext() + + if err != nil { + return nil, err + } - data, _, err := kurtosisEnclaveContext.RunStarlarkPackage(ctx, "../", "services/evm/eth/eth.star", "start_eth_node_serivce", `{"args":{},"node_type":"hardhat"}`, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) + 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 { - fmt.Println(err) + return nil, err } responseData := common.GetSerializedData(data) - ethResponseData := &common.DiveserviceResponse{} + hardhatResponseData := &common.DiveserviceResponse{} - result, err := ethResponseData.Decode([]byte(responseData)) + result, err := hardhatResponseData.Decode([]byte(responseData)) if err != nil { - fmt.Println(err) + return nil, err } - return result + return result, nil } diff --git a/cli/commands/chain/types/icon.go b/cli/commands/chain/types/icon.go index 3009a6de..93a47a3d 100644 --- a/cli/commands/chain/types/icon.go +++ b/cli/commands/chain/types/icon.go @@ -1,18 +1,18 @@ package types import ( - "context" "encoding/json" "fmt" "path/filepath" "github.com/hugobyte/dive/common" "github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings" - "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) +const genesisIcon = "github.com/hugobyte/dive/services/jvm/icon/static-files/config/genesis-icon-0.zip" + var ( id = "" genesis = "" @@ -64,7 +64,7 @@ func (sc *IconServiceConfig) EncodeToString() (string, error) { return string(encodedBytes), nil } -func NewIconCmd(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *cobra.Command { +func NewIconCmd(diveContext *common.DiveContext) *cobra.Command { var iconCmd = &cobra.Command{ Use: "icon", Short: "Build, initialize and start a icon node.", @@ -94,17 +94,31 @@ network and allows the node in executing smart contracts and maintaining the dec if decentralisation { - data := RunIconNode(ctx, kurtosisEnclaveContext, serviceConfig, genesis) + nodeResponse, err := RunIconNode(diveContext, serviceConfig, genesis) + if err != nil { + diveContext.FatalError("Run Icon Node Failed", err.Error()) + } + + params := GetDecentralizeParms(nodeResponse.ServiceName, nodeResponse.PrivateEndpoint, nodeResponse.KeystorePath, nodeResponse.KeyPassword, nodeResponse.NetworkId) - params := GetDecentralizeParms(data.ServiceName, data.PrivateEndpoint, data.KeystorePath, data.KeyPassword, data.NetworkId) + response, err := Decentralisation(diveContext, params) - Decentralisation(ctx, kurtosisEnclaveContext, params) + if err != nil { + diveContext.FatalError("Icon Node Decentralisation Failed", err.Error()) + } + + diveContext.Info(response) + + nodeResponse.WriteDiveResponse(diveContext) } else { - data := RunIconNode(ctx, kurtosisEnclaveContext, serviceConfig, genesis) + data, err := RunIconNode(diveContext, serviceConfig, genesis) + if err != nil { + diveContext.FatalError("Run Icon Node Failed", err.Error()) + } - fmt.Println(data.EncodeToString()) + data.WriteDiveResponse(diveContext) } @@ -116,26 +130,30 @@ network and allows the node in executing smart contracts and maintaining the dec iconCmd.Flags().StringVarP(&configFilePath, "config", "c", "", "gen file") iconCmd.Flags().BoolP("decentralisation", "d", false, "Decentralise Icon Node") - decentralisationCmd := IconDecentralisationCmd(ctx, kurtosisEnclaveContext) + decentralisationCmd := IconDecentralisationCmd(diveContext) iconCmd.AddCommand(decentralisationCmd) return iconCmd } -func IconDecentralisationCmd(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *cobra.Command { +func IconDecentralisationCmd(diveContext *common.DiveContext) *cobra.Command { var decentralisationCmd = &cobra.Command{ Use: "decentralize", Short: "Decentralise already running Icon Node", Long: `Decentralise Icon Node is necessary if you want to connect your local icon node to BTP network`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("Decentralisation") params := GetDecentralizeParms(serviceName, nodeEndpoint, keystorePath, keystorepassword, networkID) - Decentralisation(ctx, kurtosisEnclaveContext, params) + response, err := Decentralisation(diveContext, params) + + if err != nil { + diveContext.FatalError("Icon Node Decentralisation Failed", err.Error()) + } + diveContext.Info(response) }, } decentralisationCmd.Flags().StringVarP(&serviceName, "serviceName", "s", "", "service name") @@ -154,36 +172,51 @@ func IconDecentralisationCmd(ctx context.Context, kurtosisEnclaveContext *enclav } -func RunIconNode(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext, serviceConfig *IconServiceConfig, genesisFilePath string) *common.DiveserviceResponse { +func RunIconNode(diveContext *common.DiveContext, serviceConfig *IconServiceConfig, genesisFilePath string) (*common.DiveserviceResponse, error) { paramData, err := serviceConfig.EncodeToString() if err != nil { - logrus.Fatalln(err) + return nil, err } - data, _, err := kurtosisEnclaveContext.RunStarlarkPackage(ctx, "../", "services/jvm/icon/src/node-setup/start_icon_node.star", "get_service_config", paramData, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) + kurtosisEnclaveContext, err := diveContext.GetEnclaveContext() if err != nil { - fmt.Println(err) + return nil, err } - responseData := common.GetSerializedData(data) - - genesis_file_name := filepath.Base(genesisFilePath) - r, d, err := kurtosisEnclaveContext.UploadFiles(genesisFilePath, genesis_file_name) + 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 { - panic(err) + return nil, err } - logrus.Infof("File Uploaded sucessfully : UUID %s", r) - uploadedFiles := fmt.Sprintf(`{"file_path":"%s","file_name":"%s"}`, d, genesis_file_name) + responseData := common.GetSerializedData(data) + var genesisFile = "" + var uploadedFiles = "" + var genesisPath = "" + + if genesisFilePath != "" { + genesisFileName := filepath.Base(genesisFilePath) + r, d, err := kurtosisEnclaveContext.UploadFiles(genesisFilePath, genesisFileName) + logrus.Infof("File Uploaded sucessfully : UUID %s", r) + uploadedFiles = fmt.Sprintf(`{"file_path":"%s","file_name":"%s"}`, d, genesisFileName) + + if err != nil { + return nil, err + } + } else { + genesisFile = filepath.Base(genesisIcon) + genesisPath = genesisIcon + uploadedFiles = `{}` + + } - params := fmt.Sprintf(`{"service_config":%s,"id":"%s","uploaded_genesis":%s,"genesis_file_path":"%s","genesis_file_name":"%s"}`, responseData, serviceConfig.Id, uploadedFiles, "", "") - icon_data, _, err := kurtosisEnclaveContext.RunStarlarkPackage(ctx, "../", "services/jvm/icon/src/node-setup/start_icon_node.star", "start_icon_node", params, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) + 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) + 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 { - fmt.Println(err) + return nil, err } response := common.GetSerializedData(icon_data) @@ -193,22 +226,29 @@ func RunIconNode(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveCo result, err := iconResponseData.Decode([]byte(response)) if err != nil { - fmt.Println(err) + return nil, err } - return result + return result, nil } -func Decentralisation(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext, params string) { - data, _, err := kurtosisEnclaveContext.RunStarlarkPackage(ctx, "../", "services/jvm/icon/src/node-setup/setup_icon_node.star", "configure_node", params, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) +func Decentralisation(diveContext *common.DiveContext, params string) (string, error) { + + kurtosisEnclaveContext, err := diveContext.GetEnclaveContext() + + if err != nil { + return "", err + } + + data, _, err := kurtosisEnclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveIconDecentraliseScript, "configure_node", params, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) if err != nil { - fmt.Println(err) + return "", err } response := common.GetSerializedData(data) - fmt.Println(response) + return response, nil } diff --git a/cli/commands/clean/clean.go b/cli/commands/clean/clean.go index 9a69ef0b..744c05b8 100644 --- a/cli/commands/clean/clean.go +++ b/cli/commands/clean/clean.go @@ -4,60 +4,28 @@ Copyright © 2023 Hugobyte AI Labs package clean import ( - "context" - - "github.com/kurtosis-tech/kurtosis/api/golang/engine/lib/kurtosis_context" + "github.com/hugobyte/dive/common" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) -// cleanCmd represents the clean command -var CleanCmd = &cobra.Command{ - Use: "clean", - Short: "Cleans up Kurtosis leftover artifacts", - Long: `Destroys and removes any running encalves. If no enclaves are running to remove it will throw an error`, - Run: func(cmd *cobra.Command, args []string) { - ctx := context.Background() - kurtosisCtx, err := kurtosis_context.NewKurtosisContextFromLocalEngine() - logrus.Info("Trying to connect to local Kurtosis Engine...") - if err != nil { - logrus.Errorf("Connecting to kurtosis engine failed as kurtosis engine is not running") - } - enclaveName := getEnclaves(ctx, kurtosisCtx) - if enclaveName == "" { - logrus.Errorf("No enclaves running to clean !!") - } else { - clean(ctx, kurtosisCtx) - } - }, -} +func NewCleanCmd(diveContext *common.DiveContext) *cobra.Command { -// To get names of running enclaves, returns empty string if no enclaves -func getEnclaves(ctx context.Context, kurtosisCtx *kurtosis_context.KurtosisContext) string { - enclaves, err := kurtosisCtx.GetEnclaves(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 "" -} - -// Funstionality to clean the enclaves -func clean(ctx context.Context, kurtosisCtx *kurtosis_context.KurtosisContext) { - logrus.Info("Successfully connected to kurtosis engine...") - logrus.Info("Initializing cleaning process...") + 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) { - // shouldCleanAll set to true as default for beta release. - enclaves, err := kurtosisCtx.Clean(ctx, true) - if err != nil { - logrus.Errorf("Failed cleaning with error: %v", err) + enclaveName := diveContext.GetEnclaves() + if enclaveName == "" { + logrus.Errorf("No enclaves running to clean !!") + } else { + diveContext.Clean() + } + }, } - // Assuming only one enclave is running for beta release - logrus.Infof("Successfully destroyed and cleaned enclave %s", enclaves[0].Name) + return cleanCmd + } diff --git a/cli/commands/root.go b/cli/commands/root.go index a5b1f026..0fc7909c 100644 --- a/cli/commands/root.go +++ b/cli/commands/root.go @@ -45,11 +45,12 @@ func init() { rootCmd.CompletionOptions.DisableDefaultCmd = true rootCmd.CompletionOptions.DisableNoDescFlag = true + rootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) - rootCmd.AddCommand(version.VersionCmd) rootCmd.AddCommand(chain.NewChainCmd(diveContext)) rootCmd.AddCommand(bridge.NewBridgeCmd(diveContext)) - rootCmd.AddCommand(clean.CleanCmd) + rootCmd.AddCommand(clean.NewCleanCmd(diveContext)) + rootCmd.AddCommand(version.VersionCmd) rootCmd.AddCommand(discord.DiscordCmd) rootCmd.AddCommand(twitter.TwitterCmd) rootCmd.AddCommand(tutorial.TutorialCmd) diff --git a/cli/common/constants.go b/cli/common/constants.go index 0a1ef040..b6d0c1bc 100644 --- a/cli/common/constants.go +++ b/cli/common/constants.go @@ -1,9 +1,26 @@ package common const ( - DiveEnclave = "dive" - DiveRemotePackagePath = "github.com/hugobyte/dive" - DiveLocalPackagePath = "../" + 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 +) + +const ( + linuxOSName = "linux" + macOSName = "darwin" + windowsOSName = "windows" + + openFileLinuxCommandName = "xdg-open" + openFileMacCommandName = "open" + openFileWindowsCommandName = "rundll32" + + openFileWindowsCommandFirstArgumentDefault = "url.dll,FileProtocolHandler" ) const ( diff --git a/cli/common/types.go b/cli/common/types.go index a2b0f1f0..6863bc4a 100644 --- a/cli/common/types.go +++ b/cli/common/types.go @@ -16,18 +16,6 @@ import ( "github.com/sirupsen/logrus" ) -const ( - linuxOSName = "linux" - macOSName = "darwin" - windowsOSName = "windows" - - openFileLinuxCommandName = "xdg-open" - openFileMacCommandName = "open" - openFileWindowsCommandName = "rundll32" - - openFileWindowsCommandFirstArgumentDefault = "url.dll,FileProtocolHandler" -) - type DiveserviceResponse struct { ServiceName string `json:"service_name"` PublicEndpoint string `json:"endpoint_public"` @@ -55,21 +43,34 @@ func (dive *DiveserviceResponse) EncodeToString() (string, error) { return string(encodedBytes), nil } +func (dive *DiveserviceResponse) WriteDiveResponse(diveContext *DiveContext) { + + serialisedData, err := dive.EncodeToString() + + if err != nil { + diveContext.FatalError("Failed To Serialzed Data", err.Error()) + } + + WriteToFile(serialisedData) +} func GetSerializedData(response chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine) string { var serializedOutputObj string + for executionResponseLine := range response { - fmt.Println(executionResponseLine) + runFinishedEvent := executionResponseLine.GetRunFinishedEvent() + if runFinishedEvent == nil { - logrus.Info("Execution in progress...") + } else { - logrus.Info("Execution finished successfully") + if runFinishedEvent.GetIsRunSuccessful() { + serializedOutputObj = runFinishedEvent.GetSerializedOutput() } else { - panic("Starlark run failed") + logrus.Fatal("Starlark run Fails") } } } @@ -119,6 +120,7 @@ func GetLatestVersion() string { type DiveContext struct { Ctx context.Context KurtosisContext *kurtosis_context.KurtosisContext + log *logrus.Logger } func NewDiveContext() *DiveContext { @@ -127,10 +129,15 @@ func NewDiveContext() *DiveContext { kurtosisContext, err := kurtosis_context.NewKurtosisContextFromLocalEngine() if err != nil { - panic(err) + logrus.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") } - return &DiveContext{Ctx: ctx, KurtosisContext: kurtosisContext} + log := logrus.New() + log.SetFormatter(&logrus.TextFormatter{ + FullTimestamp: true, + TimestampFormat: "2006-01-02 15:04:05", + }) + return &DiveContext{Ctx: ctx, KurtosisContext: kurtosisContext, log: logrus.New()} } func (diveContext *DiveContext) GetEnclaveContext() (*enclaves.EnclaveContext, error) { @@ -163,7 +170,7 @@ func ReadConfigFile(filePath string) ([]byte, error) { return file, nil } func WriteToFile(data string) { - file, err := os.Create("bridge.json") + file, err := os.Create("dive.json") if err != nil { return } @@ -171,3 +178,43 @@ func WriteToFile(data string) { file.WriteString(data) } + +// 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 "" +} + +// Funstionality to clean the enclaves +func (diveContext *DiveContext) Clean() { + logrus.Info("Successfully connected to kurtosis engine...") + logrus.Info("Initializing cleaning process...") + + // shouldCleanAll set to true as default for beta release. + enclaves, err := diveContext.KurtosisContext.Clean(diveContext.Ctx, true) + if err != nil { + logrus.Errorf("Failed cleaning with error: %v", err) + } + + // Assuming only one enclave is running for beta release + logrus.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.Info(message) +} diff --git a/cli/config.json b/cli/config.json deleted file mode 100644 index 2dafeae7..00000000 --- a/cli/config.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "id": "0", - "private_port": 9080, - "public_port": 8090, - "p2p_listen_address": "7080", - "p2p_address": "8080", - "cid": "0xacbc4e" -} \ No newline at end of file diff --git a/cli/dive b/cli/dive deleted file mode 100755 index 7237617d..00000000 Binary files a/cli/dive and /dev/null differ diff --git a/cli/go.mod b/cli/go.mod index bdad2c1c..b196116c 100644 --- a/cli/go.mod +++ b/cli/go.mod @@ -6,13 +6,13 @@ require ( 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/stacktrace v0.0.0-20211028211901-1c67a77b5409 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.7.0 ) require ( github.com/Masterminds/semver/v3 v3.1.1 // indirect - github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect github.com/dsnet/compress v0.0.1 // indirect github.com/go-yaml/yaml v2.1.0+incompatible // indirect github.com/golang/protobuf v1.5.3 // indirect @@ -22,7 +22,6 @@ require ( 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/grpc-file-transfer/golang v0.0.0-20230427135111-ee2492059d06 // indirect - github.com/kurtosis-tech/stacktrace v0.0.0-20211028211901-1c67a77b5409 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.17 // indirect github.com/mholt/archiver v3.1.1+incompatible // indirect @@ -32,7 +31,7 @@ require ( 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/sys v0.6.0 // indirect + golang.org/x/sys 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 diff --git a/cli/go.sum b/cli/go.sum index ce33349d..dd6a48f2 100644 --- a/cli/go.sum +++ b/cli/go.sum @@ -6,10 +6,6 @@ github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0 github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= @@ -146,7 +142,6 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -155,8 +150,8 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= diff --git a/services/evm/eth/eth.star b/services/evm/eth/eth.star index 23618692..bd482f02 100644 --- a/services/evm/eth/eth.star +++ b/services/evm/eth/eth.star @@ -10,8 +10,8 @@ def start_eth_node_serivce(plan,args,node_type): "nid" : node_service_data.nid, "network" : node_service_data.network, "network_name": node_service_data.network_name, - "endpoint": "http://%s" % node_service_data.endpoint , - "endpoint_public": "http://%s" % node_service_data.endpoint_public , + "endpoint": node_service_data.endpoint , + "endpoint_public": node_service_data.endpoint_public , "keystore_path" : node_service_data.keystore_path, "keypassword": node_service_data.keypassword } diff --git a/services/evm/eth/src/node-setup/start-eth-node.star b/services/evm/eth/src/node-setup/start-eth-node.star index a4127aae..15c09f7e 100644 --- a/services/evm/eth/src/node-setup/start-eth-node.star +++ b/services/evm/eth/src/node-setup/start-eth-node.star @@ -12,8 +12,8 @@ def start_eth_node(plan,args): network_name= eth_contstants.network_name, network = eth_contstants.network, nid = eth_contstants.nid, - endpoint = network_address, - endpoint_public = "", + endpoint = "http://%s" % network_address, + endpoint_public = "http://", keystore_path = eth_contstants.keystore_path, keypassword = eth_contstants.keypassword ) @@ -64,8 +64,8 @@ def start_hardhat_node(plan): network_name= "hardhat", network = hardhat_constants.network, nid = hardhat_constants.network_id, - endpoint = private_url, - endpoint_public = public_url, + endpoint = "http://%s" % private_url, + endpoint_public = "http://%s" % public_url, keystore_path = hardhat_constants.keystore_path, keypassword = hardhat_constants.keypassword ) \ No newline at end of file