-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx_distr_proposal.go
206 lines (172 loc) · 6.3 KB
/
tx_distr_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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// nolint
package cli
import (
"bufio"
"fmt"
"strings"
"github.com/brc20-collab/brczero/libs/cosmos-sdk/client/context"
"github.com/brc20-collab/brczero/libs/cosmos-sdk/codec"
interfacetypes "github.com/brc20-collab/brczero/libs/cosmos-sdk/codec/types"
sdk "github.com/brc20-collab/brczero/libs/cosmos-sdk/types"
"github.com/brc20-collab/brczero/libs/cosmos-sdk/version"
"github.com/brc20-collab/brczero/libs/cosmos-sdk/x/auth"
"github.com/brc20-collab/brczero/libs/cosmos-sdk/x/auth/client/utils"
"github.com/brc20-collab/brczero/x/distribution/types"
"github.com/brc20-collab/brczero/x/gov"
"github.com/spf13/cobra"
)
var (
flagCommission = "commission"
)
// GetCmdWithdrawAllRewards command to withdraw all rewards
func GetCmdWithdrawAllRewards(cdc *codec.Codec, queryRoute string) *cobra.Command {
cmd := &cobra.Command{
Use: "withdraw-all-rewards",
Short: "withdraw all delegations rewards for a delegator",
Long: strings.TrimSpace(
fmt.Sprintf(`Withdraw all rewards for a single delegator.
Example:
$ %s tx distr withdraw-all-rewards --from mykey
`,
version.ClientName,
),
),
Args: cobra.NoArgs,
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)
delAddr := cliCtx.GetFromAddress()
msg := types.NewMsgWithdrawDelegatorAllRewards(delAddr)
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
return cmd
}
// GetChangeDistributionTypeProposal implements the command to submit a change-distr-type proposal
func GetChangeDistributionTypeProposal(cdcP *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command {
cmd := &cobra.Command{
Use: "change-distr-type [proposal-file]",
Args: cobra.ExactArgs(1),
Short: "Submit a change distribution type proposal",
Long: strings.TrimSpace(
fmt.Sprintf(`Submit a change distribution type proposal with the specified value, 0: offchain model, 1:onchain model
Example:
$ %s tx gov submit-proposal change-distr-type <path/to/proposal.json> --from=<key_or_address>
Where proposal.json contains:
{
"title": "Change Distribution Type",
"description": "Will change the distribution type",
"type": 0,
"deposit": [
{
"denom": "%s",
"amount": "100.000000000000000000"
}
]
}
`,
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 := ParseChangeDistributionTypeProposalJSON(cdc, args[0])
if err != nil {
return err
}
from := cliCtx.GetFromAddress()
content := types.NewChangeDistributionTypeProposal(proposal.Title, proposal.Description, proposal.Type)
msg := gov.NewMsgSubmitProposal(content, proposal.Deposit, from)
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
return cmd
}
// GetWithdrawRewardEnabledProposal implements the command to submit a withdraw-reward-enabled proposal
func GetWithdrawRewardEnabledProposal(cdcP *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command {
cmd := &cobra.Command{
Use: "withdraw-reward-enabled [proposal-file]",
Args: cobra.ExactArgs(1),
Short: "Submit a withdraw reward enabled or disabled proposal",
Long: strings.TrimSpace(
fmt.Sprintf(`Submit a withdraw reward enabled or disabled proposal with the specified value, true: enabled, false: disabled
Example:
$ %s tx gov submit-proposal withdraw-reward-enabled <path/to/proposal.json> --from=<key_or_address>
Where proposal.json contains:
{
"title": "Withdraw Reward Enabled | Disabled",
"description": "Will set withdraw reward enabled | disabled",
"enabled": false,
"deposit": [
{
"denom": "%s",
"amount": "100.000000000000000000"
}
]
}
`,
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 := ParseWithdrawRewardEnabledProposalJSON(cdc, args[0])
if err != nil {
return err
}
from := cliCtx.GetFromAddress()
content := types.NewWithdrawRewardEnabledProposal(proposal.Title, proposal.Description, proposal.Enabled)
msg := gov.NewMsgSubmitProposal(content, proposal.Deposit, from)
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
return cmd
}
// GetRewardTruncatePrecisionProposal implements the command to submit a reward-truncate-precision proposal
func GetRewardTruncatePrecisionProposal(cdcP *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command {
cmd := &cobra.Command{
Use: "reward-truncate-precision [proposal-file]",
Args: cobra.ExactArgs(1),
Short: "Submit a reward truncated precision proposal",
Long: strings.TrimSpace(
fmt.Sprintf(`Submit a reward truncated precision proposal with the specified value,
Example:
$ %s tx gov submit-proposal reward-truncate-precision <path/to/proposal.json> --from=<key_or_address>
Where proposal.json contains:
{
"title": "Set reward truncated precision",
"description": "Set distribution reward truncated precision",
"deposit": [{
"denom": "%s",
"amount": "100.000000000000000000"
}],
"precision": "0"
}
`,
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 := ParseRewardTruncatePrecisionProposalJSON(cdc, args[0])
if err != nil {
return err
}
from := cliCtx.GetFromAddress()
content := types.NewRewardTruncatePrecisionProposal(proposal.Title, proposal.Description, proposal.Precision)
msg := gov.NewMsgSubmitProposal(content, proposal.Deposit, from)
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
return cmd
}