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: 52 additions & 1 deletion x/distribution/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ $ %s tx distribution set-withdraw-addr cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75
return flags.PostCommands(cmd)[0]
}

func NewFundCommunityPoolCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command {
// TODO: Wire this to proposal handler in client/proposal_handler.go
func NewSubmitProposalCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command {
cmd := &cobra.Command{
Use: "community-pool-spend [proposal-file]",
Args: cobra.ExactArgs(1),
Expand Down Expand Up @@ -245,6 +246,56 @@ Where proposal.json contains:
WithAccountRetriever(ar)
cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m)

proposal, err := NewParseCommunityPoolSpendProposalJSON(m, args[0])
if err != nil {
return err
}

from := cliCtx.GetFromAddress()

amount, err := sdk.ParseCoins(proposal.Amount)
if err != nil {
return err
}
content := types.NewCommunityPoolSpendProposal(proposal.Title, proposal.Description, proposal.Recipient, amount)

deposit, err := sdk.ParseCoins(proposal.Deposit)
if err != nil {
return err
}
msg := gov.NewMsgSubmitProposal(content, deposit, from)
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTx(cliCtx, txf, msg)

},
}
return flags.PostCommands(cmd)[0]
}

func NewFundCommunityPoolCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command {
cmd := &cobra.Command{
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: "Funds the community pool with the specified amount",
Long: strings.TrimSpace(
fmt.Sprintf(`Funds the community pool with the specified amount

Example:
$ %s tx distribution fund-community-pool 100uatom --from mykey
`,
version.ClientName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txf := tx.NewFactoryFromCLI(inBuf).
WithTxGenerator(txg).
WithAccountRetriever(ar)
cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m)

depositorAddr := cliCtx.GetFromAddress()
amount, err := sdk.ParseCoins(args[0])
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions x/distribution/client/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ type (
}
)

func NewParseCommunityPoolSpendProposalJSON(cdc codec.Marshaler, proposalFile string) (CommunityPoolSpendProposalJSON, error) {
proposal := CommunityPoolSpendProposalJSON{}

contents, err := ioutil.ReadFile(proposalFile)
if err != nil {
return proposal, err
}

if err := cdc.UnmarshalJSON(contents, &proposal); err != nil {
return proposal, err
}

return proposal, nil
sahith-narahari marked this conversation as resolved.
Show resolved Hide resolved
}

// ParseCommunityPoolSpendProposalJSON reads and parses a CommunityPoolSpendProposalJSON from a file.
func ParseCommunityPoolSpendProposalJSON(cdc *codec.Codec, proposalFile string) (CommunityPoolSpendProposalJSON, error) {
proposal := CommunityPoolSpendProposalJSON{}
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)
)