8000 feat(cmd/network): the `chain prepare [id]` should fail if not-launched yet by Pantani · Pull Request #2107 · ignite/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(cmd/network): the chain prepare [id] should fail if not-launched yet #2107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 22, 2022
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
13 changes: 13 additions & 0 deletions starport/cmd/network_chain_prepare.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package starportcmd

import (
"fmt"

"github.com/spf13/cobra"

"github.com/tendermint/starport/starport/services/network"
"github.com/tendermint/starport/starport/services/network/networkchain"
)

const (
flagForce = "force"
)

// NewNetworkChainPrepare returns a new command to prepare the chain for launch
func NewNetworkChainPrepare() *cobra.Command {
c := &cobra.Command{
Expand All @@ -16,6 +22,7 @@ func NewNetworkChainPrepare() *cobra.Command {
RunE: networkChainPrepareHandler,
}

c.Flags().BoolP(flagForce, "f", false, "Force the prepare command to run even if the chain is not launched")
c.Flags().AddFlagSet(flagNetworkFrom())
c.Flags().AddFlagSet(flagSetKeyringBackend())
c.Flags().AddFlagSet(flagSetHome())
Expand All @@ -24,6 +31,8 @@ func NewNetworkChainPrepare() *cobra.Command {
}

func networkChainPrepareHandler(cmd *cobra.Command, args []string) error {
force, _ := cmd.Flags().GetBool(flagForce)

nb, err := newNetworkBuilder(cmd)
if err != nil {
return err
Expand All @@ -47,6 +56,10 @@ func networkChainPrepareHandler(cmd *cobra.Command, args []string) error {
return err
}

if !force && !chainLaunch.LaunchTriggered {
return fmt.Errorf("chain %d has not launched yet. use --force to prepare anyway", launchID)
}

c, err := nb.Chain(networkchain.SourceLaunch(chainLaunch))
if err != nil {
return err
Expand Down
30 changes: 16 additions & 14 deletions starport/services/network/networktypes/chainlaunch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import launchtypes "github.com/tendermint/spn/x/launch/types"

// ChainLaunch represents the launch of a chain on SPN
type ChainLaunch struct {
ID uint64 `json:"ID"`
ChainID string `json:"ChainID"`
SourceURL string `json:"SourceURL"`
SourceHash string `json:"SourceHash"`
GenesisURL string `json:"GenesisURL"`
GenesisHash string `json:"GenesisHash"`
LaunchTime int64 `json:"LaunchTime"`
CampaignID uint64 `json:"CampaignID"`
ID uint64 `json:"ID"`
ChainID string `json:"ChainID"`
SourceURL string `json:"SourceURL"`
SourceHash string `json:"SourceHash"`
GenesisURL string `json:"GenesisURL"`
GenesisHash string `json:"GenesisHash"`
LaunchTime int64 `json:"LaunchTime"`
CampaignID uint64 `json:"CampaignID"`
LaunchTriggered bool `json:"LaunchTriggered"`
}

// ToChainLaunch converts a chain launch data from SPN and returns a ChainLaunch object
Expand All @@ -22,12 +23,13 @@ func ToChainLaunch(chain launchtypes.Chain) ChainLaunch {
}

launch := ChainLaunch{
ID: chain.LaunchID,
ChainID: chain.GenesisChainID,
SourceURL: chain.SourceURL,
SourceHash: chain.SourceHash,
LaunchTime: launchTime,
CampaignID: chain.CampaignID,
ID: chain.LaunchID,
ChainID: chain.GenesisChainID,
SourceURL: chain.SourceURL,
SourceHash: chain.SourceHash,
LaunchTime: launchTime,
CampaignID: chain.CampaignID,
LaunchTriggered: chain.LaunchTriggered,
}

// check if custom genesis URL is provided.
Expand Down
32 changes: 17 additions & 15 deletions starport/services/network/networktypes/chainlaunch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ func TestToChainLaunch(t *testing.T) {
InitialGenesis: launchtypes.NewDefaultInitialGenesis(),
},
expected: networktypes.ChainLaunch{
ID: 1,
ChainID: "foo-1",
SourceURL: "foo.com",
SourceHash: "0xaaa",
GenesisURL: "",
GenesisHash: "",
CampaignID: 1,
ID: 1,
ChainID: "foo-1",
SourceURL: "foo.com",
SourceHash: "0xaaa",
GenesisURL: "",
GenesisHash: "",
LaunchTriggered: false,
CampaignID: 1,
},
},
{
Expand All @@ -51,14 +52,15 @@ func TestToChainLaunch(t *testing.T) {
),
},
expected: networktypes.ChainLaunch{
ID: 1,
ChainID: "bar-1",
SourceURL: "bar.com",
SourceHash: "0xbbb",
GenesisURL: "genesisfoo.com",
GenesisHash: "0xccc",
LaunchTime: 100,
CampaignID: 0,
ID: 1,
ChainID: "bar-1",
SourceURL: "bar.com",
SourceHash: "0xbbb",
GenesisURL: "genesisfoo.com",
GenesisHash: "0xccc",
LaunchTriggered: true,
LaunchTime: 100,
CampaignID: 0,
},
},
}
Expand Down
0