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

Add proto compatible community spend cli tx #6215

Merged
merged 12 commits into from
Jun 9, 2020
Merged
53 changes: 7 additions & 46 deletions x/distribution/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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]",
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there a test case for this CLI cmd?

Copy link
Contributor Author

@sahith-narahari sahith-narahari Jun 8, 2020

Choose a reason for hiding this comment

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

There's an existing WIP PR for adding more cli_tests(#6349). Will ensure to add a test for this

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 <path/to/proposal.json> --from=<key_or_address>

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,
),
Expand All @@ -235,6 +226,7 @@ Where proposal.json contains:
return tx.GenerateOrBroadcastTx(clientCtx, msg)
},
}

return cmd
}

Expand Down Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions x/distribution/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
}

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/client/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion x/distribution/client/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)