From 0786e68296fab19d961019b966926a809fcfde2c Mon Sep 17 00:00:00 2001 From: SaReN Date: Tue, 9 Jun 2020 15:48:44 +0530 Subject: [PATCH] Add proto compatible community spend cli tx (#6215) * Add NewSubmitProposal for x/distribution * Addressed comments * Fix description for fund tx * Remove old splitAndApply * Update utils * Add missing flag Co-authored-by: Alexander Bezobchuk Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> --- x/distribution/client/cli/tx.go | 53 +++-------------------- x/distribution/client/cli/tx_test.go | 6 +-- x/distribution/client/cli/utils.go | 2 +- x/distribution/client/proposal_handler.go | 2 +- 4 files changed, 12 insertions(+), 51 deletions(-) diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index 43f6ef81d2..323b3f2d90 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -156,6 +156,8 @@ $ %s tx distribution withdraw-all-rewards --from mykey return newSplitAndApply(tx.GenerateOrBroadcastTx, clientCtx, msgs, chunkSize) }, } + + cmd.Flags().Int(flagMaxMessagesPerTx, MaxMessagesPerTxDefault, "Limit the number of messages per tx (0 for unlimited)") return cmd } @@ -195,25 +197,14 @@ $ %s tx distribution set-withdraw-addr cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75 func NewFundCommunityPoolCmd(clientCtx client.Context) *cobra.Command { cmd := &cobra.Command{ - Use: "community-pool-spend [proposal-file]", + Use: "fund-community-pool [amount]", Args: cobra.ExactArgs(1), - Short: "Submit a community pool spend proposal", + Short: "Funds the community pool with the specified amount", Long: strings.TrimSpace( - fmt.Sprintf(`Submit a community pool spend proposal along with an initial deposit. -The proposal details must be supplied via a JSON file. + fmt.Sprintf(`Funds the community pool with the specified amount Example: -$ %s tx gov submit-proposal community-pool-spend --from= - -Where proposal.json contains: - -{ - "title": "Community Pool Spend", - "description": "Pay me some Atoms!", - "recipient": "cosmos1s5afhd6gxevu37mkqcvvsj8qeylhn0rz46zdlq", - "amount": "1000stake", - "deposit": "1000stake" -} +$ %s tx distribution fund-community-pool 100uatom --from mykey `, version.ClientName, ), @@ -235,6 +226,7 @@ Where proposal.json contains: return tx.GenerateOrBroadcastTx(clientCtx, msg) }, } + return cmd } @@ -298,34 +290,3 @@ Where proposal.json contains: return cmd } - -type generateOrBroadcastFunc func(client.Context, []sdk.Msg) error - -func splitAndApply( - generateOrBroadcast generateOrBroadcastFunc, - clientCtx client.Context, - msgs []sdk.Msg, - chunkSize int, -) error { - - if chunkSize == 0 { - return generateOrBroadcast(clientCtx, msgs) - } - - // split messages into slices of length chunkSize - totalMessages := len(msgs) - for i := 0; i < len(msgs); i += chunkSize { - - sliceEnd := i + chunkSize - if sliceEnd > totalMessages { - sliceEnd = totalMessages - } - - msgChunk := msgs[i:sliceEnd] - if err := generateOrBroadcast(clientCtx, msgChunk); err != nil { - return err - } - } - - return nil -} diff --git a/x/distribution/client/cli/tx_test.go b/x/distribution/client/cli/tx_test.go index f7b1e58921..2b5f27ca56 100644 --- a/x/distribution/client/cli/tx_test.go +++ b/x/distribution/client/cli/tx_test.go @@ -17,7 +17,7 @@ import ( func Test_splitAndCall_NoMessages(t *testing.T) { clientCtx := client.Context{} - err := splitAndApply(nil, clientCtx, nil, 10) + err := newSplitAndApply(nil, clientCtx, nil, 10) assert.NoError(t, err, "") } @@ -39,8 +39,8 @@ func Test_splitAndCall_Splitting(t *testing.T) { const chunkSize = 2 callCount := 0 - err := splitAndApply( - func(clientCtx client.Context, msgs []sdk.Msg) error { + err := newSplitAndApply( + func(clientCtx client.Context, msgs ...sdk.Msg) error { callCount++ assert.NotNil(t, clientCtx) diff --git a/x/distribution/client/cli/utils.go b/x/distribution/client/cli/utils.go index c5310f6469..078085c2ae 100644 --- a/x/distribution/client/cli/utils.go +++ b/x/distribution/client/cli/utils.go @@ -27,7 +27,7 @@ func ParseCommunityPoolSpendProposalJSON(cdc codec.JSONMarshaler, proposalFile s return proposal, err } - if err := cdc.UnmarshalJSON(contents, &proposal); err != nil { + if err = cdc.UnmarshalJSON(contents, &proposal); err != nil { return proposal, err } diff --git a/x/distribution/client/proposal_handler.go b/x/distribution/client/proposal_handler.go index c7fcc0bdce..517f508bff 100644 --- a/x/distribution/client/proposal_handler.go +++ b/x/distribution/client/proposal_handler.go @@ -6,7 +6,7 @@ import ( govclient "github.com/cosmos/cosmos-sdk/x/gov/client" ) -// param change proposal handler +// ProposalHandler is the community spend proposal handler. var ( ProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitProposal, rest.ProposalRESTHandler) )