Skip to content

Commit

Permalink
feat: update archway command
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyasbhat0 committed Dec 6, 2023
1 parent 687b529 commit 17f7730
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 21 deletions.
40 changes: 39 additions & 1 deletion cli/cmd/chains/chain/archway/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,49 @@ import (
"github.com/spf13/cobra"
)

var (
configFilePath string
)

const (
constructServiceConfigFunctionName = "get_service_config"
runArchwayNodeWithCustomServiceFunctionName = "start_cosmos_node"
runArchwayNodeWithDefaultConfigFunctionName = "start_node_service"
)

var ArchwayCmd = common.NewDiveCommandBuilder().
SetUse("archway").
SetShort("Build, initialize and start a archway node").
SetLong("The command starts the archway network and allows node in executing contracts").
SetRun(archway).
AddStringFlagWithShortHand(&configFilePath, "config", "c", "", "path to custom config json file to start archway node ").
Build()

func archway(cmd *cobra.Command, args []string) {}
func archway(cmd *cobra.Command, args []string) {

cliContext := common.GetCliWithKurtosisContext()

err := common.ValidateArgs(args)
if err != nil {
cliContext.Logger().Fatal(common.CodeOf(err), err.Error())
}

cliContext.Spinner().StartWithMessage("Starting Archway Node", "green")

response, err := RunArchway(cliContext)

if err != nil {
cliContext.Logger().Fatal(common.CodeOf(err), err.Error())
}

err = common.WriteServiceResponseData(response.ServiceName, *response, cliContext)
if err != nil {
cliContext.Spinner().Stop()
cliContext.Logger().SetErrorToStderr()
cliContext.Logger().Error(common.CodeOf(err), err.Error())

}

cliContext.Spinner().StopWithMessage("Archway Node Started. Please find service details in current working directory(services.json)")

}
58 changes: 58 additions & 0 deletions cli/cmd/chains/chain/archway/run.go
Original file line number Diff line number Diff line change
@@ -1 +1,59 @@
package archway

import "github.com/hugobyte/dive-core/cli/common"

func RunArchway(cli *common.Cli) (*common.DiveServiceResponse, error) {

enclaveContext, err := cli.Context().GetEnclaveContext(common.DiveEnclave)

if err != nil {
return nil, err
}

var serviceConfig = &ArchwayServiceConfig{}

err = common.LoadConfig(cli, serviceConfig, configFilePath)
if err != nil {
return nil, err
}

encodedServiceConfigDataString, err := serviceConfig.EncodeToString()

if err != nil {
return nil, common.Errorc(common.InvalidEnclaveConfigError, err.Error())
}

runConfig := common.GetStarlarkRunConfig(encodedServiceConfigDataString, common.DiveArchwayDefaultNodeScript, runArchwayNodeWithDefaultConfigFunctionName)

response, _, err := enclaveContext.RunStarlarkRemotePackage(cli.Context().GetContext(), common.DiveRemotePackagePath, runConfig)

if err != nil {
return nil, common.Errorc(common.FileError, err.Error())
}

responseData, services, skippedInstructions, err := common.GetSerializedData(cli, response)

if err != nil {

err = cli.Context().RemoveServicesByServiceNames(services, common.DiveEnclave)
if err != nil {
return nil, common.Errorc(common.InvalidEnclaveContextError, err.Error())
}

return nil, common.Errorc(common.KurtosisContextError, err.Error())
}

if cli.Context().CheckSkippedInstructions(skippedInstructions) {
return nil, common.Errorc(common.KurtosisContextError, "Already Running")
}

archwayResponseData := &common.DiveServiceResponse{}
result, err := archwayResponseData.Decode([]byte(responseData))

if err != nil {

return nil, common.Errorc(common.KurtosisContextError, err.Error())
}

return result, nil
}
46 changes: 46 additions & 0 deletions cli/cmd/chains/chain/archway/types.go
Original file line number Diff line number Diff line change
@@ -1 +1,47 @@
package archway

import (
"encoding/json"

"github.com/hugobyte/dive-core/cli/common"
)

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) LoadDefaultConfig() {
as.Cid = nil
as.Key = nil
as.Password = nil
as.PublicGrpcPort = nil
as.PublicHttpPort = nil
as.PublicRpcPort = nil
as.PublicTcpPort = nil
as.Password = nil
}

func (as *ArchwayServiceConfig) EncodeToString() (string, error) {

data, err := json.Marshal(as)
if err != nil {
return "", err
}

return string(data), nil
}

func (as *ArchwayServiceConfig) LoadConfigFromFile(cliContext *common.Cli, filePath string) error {

err := cliContext.FileHandler().ReadJson(filePath, as)
if err != nil {
return err
}
return nil
}
2 changes: 1 addition & 1 deletion cli/cmd/chains/chain/icon/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func RunIconNode(cli *common.Cli) (*common.DiveServiceResponse, error) {
return nil, err
}
var serviceConfig = &IconServiceConfig{}
err = LoadConfig(cli, serviceConfig, configFilePath)
err = common.LoadConfig(cli, serviceConfig, configFilePath)
if err != nil {
return nil, err
}
Expand Down
7 changes: 1 addition & 6 deletions cli/cmd/chains/chain/icon/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ import (
"github.com/hugobyte/dive-core/cli/common"
)

type ConfigLoader interface {
LoadDefaultConfig()
LoadConfigFromFile(cliContext *common.Cli, filePath string) error
}

type IconServiceConfig struct {
Port int `json:"private_port"`
PublicPort int `json:"public_port"`
Expand Down Expand Up @@ -38,7 +33,7 @@ func (sc *IconServiceConfig) EncodeToString() (string, error) {
}

func (sc *IconServiceConfig) LoadConfigFromFile(cliContext *common.Cli, filePath string) error {
err := cliContext.FileHandler().ReadJson(configFilePath, sc)
err := cliContext.FileHandler().ReadJson(filePath, sc)
if err != nil {
return err
}
Expand Down
13 changes: 0 additions & 13 deletions cli/cmd/chains/chain/icon/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"path/filepath"

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

Expand Down Expand Up @@ -37,18 +36,6 @@ func genesismanager(enclaveContext *enclaves.EnclaveContext) (*genesisHandler, e
return &gm, nil
}

func LoadConfig(cliContext *common.Cli, config ConfigLoader, filePath string) error {
if filePath == "" {
config.LoadDefaultConfig()
} else {
err := config.LoadConfigFromFile(cliContext, filePath)
if err != nil {
return err
}
}
return nil
}

func GetDecentralizeParams(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)
}
5 changes: 5 additions & 0 deletions cli/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ type EnclaveInfo struct {
Uuid string
ShortUuid string
}

type ConfigLoader interface {
LoadDefaultConfig()
LoadConfigFromFile(cliContext *Cli, filePath string) error
}
12 changes: 12 additions & 0 deletions cli/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,15 @@ func OpenFile(URL string) error {
}
return nil
}

func LoadConfig(cliContext *Cli, config ConfigLoader, filePath string) error {
if filePath == "" {
config.LoadDefaultConfig()
} else {
err := config.LoadConfigFromFile(cliContext, filePath)
if err != nil {
return err
}
}
return nil
}

0 comments on commit 17f7730

Please sign in to comment.