-
Notifications
You must be signed in to change notification settings - Fork 17
/
root.go
201 lines (173 loc) · 5.55 KB
/
root.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
package main
import (
"fmt"
"os"
"strconv"
"time"
kyveApp "github.com/KYVENetwork/chain/app"
tmCli "github.com/cometbft/cometbft/libs/cli"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
"github.com/cosmos/cosmos-sdk/client/debug"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/client/pruning"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/version"
"github.com/spf13/cobra"
// Auth
authCli "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
authTypes "github.com/cosmos/cosmos-sdk/x/auth/types"
// Bank
bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types"
// Crisis
"github.com/cosmos/cosmos-sdk/x/crisis"
// GenUtil
genUtilCli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
genUtilTypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
// Global
globalTypes "github.com/KYVENetwork/chain/x/global/types"
// Team
teamTypes "github.com/KYVENetwork/chain/x/team/types"
)
// NewRootCmd creates a new root command for the KYVE chain daemon.
func NewRootCmd(encodingConfig kyveApp.EncodingConfig) *cobra.Command {
initClientCtx := client.Context{}.
WithCodec(encodingConfig.Marshaler).
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
WithTxConfig(encodingConfig.TxConfig).
WithLegacyAmino(encodingConfig.Amino).
WithInput(os.Stdin).
WithAccountRetriever(authTypes.AccountRetriever{}).
WithHomeDir(kyveApp.DefaultNodeHome).
WithViper("KYVE")
rootCmd := &cobra.Command{
Use: "kyved",
Short: "KYVE Chain Daemon",
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
cmd.SetOut(cmd.OutOrStdout())
cmd.SetErr(cmd.ErrOrStderr())
initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags())
if err != nil {
return err
}
initClientCtx, err = config.ReadFromClientConfig(initClientCtx)
if err != nil {
return err
}
if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil {
return err
}
customAppTemplate, customAppConfig := initAppConfig()
customTMConfig := initTendermintConfig()
return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customTMConfig)
},
}
ac := appCreator{encodingConfig}
server.AddCommands(
rootCmd,
kyveApp.DefaultNodeHome,
ac.createApp,
ac.exportApp,
func(startCmd *cobra.Command) {
crisis.AddModuleInitFlags(startCmd)
},
)
rootCmd.AddCommand(
genUtilCli.InitCmd(kyveApp.ModuleBasics, kyveApp.DefaultNodeHome),
// TODO(@john): Investigate why the one directly from the module is nil.
genUtilCli.CollectGenTxsCmd(bankTypes.GenesisBalancesIterator{}, kyveApp.DefaultNodeHome, genUtilTypes.DefaultMessageValidator),
genUtilCli.MigrateGenesisCmd(),
genUtilCli.GenTxCmd(
kyveApp.ModuleBasics,
encodingConfig.TxConfig,
bankTypes.GenesisBalancesIterator{},
kyveApp.DefaultNodeHome,
),
infoCommand(),
genUtilCli.ValidateGenesisCmd(kyveApp.ModuleBasics),
addGenesisAccountCmd(kyveApp.DefaultNodeHome),
tmCli.NewCompletionCmd(rootCmd, true),
debug.Cmd(),
config.Cmd(),
pruning.Cmd(ac.createApp, kyveApp.DefaultNodeHome),
rpc.StatusCommand(),
queryCommand(),
txCommand(),
keys.Commands(kyveApp.DefaultNodeHome),
)
return rootCmd
}
func queryCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "query",
Aliases: []string{"q"},
Short: "Querying subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
cmd.AddCommand(
rpc.BlockCommand(),
rpc.ValidatorCommand(),
authCli.GetAccountCmd(),
authCli.QueryTxCmd(),
authCli.QueryTxsByEventsCmd(),
)
kyveApp.ModuleBasics.AddQueryCommands(cmd)
cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")
return cmd
}
func txCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "tx",
Short: "Transactions subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
cmd.AddCommand(
authCli.GetSignCommand(),
authCli.GetSignBatchCommand(),
authCli.GetMultiSignCommand(),
authCli.GetValidateSignaturesCommand(),
authCli.GetBroadcastCommand(),
authCli.GetEncodeCommand(),
authCli.GetDecodeCommand(),
)
kyveApp.ModuleBasics.AddTxCommands(cmd)
cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")
return cmd
}
func infoCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "info",
Short: "Transactions subcommands",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("Information about build variables:")
fmt.Printf("Version: %s\n", version.Version)
fmt.Printf("Denom: %s\n", globalTypes.Denom)
fmt.Printf("Team-Foundation-Authority: %s\n", teamTypes.FOUNDATION_ADDRESS)
fmt.Printf("Team-BCP-Authority: %s\n", teamTypes.BCP_ADDRESS)
fmt.Printf("Team-Allocation: %s\n", formatInt(teamTypes.TEAM_ALLOCATION))
fmt.Printf("Team-TGE: %s\n", time.Unix(int64(teamTypes.TGE), 0).String())
return nil
},
}
return cmd
}
func formatInt(number uint64) string {
output := strconv.FormatUint(number, 10)
startOffset := 3
outputIndex := len(output)
if len(output) >= 6 {
outputIndex -= 6
output = output[:outputIndex] + "." + output[outputIndex:]
for outputIndex > startOffset {
outputIndex -= 3
output = output[:outputIndex] + "," + output[outputIndex:]
}
}
return output
}