-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx.go
231 lines (200 loc) · 6.81 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package cli
import (
"bufio"
"fmt"
"io/ioutil"
"strconv"
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/client/context"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/codec"
interfacetypes "github.com/evoblockchain/evochain/libs/cosmos-sdk/codec/types"
sdk "github.com/evoblockchain/evochain/libs/cosmos-sdk/types"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/version"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/x/auth"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/x/auth/client/utils"
govcli "github.com/evoblockchain/evochain/libs/cosmos-sdk/x/gov/client/cli"
"github.com/evoblockchain/evochain/x/erc20/types"
"github.com/evoblockchain/evochain/x/gov"
"github.com/spf13/cobra"
)
// GetCmdTokenMappingProposal returns a CLI command handler for creating
// a token mapping proposal governance transaction.
func GetCmdTokenMappingProposal(cdcP *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command {
cmd := &cobra.Command{
Use: "token-mapping [denom] [contract]",
Args: cobra.ExactArgs(2),
Short: "Submit a token mapping proposal",
Long: strings.TrimSpace(
fmt.Sprintf(`Submit a token mapping proposal.
Example:
$ %s tx gov submit-proposal token-mapping xxb 0x0000...0000 --from=<key_or_address>
`, version.ClientName,
)),
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)
title, err := cmd.Flags().GetString(govcli.FlagTitle)
if err != nil {
return err
}
description, err := cmd.Flags().GetString(govcli.FlagDescription)
if err != nil {
return err
}
var contract *common.Address
if len(args[1]) > 0 {
if common.IsHexAddress(args[1]) {
addr := common.HexToAddress(args[1])
contract = &addr
} else {
return fmt.Errorf("invalid contract address %s", args[1])
}
}
content := types.NewTokenMappingProposal(
title, description, args[0], contract,
)
if err := content.ValidateBasic(); err != nil {
return err
}
strDeposit, err := cmd.Flags().GetString(govcli.FlagDeposit)
if err != nil {
return err
}
deposit, err := sdk.ParseCoins(strDeposit)
if err != nil {
return err
}
msg := gov.NewMsgSubmitProposal(content, deposit, cliCtx.GetFromAddress())
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
cmd.Flags().String(govcli.FlagTitle, "", "title of proposal")
cmd.Flags().String(govcli.FlagDescription, "", "description of proposal")
cmd.Flags().String(govcli.FlagDeposit, "", "deposit of proposal")
return cmd
}
func GetCmdProxyContractRedirectProposal(cdcP *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command {
cdc := cdcP.GetCdc()
cmd := &cobra.Command{
Use: "contract-redirect [denom] [tp] [contract|owner]",
Args: cobra.ExactArgs(3),
Short: "Submit a proxy contract redirect proposal",
Long: strings.TrimSpace(
fmt.Sprintf(`Submit a proxy contract redirect proposal.
tp:
0 implementation implementation address
1 owner owner address
Example:
$ %s tx gov submit-proposal contract-redirect xxb 0 0xffffffffffffffffffff
`, version.ClientName,
)),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().WithCodec(cdc)
title, err := cmd.Flags().GetString(govcli.FlagTitle)
if err != nil {
return err
}
description, err := cmd.Flags().GetString(govcli.FlagDescription)
if err != nil {
return err
}
tp, err := strconv.Atoi(args[1])
if err != nil {
return fmt.Errorf("invalid redirect tp,only support 0(change contract) or 1(change owner),but give %s", args[1])
}
var redirectaddr common.Address
if len(args[1]) > 0 {
if common.IsHexAddress(args[2]) {
redirectaddr = common.HexToAddress(args[2])
} else {
return fmt.Errorf("invalid contract address %s", args[1])
}
}
content := types.NewProxyContractRedirectProposal(
title, description, args[0], types.RedirectType(tp), &redirectaddr,
)
if err := content.ValidateBasic(); err != nil {
return err
}
strDeposit, err := cmd.Flags().GetString(govcli.FlagDeposit)
if err != nil {
return err
}
deposit, err := sdk.ParseCoins(strDeposit)
if err != nil {
return err
}
msg := gov.NewMsgSubmitProposal(content, deposit, cliCtx.GetFromAddress())
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
cmd.Flags().String(govcli.FlagTitle, "", "title of proposal")
cmd.Flags().String(govcli.FlagDescription, "", "description of proposal")
cmd.Flags().String(govcli.FlagDeposit, "", "deposit of proposal")
return cmd
}
func SetContractTemplateProposal(cdcP *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command {
cdc := cdcP.GetCdc()
cmd := &cobra.Command{
Use: "contract-template [file-path] proxy/implement",
Args: cobra.ExactArgs(2),
Short: "Submit a new bytecode template contract proposal",
Long: strings.TrimSpace(
fmt.Sprintf(`Submit a contract template proposal.
Example:
$ %s tx gov submit-proposal contract-template ~/template.json proxy/implement --from=<key_or_address>
the template.json should be like :
{
"abi":[xxxxx],
"bin":"xxxx"
}
`, version.ClientName,
)),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().WithCodec(cdc)
title, err := cmd.Flags().GetString(govcli.FlagTitle)
if err != nil {
return err
}
description, err := cmd.Flags().GetString(govcli.FlagDescription)
if err != nil {
return err
}
data, err := ioutil.ReadFile(args[0])
if nil != err {
return err
}
_, err = types.UnmarshalCompileContract(data)
if nil != err {
return err
}
content := types.NewContractTemplateProposal(
title, description, args[1], string(data),
)
if err := content.ValidateBasic(); err != nil {
return err
}
strDeposit, err := cmd.Flags().GetString(govcli.FlagDeposit)
if err != nil {
return err
}
deposit, err := sdk.ParseCoins(strDeposit)
if err != nil {
return err
}
msg := gov.NewMsgSubmitProposal(content, deposit, cliCtx.GetFromAddress())
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
cmd.Flags().String(govcli.FlagTitle, "", "title of proposal")
cmd.Flags().String(govcli.FlagDescription, "", "description of proposal")
cmd.Flags().String(govcli.FlagDeposit, "", "deposit of proposal")
return cmd
}