-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
90 lines (78 loc) · 2.22 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
package main
import (
"os"
"strings"
"github.com/indexooor/core/indexooor"
"github.com/urfave/cli/v2"
log "github.com/inconshreveable/log15"
)
var (
indexCommand = &cli.Command{
Name: "index",
Usage: "Index a contract",
Action: startIndexing,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "rpc",
Usage: "RPC endpoint of the node",
Value: "http://localhost:8545",
DefaultText: "http://localhost:8545",
Required: true,
},
&cli.StringFlag{
Name: "contract-addresses",
Usage: "Contract address (comma seperated for multiple contracts)",
Value: "",
DefaultText: "",
Required: true,
},
&cli.Int64Flag{
Name: "start-block",
Usage: "Block to start indexing from",
Value: 0,
DefaultText: "0",
},
&cli.Int64Flag{
Name: "run-id",
Usage: "Run ID to start indexing from block where left off",
Value: 0,
DefaultText: "0",
},
&cli.BoolFlag{
Name: "debug",
Usage: "Enable debug logs",
Value: false,
DefaultText: "false",
},
},
}
)
func main() {
// Visit https://cli.urfave.org/v2/examples/flags/ for references
app := cli.NewApp()
app.Name = "Indexooor"
app.Usage = "A command-line utility to interact with the indexer service"
app.Commands = []*cli.Command{
indexCommand,
}
if err := app.Run(os.Args); err != nil {
log.Error("Error in indexer service, exiting", "err", err)
os.Exit(1)
}
}
func startIndexing(ctx *cli.Context) error {
startBlock := ctx.Uint64("start-block")
rpc := ctx.String("rpc")
runId := ctx.Uint64("run-id")
if ctx.Bool("debug") {
log.Root().SetHandler(log.LvlFilterHandler(4, log.StreamHandler(os.Stderr, log.TerminalFormat())))
}
// split string by comma
contractAddresses := strings.Split(ctx.String("contract-addresses"), ",")
for i, contractAddress := range contractAddresses {
contractAddresses[i] = strings.TrimSpace(contractAddress)
}
log.Info("Indexoooor goes vrooom vrooom 🚀🚀")
log.Info("Starting to index", "contracts", contractAddresses, "start block", startBlock, "rpc", rpc, "run-id", runId)
return indexooor.StartIndexing(rpc, startBlock, contractAddresses, runId, nil)
}