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
|
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strconv"
"github.com/urfave/cli"
"gitlab.com/byzantine-lab/tan-monitor/monitor"
)
var app *cli.App
func init() {
app = cli.NewApp()
app.Name = filepath.Base(os.Args[0])
app.Usage = "Tangerine Newtwork Monitor"
app.Commands = []cli.Command{
commandStart,
}
}
var commandStart = cli.Command{
Name: "start",
Usage: "Start monitor job",
ArgsUsage: "<networkID> <ethThreshold>",
Description: `Start network monitor with <networkID> and <ethThreshold>
<ethThreshold>'s unit is ETH`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "emailPassword",
Value: "./email.password",
Usage: "Path to the email sender password",
},
cli.StringFlag{
Name: "ccList",
Value: "./cc.txt",
Usage: "Path to the cc list",
},
},
Action: func(ctx *cli.Context) error {
if len(ctx.Args()) != 2 {
log.Fatalf("invalid argument count")
}
networkID, err := strconv.Atoi(ctx.Args()[0])
if err != nil {
panic(err)
}
threshold := ctx.Args()[1]
emailPassword, err := ioutil.ReadFile(ctx.String("emailPassword"))
if err != nil {
panic(err)
}
ccList, _ := ioutil.ReadFile(ctx.String("ccList"))
backend := monitor.NewBlockchainBackend(networkID)
m := monitor.NewMonitor(networkID, backend, threshold)
email := monitor.NewEmail(
"no-reply@byzantine-lab.io",
string(emailPassword),
"smtp-relay.gmail.com",
string(ccList),
)
m.Register(email)
m.Run()
return nil
},
}
func main() {
if err := app.Run(os.Args); err != nil {
fmt.Println("app.Run error:", err)
os.Exit(1)
}
}
|