-
Notifications
You must be signed in to change notification settings - Fork 0
/
governor.go
75 lines (60 loc) · 2.22 KB
/
governor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package cli
import (
"bufio"
"github.com/ayher/anatha/client/context"
"github.com/ayher/anatha/codec"
sdk "github.com/ayher/anatha/types"
"github.com/ayher/anatha/x/auth"
"github.com/ayher/anatha/x/auth/client/utils"
govutils "github.com/ayher/project-anatha/x/governance/client/utils"
govtypes "github.com/ayher/project-anatha/x/governance/internal/types"
"github.com/spf13/cobra"
)
func GetCmdSubmitAddGovernorProposal(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "add-governor [proposal-file]",
Args: cobra.ExactArgs(1),
Short: "Submit a proposal to add a new governor",
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc)
proposal, err := govutils.ParseGovernorProposalJSON(cdc, args[0])
if err != nil {
return err
}
from := cliCtx.GetFromAddress()
content := govtypes.NewAddGovernorProposal(proposal.Title, proposal.Description, proposal.Governor)
msg := govtypes.NewMsgSubmitProposal(content, from)
if err := msg.ValidateBasic(); err != nil {
return err
}
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
return cmd
}
func GetCmdSubmitRemoveGovernorProposal(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "remove-governor [proposal-file]",
Args: cobra.ExactArgs(1),
Short: "Submit a proposal to remove a governor",
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc)
proposal, err := govutils.ParseGovernorProposalJSON(cdc, args[0])
if err != nil {
return err
}
from := cliCtx.GetFromAddress()
content := govtypes.NewRemoveGovernorProposal(proposal.Title, proposal.Description, proposal.Governor)
msg := govtypes.NewMsgSubmitProposal(content, from)
if err := msg.ValidateBasic(); err != nil {
return err
}
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
return cmd
}