-
Notifications
You must be signed in to change notification settings - Fork 80
/
tx.go
209 lines (172 loc) · 5.55 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
package cli
import (
"fmt"
"time"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/Canto-Network/Canto/v7/x/govshuttle/types"
)
var (
DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds())
)
const (
flagPacketTimeoutTimestamp = "packet-timeout-timestamp"
listSeparator = ","
)
// NewTxCmd returns a root CLI command handler for certain modules/erc20 transaction commands.
func NewTxCmd() *cobra.Command {
txCmd := &cobra.Command{
Use: types.ModuleName,
Short: "erc20 subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
txCmd.AddCommand()
return txCmd
}
// NewRegisterCoinProposalCmd implements the command to submit a community-pool-spend proposal
func NewLendingMarketProposalCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "lending-market [metadata]",
Args: cobra.ExactArgs(1),
Short: "Submit a lending market proposal",
Long: `Submit a proposal for the Canto Lending Market along with an initial deposit.
Upon passing, the
The proposal details must be supplied via a JSON file.`,
Example: fmt.Sprintf(`$ %s tx gov submit-proposal lending-market <path/to/metadata.json> --from=<key_or_address> --title=<title> --description=<description>
Where metadata.json contains (example):
{
"Account": ["address_1", "address_2"],
"PropId": 1,
"values": ["canto", "osmo"],
"calldatas: ["calldata1", "calldata2"],
"signatures": ["func1", "func2"]
}`, version.AppName,
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
title, err := cmd.Flags().GetString(cli.FlagTitle)
if err != nil {
return err
}
description, err := cmd.Flags().GetString(cli.FlagDescription)
if err != nil {
return err
}
depositStr, err := cmd.Flags().GetString(cli.FlagDeposit)
if err != nil {
return err
}
deposit, err := sdk.ParseCoinsNormalized(depositStr)
if err != nil {
return err
}
propMetaData, err := ParseLendingMarketMetadata(clientCtx.Codec, args[0])
if err != nil {
return sdkerrors.Wrap(err, "Failure to parse JSON object")
}
from := clientCtx.GetFromAddress()
content := types.NewLendingMarketProposal(title, description, &propMetaData)
msg, err := govtypes.NewMsgSubmitProposal(content, deposit, from)
if err != nil {
return err
}
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().String(cli.FlagTitle, "", "title of proposal")
cmd.Flags().String(cli.FlagDescription, "", "description of proposal")
cmd.Flags().String(cli.FlagDeposit, "1aevmos", "deposit of proposal")
if err := cmd.MarkFlagRequired(cli.FlagTitle); err != nil {
panic(err)
}
if err := cmd.MarkFlagRequired(cli.FlagDescription); err != nil {
panic(err)
}
if err := cmd.MarkFlagRequired(cli.FlagDeposit); err != nil {
panic(err)
}
return cmd
}
// Register TreasuryProposal submit cmd
func NewTreasuryProposalCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "treasury-proposal [metadata]",
Args: cobra.ExactArgs(1),
Short: "Submit a proposal to the Canto Treasury",
Long: `Submit a proposal for the Canto Treasury along with an initial deposit.
Upon passing, the
The proposal details must be supplied via a JSON file.`,
Example: fmt.Sprintf(`$ %s tx gov submit-proposal treasury-proposal <path/to/metadata.json> --from=<key_or_address> --title=<title> --description=<description>
Where metadata.json contains (example):
{
"recipient": "0xfffffff...",
"PropID": 1,
"amount": 1,
"denom": "canto/note"
}`, version.AppName,
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
title, err := cmd.Flags().GetString(cli.FlagTitle)
if err != nil {
return err
}
description, err := cmd.Flags().GetString(cli.FlagDescription)
if err != nil {
return err
}
depositStr, err := cmd.Flags().GetString(cli.FlagDeposit)
if err != nil {
return err
}
deposit, err := sdk.ParseCoinsNormalized(depositStr)
if err != nil {
return err
}
propMetaData, err := ParseTreasuryMetadata(clientCtx.Codec, args[0])
if err != nil {
return sdkerrors.Wrap(err, "Failure to parse JSON object")
}
from := clientCtx.GetFromAddress()
content := types.NewTreasuryProposal(title, description, &propMetaData)
msg, err := govtypes.NewMsgSubmitProposal(content, deposit, from)
if err != nil {
return err
}
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().String(cli.FlagTitle, "", "title of proposal")
cmd.Flags().String(cli.FlagDescription, "", "description of proposal")
cmd.Flags().String(cli.FlagDeposit, "1aevmos", "deposit of proposal")
if err := cmd.MarkFlagRequired(cli.FlagTitle); err != nil {
panic(err)
}
if err := cmd.MarkFlagRequired(cli.FlagDescription); err != nil {
panic(err)
}
if err := cmd.MarkFlagRequired(cli.FlagDeposit); err != nil {
panic(err)
}
return cmd
}