Skip to content

Commit db73f42

Browse files
Pantanilumtis
andauthored
feat(cmd/network): implement network profile cmd (#2145)
* add the profile command * add profile queries * profile command * add network profile method and print into the cmd * import sort * fix unit tests for network publish command * use profile interface * fix wrong coord address * grpc error responses * update spn and mocks * fix the profile command and balances * remove omitted fields * fix unit tests * fix unit tests * apply comment suggestions regarding code style * handle not found address * fix imports * fix imports 2 * some fixes = * fix cli * some fixes * goimport * fix test Co-authored-by: ltacker <lucas.bertrand.22@gmail.com>
1 parent a8c3973 commit db73f42

File tree

18 files changed

+773
-52
lines changed

18 files changed

+773
-52
lines changed

ignite/cmd/network.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func NewNetwork() *cobra.Command {
6060
NewNetworkRequest(),
6161
NewNetworkReward(),
6262
NewNetworkClient(),
63+
NewNetworkProfile(),
6364
)
6465

6566
return c

ignite/cmd/network_chain_show_accounts.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func networkChainShowAccountsHandler(cmd *cobra.Command, args []string) error {
6363
return err
6464
}
6565

66-
genesisAccEntries = append(genesisAccEntries, []string{address, acc.Coins})
66+
genesisAccEntries = append(genesisAccEntries, []string{address, acc.Coins.String()})
6767
}
6868
genesisVestingAccEntries := make([][]string, 0)
6969
for _, acc := range vestingAccs {
@@ -74,8 +74,8 @@ func networkChainShowAccountsHandler(cmd *cobra.Command, args []string) error {
7474

7575
genesisVestingAccEntries = append(genesisVestingAccEntries, []string{
7676
address,
77-
acc.TotalBalance,
78-
acc.Vesting,
77+
acc.TotalBalance.String(),
78+
acc.Vesting.String(),
7979
strconv.FormatInt(acc.EndTime, 10),
8080
})
8181
}

ignite/cmd/network_profile.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package ignitecmd
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
"github.com/ignite/cli/ignite/pkg/cliui"
7+
"github.com/ignite/cli/ignite/pkg/yaml"
8+
"github.com/ignite/cli/ignite/services/network"
9+
)
10+
11+
// NewNetworkProfile returns a new command to show the address profile info on Starport Network.
12+
func NewNetworkProfile() *cobra.Command {
13+
c := &cobra.Command{
14+
Use: "profile [campaign-id]",
15+
Short: "Show the address profile info",
16+
Args: cobra.RangeArgs(0, 1),
17+
RunE: networkProfileHandler,
18+
}
19+
c.Flags().AddFlagSet(flagNetworkFrom())
20+
c.Flags().AddFlagSet(flagSetKeyringBackend())
21+
c.Flags().AddFlagSet(flagSetHome())
22+
return c
23+
}
24+
25+
func networkProfileHandler(cmd *cobra.Command, args []string) error {
26+
session := cliui.New()
27+
defer session.Cleanup()
28+
29+
nb, err := newNetworkBuilder(cmd)
30+
if err != nil {
31+
return err
32+
}
33+
34+
n, err := nb.Network()
35+
if err != nil {
36+
return err
37+
}
38+
39+
var (
40+
campaignID uint64
41+
)
42+
if len(args) > 0 {
43+
campaignID, err = network.ParseID(args[0])
44+
if err != nil {
45+
return err
46+
}
47+
}
48+
49+
profile, err := n.Profile(cmd.Context(), campaignID)
50+
if err != nil {
51+
return err
52+
}
53+
54+
profileInfo, err := yaml.Marshal(cmd.Context(), profile)
55+
if err != nil {
56+
return err
57+
}
58+
return session.Println(profileInfo)
59+
}

ignite/services/network/campaign.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
sdk "github.com/cosmos/cosmos-sdk/types"
88
campaigntypes "github.com/tendermint/spn/x/campaign/types"
99

10+
"github.com/ignite/cli/ignite/pkg/cosmoserror"
1011
"github.com/ignite/cli/ignite/pkg/events"
1112
"github.com/ignite/cli/ignite/services/network/networktypes"
1213
)
@@ -50,7 +51,9 @@ func (n Network) Campaign(ctx context.Context, campaignID uint64) (networktypes.
5051
res, err := n.campaignQuery.Campaign(ctx, &campaigntypes.QueryGetCampaignRequest{
5152
CampaignID: campaignID,
5253
})
53-
if err != nil {
54+
if cosmoserror.Unwrap(err) == cosmoserror.ErrNotFound {
55+
return networktypes.Campaign{}, ErrObjectNotFound
56+
} else if err != nil {
5457
return networktypes.Campaign{}, err
5558
}
5659
return networktypes.ToCampaign(res.Campaign), nil

ignite/services/network/mocks/bank_client.go

Lines changed: 266 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ignite/services/network/mocks/staking_client.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)