Skip to content
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
92 changes: 75 additions & 17 deletions ignite/cmd/network_chain_list.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package ignitecmd

import (
"errors"
"fmt"
"time"

"github.com/cosmos/cosmos-sdk/types/query"
"github.com/spf13/cobra"

"github.com/ignite/cli/ignite/pkg/cliui"
Expand All @@ -11,7 +14,18 @@ import (
"github.com/ignite/cli/ignite/services/network/networktypes"
)

var LaunchSummaryHeader = []string{"launch ID", "chain ID", "source", "campaign ID", "network", "reward"}
var LaunchSummaryHeader = []string{
"launch ID",
"chain ID",
"source",
"phase",
}

var LaunchSummaryAdvancedHeader = []string{
"campaign ID",
"network",
"reward",
}

// NewNetworkChainList returns a new command to list all published chains on Ignite
func NewNetworkChainList() *cobra.Command {
Expand All @@ -21,13 +35,27 @@ func NewNetworkChainList() *cobra.Command {
Args: cobra.NoArgs,
RunE: networkChainListHandler,
}
c.Flags().Bool(flagAdvanced, false, "Show advanced information about the chains")
c.Flags().Uint64(flagLimit, 100, "Limit of results per page")
c.Flags().Uint64(flagPage, 1, "Page for chain list result")

return c
}

func networkChainListHandler(cmd *cobra.Command, _ []string) error {
var (
advanced, _ = cmd.Flags().GetBool(flagAdvanced)
limit, _ = cmd.Flags().GetUint64(flagLimit)
page, _ = cmd.Flags().GetUint64(flagPage)
)

session := cliui.New()
defer session.Cleanup()

if page == 0 {
return errors.New("invalid page value")
}

nb, err := newNetworkBuilder(cmd, CollectEvents(session.EventBus()))
if err != nil {
return err
Expand All @@ -36,40 +64,70 @@ func networkChainListHandler(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
chainLaunches, err := n.ChainLaunchesWithReward(cmd.Context())
chainLaunches, err := n.ChainLaunchesWithReward(cmd.Context(), &query.PageRequest{
Offset: limit * (page - 1),
Limit: limit,
})
if err != nil {
return err
}

session.StopSpinner()

return renderLaunchSummaries(chainLaunches, session)
return renderLaunchSummaries(chainLaunches, session, advanced)
}

// renderLaunchSummaries writes into the provided out, the list of summarized launches
func renderLaunchSummaries(chainLaunches []networktypes.ChainLaunch, session cliui.Session) error {
func renderLaunchSummaries(chainLaunches []networktypes.ChainLaunch, session cliui.Session, advanced bool) error {
header := LaunchSummaryHeader
if advanced {
// advanced information show the campaign ID, type of network and rewards for incentivized testnet
header = append(header, LaunchSummaryAdvancedHeader...)
}

var launchEntries [][]string

// iterate and fetch summary for chains
for _, c := range chainLaunches {
campaign := "no campaign"
if c.CampaignID > 0 {
campaign = fmt.Sprintf("%d", c.CampaignID)
}

reward := entrywriter.None
if len(c.Reward) > 0 {
reward = c.Reward
// get the current phase of the chain
var phase string
switch {
case !c.LaunchTriggered:
phase = "coordinating"
case time.Now().Before(c.LaunchTime):
phase = "launching"
default:
phase = "launched"
}

launchEntries = append(launchEntries, []string{
entry := []string{
fmt.Sprintf("%d", c.ID),
c.ChainID,
c.SourceURL,
campaign,
c.Network.String(),
reward,
})
phase,
}

// add advanced information
if advanced {
campaign := "no campaign"
if c.CampaignID > 0 {
campaign = fmt.Sprintf("%d", c.CampaignID)
}

reward := entrywriter.None
if len(c.Reward) > 0 {
reward = c.Reward
}

entry = append(entry,
campaign,
c.Network.String(),
reward)
}

launchEntries = append(launchEntries, entry)
}

return session.PrintTable(LaunchSummaryHeader, launchEntries...)
return session.PrintTable(header, launchEntries...)
}
8 changes: 6 additions & 2 deletions ignite/services/network/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"sort"
"sync"

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

"github.com/pkg/errors"
campaigntypes "github.com/tendermint/spn/x/campaign/types"
launchtypes "github.com/tendermint/spn/x/launch/types"
Expand Down Expand Up @@ -38,12 +40,14 @@ func (n Network) ChainLaunch(ctx context.Context, id uint64) (networktypes.Chain
}

// ChainLaunchesWithReward fetches the chain launches with rewards from Network
func (n Network) ChainLaunchesWithReward(ctx context.Context) ([]networktypes.ChainLaunch, error) {
func (n Network) ChainLaunchesWithReward(ctx context.Context, pagination *query.PageRequest) ([]networktypes.ChainLaunch, error) {
g, ctx := errgroup.WithContext(ctx)

n.ev.Send(events.New(events.StatusOngoing, "Fetching chains information"))
res, err := n.launchQuery.
ChainAll(ctx, &launchtypes.QueryAllChainRequest{})
ChainAll(ctx, &launchtypes.QueryAllChainRequest{
Pagination: pagination,
})
if err != nil {
return nil, err
}
Expand Down