Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 0 additions & 55 deletions cli/commands/chain/chain.go

This file was deleted.

68 changes: 68 additions & 0 deletions cli/commands/chain/chains.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
Copyright © 2023 Hugobyte AI Labs<hello@hugobyte.com>
*/
package chain

import (
"context"

"github.com/hugobyte/dive/commands/chain/types"
"github.com/hugobyte/dive/common"
"github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves"
"github.com/kurtosis-tech/kurtosis/api/golang/engine/lib/kurtosis_context"
"github.com/spf13/cobra"
)

// chainCmd represents the chain command

var ChainCmd = &cobra.Command{
Use: "chain",
Short: "runs specfied chain",
Long: ``,

Run: func(cmd *cobra.Command, args []string) {
cmd.Help()

},
}

func init() {

ctx := context.Background()

kurtosisContext, err := kurtosis_context.NewKurtosisContextFromLocalEngine()
if err != nil {
panic(err)

}

enclaveCtx, err := getEnclaveContext(ctx, common.DiveEnclave, kurtosisContext)
if err != nil {
panic(err)

}

ChainCmd.AddCommand(types.NewIconCmd(ctx, enclaveCtx))
ChainCmd.AddCommand(types.NewEthCmd(ctx, enclaveCtx))
ChainCmd.AddCommand(types.NewHardhatCmd(ctx, enclaveCtx))

}

func getEnclaveContext(ctx context.Context, identifier string, kurtosisContext *kurtosis_context.KurtosisContext) (*enclaves.EnclaveContext, error) {

_, err := kurtosisContext.GetEnclave(ctx, common.DiveEnclave)
if err != nil {
enclaveCtx, err := kurtosisContext.CreateEnclave(ctx, identifier, false)
if err != nil {
return nil, err

}
return enclaveCtx, nil
}
enclaveCtx, err := kurtosisContext.GetEnclaveContext(ctx, identifier)

if err != nil {
return nil, err
}
return enclaveCtx, nil
}
49 changes: 49 additions & 0 deletions cli/commands/chain/types/eth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package types

import (
"context"
"fmt"

"github.com/hugobyte/dive/common"
"github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings"
"github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves"
"github.com/spf13/cobra"
)

func NewEthCmd(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *cobra.Command {

var ethCmd = &cobra.Command{
Use: "eth",
Short: "Runs Eth Node",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {

fmt.Println(runEthNode(ctx, kurtosisEnclaveContext).EncodeToString())
},
}

return ethCmd

}

func runEthNode(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *common.DiveserviceResponse {

data, _, err := kurtosisEnclaveContext.RunStarlarkPackage(ctx, "../", "services/evm/eth/eth.star", "start_eth_node_serivce", `{"args":{},"node_type":"eth"}`, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{})

if err != nil {
fmt.Println(err)
}

responseData := common.GetSerializedData(data)

ethResponseData := &common.DiveserviceResponse{}

result, err := ethResponseData.Decode([]byte(responseData))

if err != nil {
fmt.Println(err)
}

return result

}
49 changes: 49 additions & 0 deletions cli/commands/chain/types/hardhat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package types

import (
"context"
"fmt"

"github.com/hugobyte/dive/common"
"github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings"
"github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves"
"github.com/spf13/cobra"
)

func NewHardhatCmd(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *cobra.Command {

var ethCmd = &cobra.Command{
Use: "hardhat",
Short: "Runs Hardhat Node",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {

fmt.Println(runHardhatNode(ctx, kurtosisEnclaveContext).EncodeToString())
},
}

return ethCmd

}

func runHardhatNode(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *common.DiveserviceResponse {

data, _, err := kurtosisEnclaveContext.RunStarlarkPackage(ctx, "../", "services/evm/eth/eth.star", "start_eth_node_serivce", `{"args":{},"node_type":"hardhat"}`, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{})

if err != nil {
fmt.Println(err)
}

responseData := common.GetSerializedData(data)

ethResponseData := &common.DiveserviceResponse{}

result, err := ethResponseData.Decode([]byte(responseData))

if err != nil {
fmt.Println(err)
}

return result

}
Loading