-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx_proposal.go
137 lines (120 loc) · 4.42 KB
/
tx_proposal.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package cli
import (
"bufio"
"fmt"
"os"
"strings"
interfacetypes "github.com/furyaxyz/fuxchain/libs/cosmos-sdk/codec/types"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/version"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/client/context"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/codec"
sdk "github.com/furyaxyz/fuxchain/libs/cosmos-sdk/types"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/x/auth"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/x/auth/client/utils"
"github.com/furyaxyz/fuxchain/x/gov"
"github.com/furyaxyz/fuxchain/x/staking/types"
"github.com/spf13/cobra"
)
// GetCmdEditValidatorCommissionRate gets the edit validator commission rate command
func GetCmdEditValidatorCommissionRate(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "edit-validator-commission-rate [commission-rate]",
Args: cobra.ExactArgs(1),
Short: "edit an existing validator commission rate",
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(auth.DefaultTxEncoder(cdc))
cliCtx := context.NewCLIContext().WithCodec(cdc)
valAddr := cliCtx.GetFromAddress()
rate, err := sdk.NewDecFromStr(args[0])
if err != nil {
return fmt.Errorf("invalid new commission rate: %v", err)
}
msg := types.NewMsgEditValidatorCommissionRate(sdk.ValAddress(valAddr), rate)
// build and sign the transaction, then broadcast to Tendermint
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
return cmd
}
// GetCmdProposeValidatorProposal implements a command handler for submitting propose validator proposal transaction
func GetCmdProposeValidatorProposal(cdcP *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command {
return &cobra.Command{
Use: "propose-validator [proposal-file]",
Args: cobra.ExactArgs(1),
Short: "Submit a proposal for proposing validator when consensus type is PoA.",
Long: strings.TrimSpace(
fmt.Sprintf(`Submit a proposal for proposing validator along with an initial deposit.
The proposal details must be supplied via a JSON file.
Example:
$ %s tx gov submit-proposal propose-validator <path/to/proposal.json> --from=<key_or_address>
Where proposal.json contains:
{
"title": "propose-validator",
"description": "propose a validator",
"is_add": true,
"deposit": [
{
"denom": "fury",
"amount": "100.000000000000000000"
}
],
"validator": {
"delegator_address": "did:fury:ex1ve4mwgq9967gk338yptsg2fheur4ke32u0gqh3",
"description": {
"details": "",
"identity": "",
"moniker": "node4",
"website": ""
},
"min_self_delegation": {
"amount": "0.000000000000000000",
"denom": "%s"
},
"pubkey": "did:fury:exvalconspub1zcjduepqc4l9dy4g3ghtc6g2wdy0m24tmjju2lggfd0wjpl055tx4knq82squ8ukzn=",
"validator_address": "did:fury:exvaloper1tfwvmtfkfzrla52w0u0u07gadkegre9gqk9nel"
}
}
`, version.ClientName, sdk.DefaultBondDenom,
)),
RunE: func(cmd *cobra.Command, args []string) error {
cdc := cdcP.GetCdc()
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().WithCodec(cdc)
proposal, err := parseProposeValidatorJSON(cdc, args[0])
if err != nil {
return err
}
content := types.NewProposeValidatorProposal(
proposal.Title,
proposal.Description,
proposal.IsAdd,
proposal.Validator,
)
err = content.ValidateBasic()
if err != nil {
return err
}
msg := gov.NewMsgSubmitProposal(content, proposal.Deposit, cliCtx.GetFromAddress())
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
}
type ProposeValidatorJSON struct {
Title string `json:"title" yaml:"title"`
Description string `json:"description" yaml:"description"`
IsAdd bool `json:"is_add" yaml:"is_add"`
Deposit sdk.SysCoins `json:"deposit" yaml:"deposit"`
Validator types.ProposeValidator `json:"validator" yaml:"validator"`
}
// ProposeValidatorJSON parses json from proposal file to ProposeValidatorJSON struct
func parseProposeValidatorJSON(cdc *codec.Codec, proposalFilePath string) (
proposal ProposeValidatorJSON, err error) {
contents, err := os.ReadFile(proposalFilePath)
if err != nil {
return
}
cdc.MustUnmarshalJSON(contents, &proposal)
return
}