2019-03-15 15:08:57 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2019-03-15 16:50:16 +00:00
|
|
|
"context"
|
2019-03-15 16:57:09 +00:00
|
|
|
"fmt"
|
2019-03-15 16:50:16 +00:00
|
|
|
|
2019-03-15 15:08:57 +00:00
|
|
|
cli "gopkg.in/urfave/cli.v2"
|
2019-03-15 16:50:16 +00:00
|
|
|
|
2019-03-19 08:54:45 +00:00
|
|
|
"github.com/edouardparis/lntop/app"
|
2019-03-15 16:50:16 +00:00
|
|
|
"github.com/edouardparis/lntop/config"
|
2019-03-26 16:48:58 +00:00
|
|
|
"github.com/edouardparis/lntop/events"
|
2019-03-15 16:50:16 +00:00
|
|
|
"github.com/edouardparis/lntop/logging"
|
|
|
|
"github.com/edouardparis/lntop/network"
|
2019-03-26 16:48:58 +00:00
|
|
|
"github.com/edouardparis/lntop/pubsub"
|
2019-03-18 12:38:14 +00:00
|
|
|
"github.com/edouardparis/lntop/ui"
|
2019-03-15 15:08:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// New creates a new cli app.
|
|
|
|
func New() *cli.App {
|
|
|
|
cli.VersionFlag = &cli.BoolFlag{
|
|
|
|
Name: "version", Aliases: []string{},
|
|
|
|
Usage: "print the version",
|
|
|
|
}
|
|
|
|
|
|
|
|
return &cli.App{
|
|
|
|
Name: "lntop",
|
|
|
|
EnableShellCompletion: true,
|
2019-03-18 12:25:27 +00:00
|
|
|
Action: run,
|
2019-03-15 15:08:57 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "v",
|
|
|
|
Usage: "verbose",
|
|
|
|
},
|
2019-03-15 16:50:16 +00:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "config",
|
|
|
|
Aliases: []string{"c"},
|
|
|
|
Usage: "verbose",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Commands: []*cli.Command{
|
|
|
|
{
|
|
|
|
Name: "wallet-balance",
|
|
|
|
Aliases: []string{""},
|
|
|
|
Usage: "",
|
|
|
|
Action: walletBalance,
|
|
|
|
},
|
2019-03-26 16:48:58 +00:00
|
|
|
{
|
|
|
|
Name: "pubsub",
|
|
|
|
Aliases: []string{""},
|
|
|
|
Usage: "",
|
|
|
|
Action: pubsubRun,
|
|
|
|
},
|
2019-03-15 15:08:57 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2019-03-15 16:50:16 +00:00
|
|
|
|
2019-03-18 12:25:27 +00:00
|
|
|
func run(c *cli.Context) error {
|
2019-03-26 13:02:59 +00:00
|
|
|
cfg, err := config.Load(c.String("config"))
|
2019-03-19 08:54:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-03-26 13:02:59 +00:00
|
|
|
app, err := app.New(cfg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-03-19 13:19:49 +00:00
|
|
|
|
2019-03-29 16:30:48 +00:00
|
|
|
events := make(chan *events.Event)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
err := ui.Run(context.Background(), app, events)
|
|
|
|
if err != nil {
|
|
|
|
app.Logger.Debug("ui", logging.String("error", err.Error()))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
pubsub.Run(context.Background(), app, events)
|
|
|
|
return nil
|
2019-03-18 12:25:27 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 16:48:58 +00:00
|
|
|
func pubsubRun(c *cli.Context) error {
|
|
|
|
cfg, err := config.Load(c.String("config"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
app, err := app.New(cfg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
events := make(chan *events.Event)
|
2019-03-29 16:30:48 +00:00
|
|
|
pubsub.Run(context.Background(), app, events)
|
2019-03-29 16:02:52 +00:00
|
|
|
//ev := <-events
|
|
|
|
//app.Logger.Info("events quit ", logging.String("type", ev.Type))
|
|
|
|
|
|
|
|
return nil
|
2019-03-26 16:48:58 +00:00
|
|
|
}
|
|
|
|
|
2019-03-19 13:19:49 +00:00
|
|
|
func getNetworkFromConfig(c *cli.Context) (*network.Network, error) {
|
2019-03-15 16:50:16 +00:00
|
|
|
cfg, err := config.Load(c.String("config"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-03-19 13:19:49 +00:00
|
|
|
logger := logging.New(config.Logger{Type: "nope"})
|
2019-03-15 16:50:16 +00:00
|
|
|
|
|
|
|
return network.New(&cfg.Network, logger)
|
|
|
|
}
|
|
|
|
|
|
|
|
func walletBalance(c *cli.Context) error {
|
|
|
|
clt, err := getNetworkFromConfig(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-03-15 16:57:09 +00:00
|
|
|
res, err := clt.GetWalletBalance(context.Background())
|
2019-03-15 16:50:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-03-15 16:57:09 +00:00
|
|
|
fmt.Println(res.TotalBalance)
|
|
|
|
|
2019-03-15 16:50:16 +00:00
|
|
|
return nil
|
|
|
|
}
|