This repository was archived by the owner on Jul 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathnetwork_chain_list.go
More file actions
132 lines (109 loc) · 2.96 KB
/
Copy pathnetwork_chain_list.go
File metadata and controls
132 lines (109 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package cmd
import (
"errors"
"fmt"
"time"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/ignite/cli/ignite/pkg/cliui"
"github.com/ignite/cli/ignite/pkg/cliui/entrywriter"
"github.com/spf13/cobra"
"github.com/ignite/cli-plugin-network/network"
"github.com/ignite/cli-plugin-network/network/networktypes"
)
var LaunchSummaryHeader = []string{
"launch ID",
"chain ID",
"source",
"phase",
}
var LaunchSummaryAdvancedHeader = []string{
"project ID",
"network",
"reward",
}
// NewNetworkChainList returns a new command to list all published chains on Ignite.
func NewNetworkChainList() *cobra.Command {
c := &cobra.Command{
Use: "list",
Short: "List published chains",
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(cliui.StartSpinner())
defer session.End()
if page == 0 {
return errors.New("invalid page value")
}
nb, err := newNetworkBuilder(cmd, CollectEvents(session.EventBus()))
if err != nil {
return err
}
n, err := nb.Network(network.CollectEvents(session.EventBus()))
if err != nil {
return err
}
chainLaunches, err := n.ChainLaunchesWithReward(cmd.Context(), &query.PageRequest{
Offset: limit * (page - 1),
Limit: limit,
})
if err != nil {
return err
}
return renderLaunchSummaries(chainLaunches, session, advanced)
}
// renderLaunchSummaries writes into the provided out, the list of summarized launches.
func renderLaunchSummaries(chainLaunches []networktypes.ChainLaunch, session *cliui.Session, advanced bool) error {
header := LaunchSummaryHeader
if advanced {
// advanced information show the project 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 {
// 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"
}
entry := []string{
fmt.Sprintf("%d", c.ID),
c.ChainID,
c.SourceURL,
phase,
}
// add advanced information
if advanced {
project := "no project"
if c.ProjectID > 0 {
project = fmt.Sprintf("%d", c.ProjectID)
}
reward := entrywriter.None
if len(c.Reward) > 0 {
reward = c.Reward
}
entry = append(entry,
project,
c.Network.String(),
reward)
}
launchEntries = append(launchEntries, entry)
}
return session.PrintTable(header, launchEntries...)
}