/
main.go
263 lines (224 loc) · 9.21 KB
/
main.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
package main
import (
"fmt"
"os"
"path"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
"github.com/cosmos/cosmos-sdk/x/bank"
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
"github.com/mesg-foundation/engine/app"
"github.com/mesg-foundation/engine/cosmos"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/libs/cli"
)
func main() {
// Configure cobra to sort commands
cobra.EnableCommandSorting = false
// Instantiate the codec for the command line application
cdc := app.MakeCodec()
// init the config of cosmos
cosmos.InitConfig()
rootCmd := &cobra.Command{
Use: version.ClientName,
Short: "Command line interface for interacting with " + version.Name,
}
// Add --chain-id to persistent flags and mark it required
rootCmd.PersistentFlags().String(flags.FlagChainID, "", "Chain ID of tendermint node")
rootCmd.PersistentPreRunE = func(_ *cobra.Command, _ []string) error {
return initConfig(rootCmd)
}
// Construct Root Command
rootCmd.AddCommand(
rpc.StatusCommand(),
client.ConfigCmd(app.DefaultCLIHome),
queryCmd(cdc),
txCmd(cdc),
flags.LineBreak,
orchestratorCmd(cdc),
flags.LineBreak,
ServeCommand(cdc),
flags.LineBreak,
keys.Commands(),
signCommand(),
verifySignCommand(),
flags.LineBreak,
version.Cmd,
flags.NewCompletionCmd(rootCmd, true),
)
// Add flags and prefix all env exposed with MESG
executor := cli.PrepareMainCmd(rootCmd, "MESG", app.DefaultCLIHome)
if err := executor.Execute(); err != nil {
fmt.Printf("Failed executing CLI command: %s, exiting...\n", err)
os.Exit(1)
}
}
func queryCmd(cdc *amino.Codec) *cobra.Command {
queryCmd := &cobra.Command{
Use: "query",
Aliases: []string{"q"},
Short: "Querying subcommands",
}
queryCmd.AddCommand(
authcmd.GetAccountCmd(cdc),
flags.LineBreak,
rpc.ValidatorCommand(cdc),
rpc.BlockCommand(),
authcmd.QueryTxsByEventsCmd(cdc),
authcmd.QueryTxCmd(cdc),
flags.LineBreak,
)
// add modules' query commands
app.ModuleBasics.AddQueryCommands(queryCmd, cdc)
return queryCmd
}
func txCmd(cdc *amino.Codec) *cobra.Command {
txCmd := &cobra.Command{
Use: "tx",
Short: "Transactions subcommands",
}
txCmd.AddCommand(
bankcmd.SendTxCmd(cdc),
flags.LineBreak,
authcmd.GetSignCommand(cdc),
authcmd.GetMultiSignCommand(cdc),
flags.LineBreak,
authcmd.GetBroadcastCommand(cdc),
authcmd.GetEncodeCommand(cdc),
authcmd.GetDecodeCommand(cdc),
flags.LineBreak,
)
// add modules' tx commands
app.ModuleBasics.AddTxCommands(txCmd, cdc)
// remove auth and bank commands as they're mounted under the root tx command
var cmdsToRemove []*cobra.Command
for _, cmd := range txCmd.Commands() {
if cmd.Use == auth.ModuleName || cmd.Use == bank.ModuleName {
cmdsToRemove = append(cmdsToRemove, cmd)
}
}
txCmd.RemoveCommand(cmdsToRemove...)
return txCmd
}
func initConfig(cmd *cobra.Command) error {
home, err := cmd.PersistentFlags().GetString(cli.HomeFlag)
if err != nil {
return err
}
cfgFile := path.Join(home, "config", "config.toml")
if _, err := os.Stat(cfgFile); err == nil {
viper.SetConfigFile(cfgFile)
if err := viper.ReadInConfig(); err != nil {
return err
}
}
if err := viper.BindPFlag(flags.FlagChainID, cmd.PersistentFlags().Lookup(flags.FlagChainID)); err != nil {
return err
}
if err := viper.BindPFlag(cli.EncodingFlag, cmd.PersistentFlags().Lookup(cli.EncodingFlag)); err != nil {
return err
}
return viper.BindPFlag(cli.OutputFlag, cmd.PersistentFlags().Lookup(cli.OutputFlag))
}
/*
List of commands that could be used in this cli
distribution
func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
func GetCmdWithdrawRewards(cdc *codec.Codec) *cobra.Command {
func GetCmdWithdrawAllRewards(cdc *codec.Codec, queryRoute string) *cobra.Command {
func GetCmdSetWithdrawAddr(cdc *codec.Codec) *cobra.Command {
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryValidatorOutstandingRewards(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryValidatorCommission(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryValidatorSlashes(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryDelegatorRewards(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryCommunityPool(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdSubmitProposal(cdc *codec.Codec) *cobra.Command {
gov
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryProposals(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryVote(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryVotes(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryDeposit(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryDeposits(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryTally(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryParam(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryProposer(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetTxCmd(storeKey string, cdc *codec.Codec, pcmds []*cobra.Command) *cobra.Command {
func GetCmdSubmitProposal(cdc *codec.Codec) *cobra.Command {
func GetCmdDeposit(cdc *codec.Codec) *cobra.Command {
func GetCmdVote(cdc *codec.Codec) *cobra.Command {
bank
func GetTxCmd(cdc *codec.Codec) *cobra.Command {
func SendTxCmd(cdc *codec.Codec) *cobra.Command {
params
func GetCmdSubmitProposal(cdc *codec.Codec) *cobra.Command {
auth
func GetQueryCmd(cdc *codec.Codec) *cobra.Command {
func GetAccountCmd(cdc *codec.Codec) *cobra.Command {
func QueryTxsByEventsCmd(cdc *codec.Codec) *cobra.Command {
func QueryTxCmd(cdc *codec.Codec) *cobra.Command {
func GetTxCmd(cdc *codec.Codec) *cobra.Command {
func GetSignCommand(codec *codec.Codec) *cobra.Command {
func GetMultiSignCommand(cdc *codec.Codec) *cobra.Command {
func GetBroadcastCommand(cdc *codec.Codec) *cobra.Command {
func GetEncodeCommand(cdc *codec.Codec) *cobra.Command {
staking
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryValidator(storeName string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryValidators(storeName string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryValidatorUnbondingDelegations(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryValidatorRedelegations(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryDelegation(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryDelegations(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryValidatorDelegations(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryUnbondingDelegation(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryUnbondingDelegations(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryRedelegation(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryRedelegations(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryPool(storeName string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryParams(storeName string, cdc *codec.Codec) *cobra.Command {
func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
func GetCmdCreateValidator(cdc *codec.Codec) *cobra.Command {
func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command {
func GetCmdDelegate(cdc *codec.Codec) *cobra.Command {
func GetCmdRedelegate(storeName string, cdc *codec.Codec) *cobra.Command {
func GetCmdUnbond(storeName string, cdc *codec.Codec) *cobra.Command {
crisis
func GetTxCmd(cdc *codec.Codec) *cobra.Command {
func GetCmdInvariantBroken(cdc *codec.Codec) *cobra.Command {
supply
func GetQueryCmd(cdc *codec.Codec) *cobra.Command {
func GetCmdQueryTotalSupply(cdc *codec.Codec) *cobra.Command {
slashing
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQuerySigningInfo(storeName string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryParams(cdc *codec.Codec) *cobra.Command {
func GetTxCmd(cdc *codec.Codec) *cobra.Command {
func GetCmdUnjail(cdc *codec.Codec) *cobra.Command {
mint
func GetQueryCmd(cdc *codec.Codec) *cobra.Command {
func GetCmdQueryParams(cdc *codec.Codec) *cobra.Command {
func GetCmdQueryInflation(cdc *codec.Codec) *cobra.Command {
func GetCmdQueryAnnualProvisions(cdc *codec.Codec) *cobra.Command {
client
func ConfigCmd(defaultCLIHome string) *cobra.Command {
client/lcd
func ServeCommand(cdc *codec.Codec, registerRoutesFn func(*RestServer)) *cobra.Command {
client/keys
func Commands() *cobra.Command {
client/rpc
func ValidatorCommand(cdc *codec.Codec) *cobra.Command {
func StatusCommand() *cobra.Command {
func BlockCommand() *cobra.Command {
*/