mirror of https://github.com/edouardparis/lntop
refac network backend
parent
6253b3cb5b
commit
f3900d9105
@ -1,101 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
cli "gopkg.in/urfave/cli.v2"
|
||||
|
||||
"github.com/edouardparis/lntop/app"
|
||||
"github.com/edouardparis/lntop/config"
|
||||
"github.com/edouardparis/lntop/events"
|
||||
"github.com/edouardparis/lntop/logging"
|
||||
"github.com/edouardparis/lntop/pubsub"
|
||||
"github.com/edouardparis/lntop/ui"
|
||||
)
|
||||
|
||||
const version = "v0.1.0"
|
||||
|
||||
// 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",
|
||||
Version: version,
|
||||
EnableShellCompletion: true,
|
||||
Action: run,
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "config",
|
||||
Aliases: []string{"c"},
|
||||
Usage: "path to config file",
|
||||
},
|
||||
},
|
||||
Commands: []*cli.Command{
|
||||
{
|
||||
Name: "pubsub",
|
||||
Aliases: []string{""},
|
||||
Usage: "run the pubsub only",
|
||||
Action: pubsubRun,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func run(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
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
events := make(chan *events.Event)
|
||||
ps := pubsub.New(app.Logger, app.Network)
|
||||
|
||||
go func() {
|
||||
err := ui.Run(ctx, app, events)
|
||||
if err != nil {
|
||||
app.Logger.Debug("ui", logging.String("error", err.Error()))
|
||||
}
|
||||
ps.Stop()
|
||||
}()
|
||||
|
||||
ps.Run(ctx, events)
|
||||
return nil
|
||||
}
|
||||
|
||||
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)
|
||||
ps := pubsub.New(app.Logger, app.Network)
|
||||
ps.Run(context.Background(), events)
|
||||
|
||||
sig := make(chan os.Signal, 1)
|
||||
signal.Notify(sig, os.Interrupt)
|
||||
go func() {
|
||||
<-sig
|
||||
ps.Stop()
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/edouardparis/lntop/network/models"
|
||||
"github.com/edouardparis/lntop/network/options"
|
||||
)
|
||||
|
||||
type Backend interface {
|
||||
Ping() error
|
||||
|
||||
SubscribeInvoice(context.Context, chan *models.Invoice) error
|
||||
|
||||
SubscribeChannels(context.Context, chan *models.ChannelUpdate) error
|
||||
|
||||
NodeName() string
|
||||
|
||||
Info(context.Context) (*models.Info, error)
|
||||
|
||||
GetNode(context.Context, string) (*models.Node, error)
|
||||
|
||||
GetWalletBalance(context.Context) (*models.WalletBalance, error)
|
||||
|
||||
GetChannelsBalance(context.Context) (*models.ChannelsBalance, error)
|
||||
|
||||
ListChannels(context.Context, ...options.Channel) ([]*models.Channel, error)
|
||||
|
||||
GetChannelInfo(context.Context, *models.Channel) error
|
||||
|
||||
CreateInvoice(context.Context, int64, string) (*models.Invoice, error)
|
||||
|
||||
GetInvoice(context.Context, string) (*models.Invoice, error)
|
||||
|
||||
DecodePayReq(context.Context, string) (*models.PayReq, error)
|
||||
|
||||
SendPayment(context.Context, *models.PayReq) (*models.Payment, error)
|
||||
|
||||
GetTransactions(context.Context) ([]*models.Transaction, error)
|
||||
|
||||
SubscribeTransactions(context.Context, chan *models.Transaction) error
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
package version
|
||||
|
||||
const Version = "v0.1.0"
|
Loading…
Reference in New Issue