forked from 0xPolygonHermez/zkevm-node
-
Notifications
You must be signed in to change notification settings - Fork 217
/
main.go
128 lines (122 loc) · 3.47 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
package main
import (
"fmt"
"os"
"github.com/0xPolygonHermez/zkevm-node/config"
"github.com/0xPolygonHermez/zkevm-node/jsonrpc"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/urfave/cli/v2"
)
const (
// App name
appName = "zkevm-node"
// version represents the program based on the git tag
version = "v0.1.0"
// commit represents the program based on the git commit
commit = "dev"
// date represents the date of application was built
date = ""
)
const (
// AGGREGATOR is the aggregator component identifier.
AGGREGATOR = "aggregator"
// SEQUENCER is the sequencer component identifier.
SEQUENCER = "sequencer"
// RPC is the RPC component identifier.
RPC = "rpc"
// SYNCHRONIZER is the synchronizer component identifier.
SYNCHRONIZER = "synchronizer"
// BROADCAST is the broadcast component identifier.
BROADCAST = "broadcast-trusted-state"
)
func main() {
app := cli.NewApp()
app.Name = appName
app.Version = version
flags := []cli.Flag{
&cli.StringFlag{
Name: config.FlagCfg,
Aliases: []string{"c"},
Usage: "Configuration `FILE`",
Required: false,
},
&cli.StringFlag{
Name: config.FlagNetwork,
Aliases: []string{"n"},
Usage: "Network: mainnet, testnet, internaltestnet, local, custom, merge. By default it uses mainnet",
Required: false,
},
&cli.StringFlag{
Name: config.FlagNetworkCfg,
Aliases: []string{"nc"},
Usage: "Custom network configuration `FILE` when using --network custom parameter",
},
&cli.StringFlag{
Name: config.FlagNetworkBase,
Aliases: []string{"nb"},
Usage: "Base existing network configuration to be merged with the custom configuration passed with --network-cfg, by default it uses internaltestnet",
Value: "internaltestnet",
Required: false,
},
&cli.BoolFlag{
Name: config.FlagYes,
Aliases: []string{"y"},
Usage: "Automatically accepts any confirmation to execute the command",
Required: false,
},
&cli.StringSliceFlag{
Name: config.FlagComponents,
Aliases: []string{"co"},
Usage: "List of components to run",
Required: false,
Value: cli.NewStringSlice(AGGREGATOR, SEQUENCER, RPC, SYNCHRONIZER),
},
&cli.StringSliceFlag{
Name: config.FlagHTTPAPI,
Aliases: []string{"ha"},
Usage: fmt.Sprintf("List of JSON RPC apis to be exposed by the server: --http.api=%v,%v,%v,%v,%v,%v", jsonrpc.APIEth, jsonrpc.APINet, jsonrpc.APIDebug, jsonrpc.APIHez, jsonrpc.APITxPool, jsonrpc.APIWeb3),
Required: false,
Value: cli.NewStringSlice(jsonrpc.APIEth, jsonrpc.APINet, jsonrpc.APIHez, jsonrpc.APITxPool, jsonrpc.APIWeb3),
},
}
app.Commands = []*cli.Command{
{
Name: "version",
Aliases: []string{},
Usage: "Application version and build",
Action: versionCmd,
},
{
Name: "run",
Aliases: []string{},
Usage: "Run the zkevm-node",
Action: start,
Flags: flags,
},
{
Name: "approve",
Aliases: []string{"ap"},
Usage: "Approve tokens to be spent by the smart contract",
Action: approveTokens,
Flags: append(flags, &cli.StringFlag{
Name: config.FlagAmount,
Aliases: []string{"am"},
Usage: "Amount that is gonna be approved",
Required: true,
},
),
},
{
Name: "encryptKey",
Aliases: []string{},
Usage: "Encrypts the privatekey with a password and create a keystore file",
Action: encryptKey,
Flags: encryptKeyFlags,
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
os.Exit(1)
}
}