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 <alexanderbez@users.noreply.github.com>
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
SaReN
2020-06-09 10:18:44 +00:00
committed by GitHub
co-authored by Alexander Bezobchuk Federico Kunze
parent ea12c3580e
commit 0786e68296
4 changed files with 12 additions and 51 deletions
+7 -46
View File
@@ -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 <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,
),
@@ -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
}
+3 -3
View File
@@ -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)
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -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)
)