Skip to content
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

feat(cmd/network): creates network campaign account list command #2089

Merged
merged 29 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
02a695c
creates `network campaign account list [campaign-id]` command
Pantani Feb 15, 2022
c0e254c
Merge branch 'develop' into feat/campaign-accounts-list
Pantani Feb 15, 2022
f59f0e7
Merge branch 'develop' into feat/campaign-accounts-list
Pantani Feb 17, 2022
7bd09d9
run make format
Pantani Feb 17, 2022
52585e0
Merge branch 'develop' into feat/campaign-accounts-list
Pantani Feb 17, 2022
2985d88
Merge branch 'develop' into feat/campaign-accounts-list
Pantani Feb 17, 2022
99edbd7
Merge branch 'develop' into feat/campaign-accounts-list
Pantani Feb 18, 2022
0b07789
Merge branch 'develop' into feat/campaign-accounts-list
Pantani Feb 21, 2022
f256051
Merge branch 'develop' into feat/campaign-accounts-list
Pantani Feb 22, 2022
70f9e0d
Merge branch 'develop' into feat/campaign-accounts-list
Pantani Feb 23, 2022
ed323c7
Merge remote-tracking branch 'origin/develop' into feat/campaign-acco…
Pantani Feb 23, 2022
1a7e544
Merge branch 'develop' into feat/campaign-accounts-list
Pantani Feb 23, 2022
67d4a23
use goroutine to fetch the campaign accounts
Pantani Feb 23, 2022
377d229
use Coin and Share type instead string
Pantani Feb 24, 2022
6d0fa25
add the validator account flag back
Pantani Feb 24, 2022
11e394e
add event options
Pantani Feb 24, 2022
1a85212
print a msg if the summary is empty
Pantani Feb 24, 2022
47d6e0b
remove unused flags
Pantani Feb 24, 2022
47936d9
Merge branch 'develop' into feat/campaign-accounts-list
Pantani Feb 24, 2022
e04ec3c
put back the keyring flags
Pantani Feb 24, 2022
ef07603
Merge branch 'develop' into feat/campaign-accounts-list
Pantani Mar 2, 2022
a0d41d5
add the keyring flags to the right cmd method
Pantani Mar 3, 2022
d709690
update spn version
Pantani Mar 4, 2022
157f9c0
Merge branch 'develop' into feat/campaign-accounts-list
Pantani Mar 7, 2022
bd133a8
fix events unit tests
Pantani Mar 8, 2022
f4ebfbc
Merge remote-tracking branch 'origin/develop' into feat/campaign-acco…
Pantani Mar 9, 2022
d05ba35
Merge branch 'develop' into feat/campaign-accounts-list
Pantani Mar 9, 2022
075e02f
Merge remote-tracking branch 'origin/develop' into feat/campaign-acco…
Pantani Mar 10, 2022
2fe3817
Merge branch 'develop' into feat/campaign-accounts-list
Pantani Mar 10, 2022
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
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ require (
github.com/briandowns/spinner v1.11.1
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/charmbracelet/glow v1.4.0
github.com/cosmos/cosmos-sdk v0.44.5
github.com/cosmos/cosmos-sdk v0.44.6
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/ibc-go/v2 v2.0.2
github.com/cosmos/ibc-go/v2 v2.0.3
github.com/docker/docker v20.10.7+incompatible
github.com/emicklei/proto v1.9.0
github.com/fatih/color v1.12.0
Expand Down Expand Up @@ -45,7 +45,7 @@ require (
github.com/stretchr/testify v1.7.0
github.com/takuoki/gocase v1.0.0
github.com/tendermint/flutter/v2 v2.0.3
github.com/tendermint/spn v0.1.1-0.20220217212620-bb39a868898e
github.com/tendermint/spn v0.1.1-0.20220223181013-9b803b7972cc
github.com/tendermint/tendermint v0.34.14
github.com/tendermint/tm-db v0.6.4
github.com/tendermint/vue v0.3.0
Expand Down
13 changes: 8 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,9 @@ github.com/cloudflare/cloudflare-go v0.10.2-0.20190916151808-a80f83b9add9/go.mod
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/coinbase/rosetta-sdk-go v0.6.10 h1:rgHD/nHjxLh0lMEdfGDqpTtlvtSBwULqrrZ2qPdNaCM=
github.com/coinbase/rosetta-sdk-go v0.6.10/go.mod h1:J/JFMsfcePrjJZkwQFLh+hJErkAmdm9Iyy3D5Y0LfXo=
github.com/coinbase/rosetta-sdk-go v0.7.0 h1:lmTO/JEpCvZgpbkOITL95rA80CPKb5CtMzLaqF2mCNg=
github.com/coinbase/rosetta-sdk-go v0.7.0/go.mod h1:7nD3oBPIiHqhRprqvMgPoGxe/nyq3yftRmpsy29coWE=
github.com/confio/ics23/go v0.0.0-20200817220745-f173e6211efb/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg=
github.com/confio/ics23/go v0.6.3/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg=
github.com/confio/ics23/go v0.6.6 h1:pkOy18YxxJ/r0XFDCnrl4Bjv6h4LkBSpLS6F38mrKL8=
Expand Down Expand Up @@ -406,8 +407,9 @@ github.com/cosmos/cosmos-sdk v0.44.0/go.mod h1:orG0jzFJ2KsDfzLd/X0JSOMzF4Oxc/BQz
github.com/cosmos/cosmos-sdk v0.44.2/go.mod h1:fwQJdw+aECatpTvQTo1tSfHEsxACdZYU80QCZUPnHr4=
github.com/cosmos/cosmos-sdk v0.44.3/go.mod h1:bA3+VenaR/l/vDiYzaiwbWvRPWHMBX2jG0ygiFtiBp0=
github.com/cosmos/cosmos-sdk v0.44.4/go.mod h1:0QTCOkE8IWu5LZyfnbbjFjxYRIcV4pBOr7+zPpJwl58=
github.com/cosmos/cosmos-sdk v0.44.5 h1:t5h+KPzZb0Zsag1RP1DCMQlyJyIQqJcqSPJrbUCDGHY=
github.com/cosmos/cosmos-sdk v0.44.5/go.mod h1:maUA6m2TBxOJZkbwl0eRtEBgTX37kcaiOWU5t1HEGaY=
github.com/cosmos/cosmos-sdk v0.44.6 h1:QCAudiVmrts9IZ0s3QrG8qXXmzA0eiZvq2m5mf/7mjg=
github.com/cosmos/cosmos-sdk v0.44.6/go.mod h1:XXS/asyCqWNWkx2rW6pSuen+EVcpAFxq6khrhnZgHaQ=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
Expand All @@ -422,8 +424,9 @@ github.com/cosmos/iavl v0.17.3/go.mod h1:prJoErZFABYZGDHka1R6Oay4z9PrNeFFiMKHDAM
github.com/cosmos/ibc-go v1.2.0/go.mod h1:wGjeNd+T4kpGrt0OC8DTiE/qXLrlmTPNpdoYsBZUjKI=
github.com/cosmos/ibc-go v1.2.2 h1:bs6TZ8Es1kycIu2AHlRZ9dzJ+mveqlLN/0sjWtRH88o=
github.com/cosmos/ibc-go v1.2.2/go.mod h1:XmYjsRFOs6Q9Cz+CSsX21icNoH27vQKb3squgnCOCbs=
github.com/cosmos/ibc-go/v2 v2.0.2 h1:y7eUgggMEVe43wHLw9XrGbeaTWtfkJYMoL3m6YW4fIY=
github.com/cosmos/ibc-go/v2 v2.0.2/go.mod h1:XUmW7wmubCRhIEAGtMGS+5IjiSSmcAwihoN/yPGd6Kk=
github.com/cosmos/ibc-go/v2 v2.0.3 h1:kZ6SAj7hyxoixsLEUBx431bVGiBW22PCHwkWHafWhXs=
github.com/cosmos/ibc-go/v2 v2.0.3/go.mod h1:XUmW7wmubCRhIEAGtMGS+5IjiSSmcAwihoN/yPGd6Kk=
github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4=
github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY=
github.com/cosmos/ledger-go v0.9.2 h1:Nnao/dLwaVTk1Q5U9THldpUMMXU94BOTWPddSmVB6pI=
Expand Down Expand Up @@ -1510,8 +1513,8 @@ github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoM
github.com/tendermint/spm v0.1.5/go.mod h1:+rHrI1axfSX1R0DY6KA4IbrHPgJ0WVNJKhey71ulXO8=
github.com/tendermint/spm v0.1.8/go.mod h1:iHgfQ5YOI6ONc9E7ugGQolVdfSMHpeXfZ/OpXuN/42Q=
github.com/tendermint/spn v0.1.1-0.20211210094128-4ca78a240c57/go.mod h1:p4BO8YC6kOKSKqMfySqaLHfwBmuPE/QcLwnnVhh7H9M=
github.com/tendermint/spn v0.1.1-0.20220217212620-bb39a868898e h1:7ToGHB8AiaqKHtKWG7LzR5CMM+FxVoUhpwWLLdTiM6w=
github.com/tendermint/spn v0.1.1-0.20220217212620-bb39a868898e/go.mod h1:aPUMZ2zCuwpu98HIhaG+hWjOKgw23k5202P0LAIbFHw=
github.com/tendermint/spn v0.1.1-0.20220223181013-9b803b7972cc h1:37wEtEUGmgSzB0XD3KVR1tlOaWEu49ScTfD4L5y0hfU=
github.com/tendermint/spn v0.1.1-0.20220223181013-9b803b7972cc/go.mod h1:K9AO5C3xAcavM2gqCN5LyETKoYICU+UoaB+zBcuwmhM=
github.com/tendermint/starport v0.19.3/go.mod h1:1BlPohoDtLl8CFqTHbMSN3rhq5YLBHlTQ9mJhcRuvwI=
github.com/tendermint/tendermint v0.34.0-rc4/go.mod h1:yotsojf2C1QBOw4dZrTcxbyxmPUrT4hNuOQWX9XUwB4=
github.com/tendermint/tendermint v0.34.0-rc6/go.mod h1:ugzyZO5foutZImv0Iyx/gOFCX6mjJTgbLHTwi17VDVg=
Expand Down
1 change: 1 addition & 0 deletions starport/cmd/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func NewNetwork() *cobra.Command {
NewNetworkChain(),
NewNetworkCampaign(),
NewNetworkRequest(),
NewNetworkCampaign(),
)

return c
Expand Down
2 changes: 1 addition & 1 deletion starport/cmd/network_campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func NewNetworkCampaign() *cobra.Command {
c.AddCommand(
NewNetworkCampaignList(),
NewNetworkCampaignShow(),
NewNetworkCampaignAccount(),
)

return c
}
104 changes: 104 additions & 0 deletions starport/cmd/network_campaign_account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package starportcmd

import (
"bytes"
"fmt"
"strconv"

"github.com/spf13/cobra"

"github.com/tendermint/starport/starport/pkg/entrywriter"
)

var (
campaignMainnetsAccSummaryHeader = []string{"Mainnet Account", "Shares"}
campaignVestingAccSummaryHeader = []string{"Vesting Account", "Total Shares", "Vesting", "EndTime"}
)

// NewNetworkCampaignAccount creates a new campaign account command that holds some other
// sub commands related to account for a campaign.
func NewNetworkCampaignAccount() *cobra.Command {
c := &cobra.Command{
Use: "account",
Short: "Handle campaign accounts",
}

c.AddCommand(
newNetworkCampaignAccountList(),
)
c.PersistentFlags().AddFlagSet(flagNetworkFrom())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't this in query apis.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't remove these flags now because the network command will not work. The network method requires both flags to use the helper methods. We can refactor it in another PR

c.PersistentFlags().AddFlagSet(flagSetKeyringBackend())
Copy link
Member

@ilgooz ilgooz Feb 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need these in query apis.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


return c
}

func newNetworkCampaignAccountList() *cobra.Command {
c := &cobra.Command{
Use: "list [campaign-id]",
Short: "Show all mainnet and mainnet vesting of the campaign",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
nb, campaignID, err := networkChainLaunch(cmd, args)
if err != nil {
return err
}
defer nb.Cleanup()
n, err := nb.Network()
if err != nil {
return err
}

accountSummary := bytes.NewBufferString("")

// get all campaign mainnet accounts
mainnetAccs, err := n.MainnetAccounts(cmd.Context(), campaignID)
if err != nil {
return err
}
mainnetAccEntries := make([][]string, 0)
for _, acc := range mainnetAccs {
mainnetAccEntries = append(mainnetAccEntries, []string{
acc.Address,
acc.Shares,
})
}
if len(mainnetAccEntries) > 0 {
if err = entrywriter.MustWrite(
accountSummary,
campaignMainnetsAccSummaryHeader,
mainnetAccEntries...,
); err != nil {
return err
}
}

// get all campaign vesting accounts
vestingAccs, err := n.MainnetVestingAccounts(cmd.Context(), campaignID)
if err != nil {
return err
}
mainnetVestingAccEntries := make([][]string, 0)
for _, acc := range vestingAccs {
mainnetVestingAccEntries = append(mainnetVestingAccEntries, []string{
acc.Address,
acc.TotalShares,
acc.Vesting,
strconv.FormatInt(acc.EndTime, 10),
})
}
if len(mainnetVestingAccEntries) > 0 {
if err = entrywriter.MustWrite(
accountSummary,
campaignVestingAccSummaryHeader,
mainnetVestingAccEntries...,
); err != nil {
return err
}
}
nb.Spinner.Stop()
fmt.Print(accountSummary.String())
return nil
},
}
return c
}
36 changes: 36 additions & 0 deletions starport/services/network/networktypes/campaign.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package networktypes

import (
sdk "github.com/cosmos/cosmos-sdk/types"
campaigntypes "github.com/tendermint/spn/x/campaign/types"
)

Expand Down Expand Up @@ -31,3 +32,38 @@ func ToCampaign(campaign campaigntypes.Campaign) Campaign {
TotalShares: campaign.TotalShares.String(),
}
}

