This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tx.go
215 lines (183 loc) · 5.52 KB
/
tx.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
207
208
209
210
211
212
213
214
215
package cli
import (
"errors"
"fmt"
"strings"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/bianjieai/spartan-cosmos/module/node"
"github.com/bianjieai/spartan-cosmos/module/node/client/utils"
)
// NewCreateValidatorProposalTxCmd returns a CLI command handler for creating
// a validator create proposal governance transaction.
func NewCreateValidatorProposalTxCmd() *cobra.Command {
return &cobra.Command{
Use: "create-validator [file]",
Args: cobra.ExactArgs(1),
Short: "Submit a validator to create proposal",
Long: strings.TrimSpace(
fmt.Sprintf(`Submit a proposal along with an initial deposit.
Example:
$ %s tx gov submit-proposal create-validator proposal.json --from mykey
Where proposal.json contains:
{
"deposit":"1000usnmt",
"content":{
"title":"proposal title",
"summary":"proposal description",
"name":"node1",
"pubkey":"{\"@type\":\"/cosmos.crypto.ed25519.PubKey\",\"key\":\"FU1a1Yhu+eE0XlZWSwywZur2uItmtpYZGs8TpMK4im0=\"}",
"power":"100",
"description":"my node1",
"operator":"iaa104hrdtdkk5lfh8c3nc3pf20ad0sgdvselg0vxs"
}
}
`,
version.AppName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
proposal, err := utils.ParseValidatorCreateJSON(clientCtx.LegacyAmino, args[0])
if err != nil {
return err
}
from := clientCtx.GetFromAddress()
deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit)
if err != nil {
return err
}
if len(proposal.Content.Pubkey) == 0 {
return errors.New("pubkey cannot be blank")
}
var pk cryptotypes.PubKey
if err := clientCtx.Codec.UnmarshalInterfaceJSON([]byte(proposal.Content.Pubkey), &pk); err != nil {
return err
}
var pkAny *codectypes.Any
if pkAny, err = codectypes.NewAnyWithValue(pk); err != nil {
return err
}
content := &node.CreateValidatorProposal{
Title: proposal.Content.Title,
Summary: proposal.Content.Summary,
Name: proposal.Content.Name,
Pubkey: pkAny,
Power: proposal.Content.Power,
Description: proposal.Content.Description,
Operator: proposal.Content.Operator,
}
msg, err := govtypes.NewMsgSubmitProposal(content, deposit, from)
if err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
}
// NewUpdateValidatorProposalTxCmd returns a CLI command handler for creating
// a validator create proposal governance transaction.
func NewUpdateValidatorProposalTxCmd() *cobra.Command {
return &cobra.Command{
Use: "update-validator [file]",
Args: cobra.ExactArgs(1),
Short: "Submit a validator to update proposal",
Long: strings.TrimSpace(
fmt.Sprintf(`Submit a proposal along with an initial deposit.
Example:
$ %s tx gov submit-proposal update-validator proposal.json --from mykey
Where proposal.json contains:
{
"deposit":"1000usnmt",
"content":{
"title":"proposal title",
"summary":"proposal description",
"id":"3B0CB3D0CFD6590F1101543B9608CF590BB4CF9380C86407BA9DE1E7DA12F43E",
"name":"node1",
"power":"100",
"description":"my node1",
"operator":"iaa104hrdtdkk5lfh8c3nc3pf20ad0sgdvselg0vxs"
}
}
`,
version.AppName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
proposal, err := utils.ParseValidatorUpdateJSON(clientCtx.LegacyAmino, args[0])
if err != nil {
return err
}
from := clientCtx.GetFromAddress()
deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit)
if err != nil {
return err
}
msg, err := govtypes.NewMsgSubmitProposal(&proposal.Content, deposit, from)
if err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
}
// NewRemoveValidatorProposalTxCmd returns a CLI command handler for creating
// a validator create proposal governance transaction.
func NewRemoveValidatorProposalTxCmd() *cobra.Command {
return &cobra.Command{
Use: "remove-validator [file]",
Args: cobra.ExactArgs(1),
Short: "Submit a validator to remove proposal",
Long: strings.TrimSpace(
fmt.Sprintf(`Submit a proposal along with an initial deposit.
Example:
$ %s tx gov submit-proposal remove-validator proposal.json --from mykey
Where proposal.json contains:
{
"deposit":"1000usnmt",
"content":{
"title":"proposal title",
"summary":"proposal description",
"id":"3B0CB3D0CFD6590F1101543B9608CF590BB4CF9380C86407BA9DE1E7DA12F43E",
"operator":"iaa104hrdtdkk5lfh8c3nc3pf20ad0sgdvselg0vxs"
}
}
`,
version.AppName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
proposal, err := utils.ParseValidatorRemoveJSON(clientCtx.LegacyAmino, args[0])
if err != nil {
return err
}
from := clientCtx.GetFromAddress()
deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit)
if err != nil {
return err
}
msg, err := govtypes.NewMsgSubmitProposal(&proposal.Content, deposit, from)
if err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
}