Skip to content

Commit

Permalink
add a reset command
Browse files Browse the repository at this point in the history
  • Loading branch information
likesToEatFish committed Sep 30, 2024
1 parent 3a2f656 commit fa09a75
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 19 additions & 5 deletions ignite/cmd/testnet_multi_node.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package ignitecmd

import (
"fmt"
"math/rand"
"os"
"path/filepath"
"strconv"
"time"

"cosmossdk.io/math"
tea "github.com/charmbracelet/bubbletea"
"github.com/spf13/cobra"

sdk "github.com/cosmos/cosmos-sdk/types"

tea "github.com/charmbracelet/bubbletea"

cmdmodel "github.com/ignite/cli/v29/ignite/cmd/model"
"github.com/ignite/cli/v29/ignite/config/chain/base"
"github.com/ignite/cli/v29/ignite/pkg/cliui"
Expand Down Expand Up @@ -61,6 +61,7 @@ func NewTestnetMultiNode() *cobra.Command {
c.Flags().AddFlagSet(flagSetCheckDependencies())
c.Flags().AddFlagSet(flagSetSkipProto())
c.Flags().AddFlagSet(flagSetVerbose())
c.Flags().BoolP(flagResetOnce, "r", false, "reset the app state once on init")

c.Flags().Bool(flagQuitOnFail, false, "quit program if the app fails to start")
return c
Expand Down Expand Up @@ -106,7 +107,12 @@ func testnetMultiNode(cmd *cobra.Command, session *cliui.Session) error {
if err != nil {
return err
}
outputDir := ".ignite/local-chains/" + c.Name() + "d/testnet/"
homeDir, err := os.UserHomeDir()
if err != nil {
return err
}

outputDir := filepath.Join(homeDir, ".ignite/local-chains/"+c.Name()+"d/testnet/")
args := chain.MultiNodeArgs{
ChainID: cfg.MultiNode.ChainID,
ValidatorsStakeAmount: amountDetails,
Expand All @@ -115,7 +121,15 @@ func testnetMultiNode(cmd *cobra.Command, session *cliui.Session) error {
NodeDirPrefix: cfg.MultiNode.NodeDirPrefix,
}

fmt.Printf("Creating %s nodes \n\n", args.NumValidator)
resetOnce, _ := cmd.Flags().GetBool(flagResetOnce)
if resetOnce {
// If resetOnce is true, the app state will be reset by deleting the output directory.
err := os.RemoveAll(outputDir)
if err != nil {
return err
}
}

err = c.TestnetMultiNode(cmd.Context(), args)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions ignite/services/chain/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type MultiNodeArgs struct {
NodeDirPrefix string
}

// If the app state still exists, TestnetMultiNode will reuse it.
// Otherwise, it will automatically re-initialize the app state from the beginning.
func (c Chain) TestnetMultiNode(ctx context.Context, args MultiNodeArgs) error {
commands, err := c.Commands(ctx)
if err != nil {
Expand Down

0 comments on commit fa09a75

Please sign in to comment.