-
Notifications
You must be signed in to change notification settings - Fork 2
/
root.go
242 lines (223 loc) · 4.62 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
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
// Copyright (C) 2024, AllianceBlock. All rights reserved.
// See the file LICENSE for licensing terms.
package cmd
import (
"fmt"
"time"
"github.com/ava-labs/hypersdk/cli"
"github.com/ava-labs/hypersdk/utils"
"github.com/spf13/cobra"
)
const (
fsModeWrite = 0o600
defaultDatabase = ".nuklai-cli"
defaultGenesis = "genesis.json"
)
var (
handler *Handler
dbPath string
genesisFile string
minBlockGap int64
minUnitPrice []string
maxBlockUnits []string
windowTargetUnits []string
hideTxs bool
randomRecipient bool
maxTxBacklog int
checkAllChains bool
prometheusBaseURI string
prometheusOpenBrowser bool
prometheusFile string
prometheusData string
startPrometheus bool
maxFee int64
numCores int
rootCmd = &cobra.Command{
Use: "nuklai-cli",
Short: "NuklaiVM CLI",
SuggestFor: []string{"nuklai-cli", "nuklaicli"},
}
)
func init() {
cobra.EnablePrefixMatching = true
rootCmd.AddCommand(
genesisCmd,
keyCmd,
chainCmd,
actionCmd,
emissionCmd,
spamCmd,
prometheusCmd,
)
rootCmd.PersistentFlags().StringVar(
&dbPath,
"database",
defaultDatabase,
"path to database (will create it missing)",
)
rootCmd.PersistentPreRunE = func(*cobra.Command, []string) error {
utils.Outf("{{yellow}}database:{{/}} %s\n", dbPath)
controller := NewController(dbPath)
root, err := cli.New(controller)
if err != nil {
return err
}
handler = NewHandler(root)
return err
}
rootCmd.PersistentPostRunE = func(*cobra.Command, []string) error {
return handler.Root().CloseDatabase()
}
rootCmd.SilenceErrors = true
// genesis
genGenesisCmd.PersistentFlags().StringVar(
&genesisFile,
"genesis-file",
defaultGenesis,
"genesis file path",
)
genGenesisCmd.PersistentFlags().StringSliceVar(
&minUnitPrice,
"min-unit-price",
[]string{},
"minimum price",
)
genGenesisCmd.PersistentFlags().StringSliceVar(
&maxBlockUnits,
"max-block-units",
[]string{},
"max block units",
)
genGenesisCmd.PersistentFlags().StringSliceVar(
&windowTargetUnits,
"window-target-units",
[]string{},
"window target units",
)
genGenesisCmd.PersistentFlags().Int64Var(
&minBlockGap,
"min-block-gap",
-1,
"minimum block gap (ms)",
)
genesisCmd.AddCommand(
genGenesisCmd,
)
// key
balanceKeyCmd.PersistentFlags().BoolVar(
&checkAllChains,
"check-all-chains",
false,
"check all chains",
)
balanceKeyCmd.PersistentFlags().IntVar(
&numCores,
"num-cores",
4,
"num-cores",
)
keyCmd.AddCommand(
genKeyCmd,
importKeyCmd,
setKeyCmd,
balanceKeyCmd,
vanityAddressCmd,
)
// chain
watchChainCmd.PersistentFlags().BoolVar(
&hideTxs,
"hide-txs",
false,
"hide txs",
)
chainCmd.AddCommand(
importChainCmd,
importANRChainCmd,
importAvalancheCliChainCmd,
setChainCmd,
chainInfoCmd,
watchChainCmd,
)
// actions
actionCmd.AddCommand(
transferCmd,
createAssetCmd,
mintAssetCmd,
// burnAssetCmd,
importAssetCmd,
exportAssetCmd,
registerValidatorStakeCmd,
getValidatorStakeCmd,
claimValidatorStakeRewardCmd,
withdrawValidatorStakeCmd,
delegateUserStakeCmd,
getUserStakeCmd,
claimUserStakeRewardCmd,
undelegateUserStakeCmd,
)
// emission
emissionCmd.AddCommand(
emissionInfoCmd,
emissionAllValidatorsCmd,
emissionStakedValidatorsCmd,
)
// spam
runSpamCmd.PersistentFlags().BoolVar(
&randomRecipient,
"random-recipient",
false,
"random recipient",
)
runSpamCmd.PersistentFlags().IntVar(
&maxTxBacklog,
"max-tx-backlog",
72_000,
"max tx backlog",
)
runSpamCmd.PersistentFlags().Int64Var(
&maxFee,
"max-fee",
-1,
"max fee per tx",
)
spamCmd.AddCommand(
runSpamCmd,
)
// prometheus
generatePrometheusCmd.PersistentFlags().StringVar(
&prometheusBaseURI,
"prometheus-base-uri",
"http://localhost:9090",
"prometheus server location",
)
generatePrometheusCmd.PersistentFlags().BoolVar(
&prometheusOpenBrowser,
"prometheus-open-browser",
true,
"open browser to prometheus dashboard",
)
generatePrometheusCmd.PersistentFlags().StringVar(
&prometheusFile,
"prometheus-file",
"/tmp/prometheus.yaml",
"prometheus file location",
)
generatePrometheusCmd.PersistentFlags().StringVar(
&prometheusData,
"prometheus-data",
fmt.Sprintf("/tmp/prometheus-%d", time.Now().Unix()),
"prometheus data location",
)
generatePrometheusCmd.PersistentFlags().BoolVar(
&startPrometheus,
"prometheus-start",
true,
"start local prometheus server",
)
prometheusCmd.AddCommand(
generatePrometheusCmd,
)
}
func Execute() error {
return rootCmd.Execute()
}