// MainnetAccount represents the campaign mainnet account of a chain on SPN
type MainnetAccount struct {
Address string `json:"Address"`
Shares string `json:"Shares"`
}

// ToMainnetAccount converts a mainnet account data from SPN and returns a MainnetAccount object
func ToMainnetAccount(acc campaigntypes.MainnetAccount) MainnetAccount {
launch := MainnetAccount{
Address: acc.Address,
Shares: sdk.Coins(acc.Shares).String(),
}
return launch
}

// MainnetVestingAccount represents the campaign mainnet vesting account of a chain on SPN
type MainnetVestingAccount struct {
Address string `json:"Address"`
TotalShares string `json:"TotalShares"`
Vesting string `json:"Vesting"`
EndTime int64 `json:"EndTime"`
}

// ToMainnetVestingAccount converts a mainnet vesting account data from SPN and returns a MainnetVestingAccount object
func ToMainnetVestingAccount(acc campaigntypes.MainnetVestingAccount) MainnetVestingAccount {
delaydVesting := acc.VestingOptions.GetDelayedVesting()
launch := MainnetVestingAccount{
Address: acc.Address,
TotalShares: sdk.Coins(delaydVesting.TotalShares).String(),
Vesting: sdk.Coins(delaydVesting.Vesting).String(),
EndTime: delaydVesting.EndTime,
}
return launch
}
1 change: 1 addition & 0 deletions starport/services/network/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (n Network) Publish(ctx context.Context, c Chain, options ...PublishOption)
coordinatorAddress,
c.Name(),
nil,
nil,
)
res, err := n.cosmos.BroadcastTx(n.account.Name, msgCreateCampaign)
if err != nil {
Expand Down
35 changes: 35 additions & 0 deletions starport/services/network/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/pkg/errors"
campaigntypes "github.com/tendermint/spn/x/campaign/types"
launchtypes "github.com/tendermint/spn/x/launch/types"

"github.com/tendermint/starport/starport/pkg/events"
Expand Down Expand Up @@ -117,3 +118,37 @@ func (n Network) GenesisValidators(ctx context.Context, launchID uint64) (genVal

return genVals, nil
}

// MainnetAccounts returns the list of campaign mainnet accounts for a launch from SPN
func (n Network) MainnetAccounts(ctx context.Context, campaignID uint64) (genAccs []networktypes.MainnetAccount, err error) {
n.ev.Send(events.New(events.StatusOngoing, "Fetching campaign mainnet accounts"))
res, err := campaigntypes.NewQueryClient(n.cosmos.Context).MainnetAccountAll(ctx, &campaigntypes.QueryAllMainnetAccountRequest{
CampaignID: campaignID,
})
if err != nil {
return genAccs, err
}

for _, acc := range res.MainnetAccount {
genAccs = append(genAccs, networktypes.ToMainnetAccount(acc))
}

return genAccs, nil
}

// MainnetVestingAccounts returns the list of campaign mainnet vesting accounts for a launch from SPN
func (n Network) MainnetVestingAccounts(ctx context.Context, campaignID uint64) (genAccs []networktypes.MainnetVestingAccount, err error) {
n.ev.Send(events.New(events.StatusOngoing, "Fetching campaign mainnet vesting accounts"))
res, err := campaigntypes.NewQueryClient(n.cosmos.Context).MainnetVestingAccountAll(ctx, &campaigntypes.QueryAllMainnetVestingAccountRequest{
CampaignID: campaignID,
})
if err != nil {
return genAccs, err
}

for _, acc := range res.MainnetVestingAccount {
genAccs = append(genAccs, networktypes.ToMainnetVestingAccount(acc))
}

return genAccs, nil
}