-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.go
More file actions
50 lines (38 loc) · 1.21 KB
/
commands.go
File metadata and controls
50 lines (38 loc) · 1.21 KB
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
package poller
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/urfave/cli"
)
func PollAction(cliCtx *cli.Context) error {
var err error
wsRPCEndpoint := cliCtx.Args().Get(0)
dbConnectionString := cliCtx.Args().Get(1)
trackedAddresses := []string{}
if cliCtx.Args().Get(2) != "" {
trackedAddresses, err = GetTrackedAddressesFromFile(cliCtx.Args().Get(2))
if err != nil {
return err
}
}
poller := new(Poller)
err = poller.Initialize(wsRPCEndpoint, dbConnectionString, trackedAddresses)
if err != nil {
return err
}
go poller.Poll()
log.Println("Listening for new blocks...")
signalChannel := make(chan os.Signal, 1)
signal.Notify(signalChannel, syscall.SIGTERM)
signal.Notify(signalChannel, syscall.SIGINT)
<-signalChannel
return nil
}
var PollCommand = cli.Command{
Name: "poll",
Usage: "Listens for new blocks on the provided websocket RPC endpoint and indexes them to the provided PostgreSQL connection. Optionally accepts a JSON array of hex addresses for which to index balances.",
ArgsUsage: "Provide a websocket RPC endpoint, a PostgreSQL connection string, and, optionally, a path to a JSON file containing an array of hex addresses to track.",
Action: PollAction,
}