-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
76 lines (64 loc) · 1.84 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
package main
import (
"flag"
"github.com/go-echarts/go-echarts/v2/components"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/macaroons"
"github.com/philipglazman/lnviz/data"
"github.com/philipglazman/lnviz/report"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"gopkg.in/macaroon.v2"
"io"
"io/ioutil"
"log"
"os"
)
func main() {
/* ------ Flags ------ */
var certFile string
var macaroonFile string
var node string
flag.StringVar(&certFile, "cert", "", "path to file containing TLS certificate for LND node")
flag.StringVar(&macaroonFile, "macaroon", "", "path to file containing macaroon for LND node")
flag.StringVar(&node, "host", "", "host:port of LND node")
flag.Parse()
// Connect to lightning client.
nodeTLS, err := credentials.NewClientTLSFromFile(certFile, "")
if err != nil {
log.Fatal(err)
}
macaroonBytes, err := ioutil.ReadFile(macaroonFile)
if err != nil {
log.Fatal(err)
}
nodeMacaroon := macaroon.Macaroon{}
if err := nodeMacaroon.UnmarshalBinary(macaroonBytes); err != nil {
log.Fatal(err)
}
options := []grpc.DialOption{
grpc.WithTransportCredentials(nodeTLS),
grpc.WithPerRPCCredentials(macaroons.NewMacaroonCredential(&nodeMacaroon)),
}
conn, err := grpc.Dial(node, options...)
if err != nil {
log.Fatal(err)
}
client := lnrpc.NewLightningClient(conn)
events, nodes, err := data.BuildData(client)
if err != nil {
log.Fatal(err)
}
f, _ := os.Create("report.html")
// Create report.
if err := components.NewPage().AddCharts(
report.DailyRoutesProcessed(events),
report.DailyRouteFees(events),
report.DailyRoutingVolume(events),
report.RouteFeePerChanOut(events, nodes),
report.RouteFeePerChanIn(events, nodes),
report.CumulativeRoutingFees(events),
).SetLayout(components.PageFlexLayout).Render(io.MultiWriter(f)); err != nil {
return
}
}