forked from smartcontractkit/chainlink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
191 lines (184 loc) · 4.86 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
package main
import (
"fmt"
"os"
"time"
"github.com/smartcontractkit/chainlink/cmd"
"github.com/smartcontractkit/chainlink/logger"
"github.com/smartcontractkit/chainlink/store"
"github.com/urfave/cli"
)
//go:generate sh -c "CGO_ENABLED=0 go run gui/main.go $PWD"
func init() {
time.LoadLocation("UTC")
}
func main() {
Run(NewProductionClient(), os.Args...)
}
// Run runs the CLI, providing further command instructions by default.
func Run(client *cmd.Client, args ...string) {
app := cli.NewApp()
app.Usage = "CLI for Chainlink"
app.Version = fmt.Sprintf("%v@%v", store.Version, store.Sha)
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "json, j",
Usage: "json output as opposed to table",
},
}
app.Before = func(c *cli.Context) error {
if c.Bool("json") {
client.Renderer = cmd.RendererJSON{Writer: os.Stdout}
}
return nil
}
app.Commands = []cli.Command{
{
Name: "node",
Aliases: []string{"n"},
Flags: []cli.Flag{
cli.StringFlag{
Name: "api, a",
Usage: "text file holding the API email and password, each on a line",
},
cli.StringFlag{
Name: "password, p",
Usage: "text file holding the password for the node's account",
},
cli.BoolFlag{
Name: "debug, d",
Usage: "set logger level to debug",
},
},
Usage: "Run the chainlink node",
Action: client.RunNode,
},
{
Name: "deleteuser",
Usage: "Erase the *local node's* user and corresponding session to force recreation on next node launch. Does not work remotely over API.",
Action: client.DeleteUser,
},
{
Name: "login",
Usage: "Login to remote client by creating a session cookie",
Action: client.RemoteLogin,
Flags: []cli.Flag{
cli.StringFlag{
Name: "file, f",
Usage: "text file holding the API email and password needed to create a session cookie",
},
},
},
{
Name: "account",
Aliases: []string{"a"},
Usage: "Display the account address with its ETH & LINK balances",
Action: client.DisplayAccountBalance,
},
{
Name: "jobspecs",
Aliases: []string{"jobs", "j", "specs"},
Usage: "Get all jobs",
Action: client.GetJobSpecs,
Flags: []cli.Flag{
cli.IntFlag{
Name: "page",
Usage: "page of results to display",
},
},
},
{
Name: "show",
Aliases: []string{"s"},
Usage: "Show a specific job",
Action: client.ShowJobSpec,
},
{
Name: "create",
Aliases: []string{"c"},
Usage: "Create job spec from JSON",
Action: client.CreateJobSpec,
},
{
Name: "run",
Aliases: []string{"r"},
Usage: "Begin job run for specid",
Action: client.CreateJobRun,
},
{
Name: "backup",
Usage: "Backup the database of the running node",
Action: client.BackupDatabase,
},
{
Name: "import",
Aliases: []string{"i"},
Usage: "Import a key file to use with the node",
Action: client.ImportKey,
},
{
Name: "bridge",
Usage: "Add a new bridge to the node",
Action: client.AddBridge,
},
{
Name: "getbridges",
Usage: "List all bridges added to the node",
Action: client.GetBridges,
Flags: []cli.Flag{
cli.IntFlag{
Name: "page",
Usage: "page of results to display",
},
},
},
{
Name: "showbridge",
Usage: "Show a specific bridge",
Action: client.ShowBridge,
},
{
Name: "removebridge",
Usage: "Removes a specific bridge",
Action: client.RemoveBridge,
},
{
Name: "agree",
Aliases: []string{"createsa"},
Usage: "Creates a service agreement",
Action: client.CreateServiceAgreement,
},
{
Name: "withdraw",
Aliases: []string{"w"},
Usage: "Withdraw LINK to an authorized address",
Action: client.Withdraw,
},
{
Name: "chpass",
Usage: "Change your password",
Action: client.ChangePassword,
},
}
logger.WarnIf(app.Run(args))
}
// NewProductionClient configures an instance of the CLI to be used
// in production.
func NewProductionClient() *cmd.Client {
cfg := store.NewConfig()
prompter := cmd.NewTerminalPrompter()
cookieAuth := cmd.NewSessionCookieAuthenticator(cfg, cmd.DiskCookieStore{Config: cfg})
return &cmd.Client{
Renderer: cmd.RendererTable{Writer: os.Stdout},
Config: cfg,
AppFactory: cmd.ChainlinkAppFactory{},
KeyStoreAuthenticator: cmd.TerminalKeyStoreAuthenticator{Prompter: prompter},
FallbackAPIInitializer: cmd.NewPromptingAPIInitializer(prompter),
Runner: cmd.ChainlinkRunner{},
HTTP: cmd.NewAuthenticatedHTTPClient(cfg, cookieAuth),
CookieAuthenticator: cookieAuth,
FileSessionRequestBuilder: cmd.NewFileSessionRequestBuilder(),
PromptingSessionRequestBuilder: cmd.NewPromptingSessionRequestBuilder(prompter),
ChangePasswordPrompter: cmd.NewChangePasswordPrompter(),
}
}