forked from ignite/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…e#2100) * add campaign info command * add campaign show command * apply pr review discussions * remove unused method call
- Loading branch information
Showing
24 changed files
with
248 additions
and
32 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
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
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
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,21 @@ | ||
package starportcmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewNetworkCampaign creates a new campaign command that holds other | ||
// subcommands related to launching a network for a campaign. | ||
func NewNetworkCampaign() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: "campaign", | ||
Short: "Handle campaigns", | ||
} | ||
|
||
c.AddCommand( | ||
NewNetworkCampaignList(), | ||
NewNetworkCampaignShow(), | ||
) | ||
|
||
return c | ||
} |
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,73 @@ | ||
package starportcmd | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/tendermint/starport/starport/pkg/entrywriter" | ||
"github.com/tendermint/starport/starport/services/network/networktypes" | ||
) | ||
|
||
var CampaignSummaryHeader = []string{ | ||
"id", | ||
"name", | ||
"coordinator id", | ||
"mainnet id", | ||
} | ||
|
||
// NewNetworkCampaignList returns a new command to list all published campaigns on Starport Network. | ||
func NewNetworkCampaignList() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: "list", | ||
Short: "List published campaigns", | ||
Args: cobra.NoArgs, | ||
RunE: networkCampaignListHandler, | ||
} | ||
c.Flags().AddFlagSet(flagNetworkFrom()) | ||
c.Flags().AddFlagSet(flagSetKeyringBackend()) | ||
c.Flags().AddFlagSet(flagSetHome()) | ||
return c | ||
} | ||
|
||
func networkCampaignListHandler(cmd *cobra.Command, args []string) error { | ||
nb, err := newNetworkBuilder(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
n, err := nb.Network() | ||
if err != nil { | ||
return err | ||
} | ||
campaigns, err := n.Campaigns(cmd.Context()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
nb.Cleanup() | ||
return renderCampaignSummaries(campaigns, os.Stdout) | ||
} | ||
|
||
// renderCampaignSummaries writes into the provided out, the list of summarized campaigns | ||
func renderCampaignSummaries(campaigns []networktypes.Campaign, out io.Writer) error { | ||
var campaignEntries [][]string | ||
|
||
for _, c := range campaigns { | ||
mainnetID := entrywriter.None | ||
if c.MainnetInitialized { | ||
mainnetID = fmt.Sprintf("%d", c.MainnetID) | ||
} | ||
|
||
campaignEntries = append(campaignEntries, []string{ | ||
fmt.Sprintf("%d", c.ID), | ||
c.Name, | ||
fmt.Sprintf("%d", c.CoordinatorID), | ||
mainnetID, | ||
}) | ||
} | ||
|
||
return entrywriter.MustWrite(out, CampaignSummaryHeader, campaignEntries...) | ||
} |
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,56 @@ | ||
package starportcmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/tendermint/starport/starport/pkg/yaml" | ||
"github.com/tendermint/starport/starport/services/network" | ||
) | ||
|
||
// NewNetworkCampaignShow returns a new command to show published campaign on Starport Network | ||
func NewNetworkCampaignShow() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: "show [campaign-id]", | ||
Short: "Show published campaign", | ||
Args: cobra.ExactArgs(1), | ||
RunE: networkCampaignShowHandler, | ||
} | ||
c.Flags().AddFlagSet(flagNetworkFrom()) | ||
c.Flags().AddFlagSet(flagSetKeyringBackend()) | ||
c.Flags().AddFlagSet(flagSetHome()) | ||
return c | ||
} | ||
|
||
func networkCampaignShowHandler(cmd *cobra.Command, args []string) error { | ||
// parse campaign ID | ||
campaignID, err := network.ParseID(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
nb, err := newNetworkBuilder(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
defer nb.Cleanup() | ||
|
||
n, err := nb.Network() | ||
if err != nil { | ||
return err | ||
} | ||
campaign, err := n.Campaign(cmd.Context(), campaignID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
info, err := yaml.Marshal(cmd.Context(), campaign) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
nb.Spinner.Stop() | ||
fmt.Print(info) | ||
return nil | ||
} |
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
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
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
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
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
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
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
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
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
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
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
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
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
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,40 @@ | ||
package network | ||
|
||
import ( | ||
"context" | ||
|
||
campaigntypes "github.com/tendermint/spn/x/campaign/types" | ||
|
||
"github.com/tendermint/starport/starport/pkg/events" | ||
"github.com/tendermint/starport/starport/services/network/networktypes" | ||
) | ||
|
||
// Campaign fetches the campaign from Starport Network | ||
func (n Network) Campaign(ctx context.Context, campaignID uint64) (networktypes.Campaign, error) { | ||
n.ev.Send(events.New(events.StatusOngoing, "Fetching campaign information")) | ||
res, err := campaigntypes.NewQueryClient(n.cosmos.Context).Campaign(ctx, &campaigntypes.QueryGetCampaignRequest{ | ||
CampaignID: campaignID, | ||
}) | ||
if err != nil { | ||
return networktypes.Campaign{}, err | ||
} | ||
return networktypes.ToCampaign(res.Campaign), nil | ||
} | ||
|
||
// Campaigns fetches the campaigns from Starport Network | ||
func (n Network) Campaigns(ctx context.Context) ([]networktypes.Campaign, error) { | ||
var campaigns []networktypes.Campaign | ||
|
||
n.ev.Send(events.New(events.StatusOngoing, "Fetching campaigns information")) | ||
res, err := campaigntypes.NewQueryClient(n.cosmos.Context).CampaignAll(ctx, &campaigntypes.QueryAllCampaignRequest{}) | ||
if err != nil { | ||
return campaigns, err | ||
} | ||
|
||
// Parse fetched campaigns | ||
for _, campaign := range res.Campaign { | ||
campaigns = append(campaigns, networktypes.ToCampaign(campaign)) | ||
} | ||
|
||
return campaigns, nil | ||
} |
Oops, something went wrong.