generated from kurtosis-tech/package-template-repo
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from HugoByte/DIVE-364-Refactor-Redundant-Code
feat: implement chain commands with dive context manager
- Loading branch information
Showing
38 changed files
with
1,344 additions
and
571 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package archway | ||
|
||
import ( | ||
"github.com/hugobyte/dive-core/cli/common" | ||
"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) { | ||
|
||
cliContext := common.GetCliWithKurtosisContext() | ||
|
||
err := common.ValidateArgs(args) | ||
if err != nil { | ||
cliContext.Fatalf("Error %s. %s", err, cmd.UsageString()) | ||
} | ||
|
||
cliContext.Spinner().StartWithMessage("Starting Archway Node", "green") | ||
|
||
response, err := RunArchway(cliContext) | ||
|
||
if err != nil { | ||
cliContext.Fatal(err) | ||
} | ||
|
||
err = common.WriteServiceResponseData(response.ServiceName, *response, cliContext) | ||
if err != nil { | ||
cliContext.Fatal(err) | ||
|
||
} | ||
|
||
cliContext.Spinner().StopWithMessage("Archway Node Started. Please find service details in current working directory(services.json)") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package archway | ||
|
||
import ( | ||
"github.com/hugobyte/dive-core/cli/cmd/chains/utils" | ||
"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, common.WrapMessageToError(err, "Archway Run Failed") | ||
} | ||
|
||
var serviceConfig = &utils.CosmosServiceConfig{} | ||
|
||
err = common.LoadConfig(cli, serviceConfig, configFilePath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
encodedServiceConfigDataString, err := serviceConfig.EncodeToString() | ||
|
||
if err != nil { | ||
return nil, common.WrapMessageToError(common.ErrDataMarshall, 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.WrapMessageToError(common.ErrStarlarkRunFailed, err.Error()) | ||
} | ||
|
||
responseData, services, skippedInstructions, err := common.GetSerializedData(cli, response) | ||
|
||
if err != nil { | ||
|
||
errRemove := cli.Context().RemoveServicesByServiceNames(services, common.DiveEnclave) | ||
if errRemove != nil { | ||
return nil, common.WrapMessageToError(errRemove, "Archway Run Failed ") | ||
} | ||
|
||
return nil, common.WrapMessageToError(err, "Archway Run Failed ") | ||
} | ||
|
||
if cli.Context().CheckSkippedInstructions(skippedInstructions) { | ||
return nil, common.WrapMessageToError(common.ErrStarlarkResponse, "Already Running") | ||
} | ||
|
||
archwayResponseData := &common.DiveServiceResponse{} | ||
result, err := archwayResponseData.Decode([]byte(responseData)) | ||
|
||
if err != nil { | ||
|
||
errRemove := cli.Context().RemoveServicesByServiceNames(services, common.DiveEnclave) | ||
if errRemove != nil { | ||
return nil, common.WrapMessageToError(errRemove, "Archway Run Failed ") | ||
} | ||
|
||
return nil, common.WrapMessageToErrorf(common.ErrDataUnMarshall, "%s.%s", err, "Archway Run Failed ") | ||
|
||
} | ||
|
||
return result, nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.