ft network: Info

pull/1/head
Edouard Paris 5 years ago
parent e918c13c49
commit bd04cacf4e

@ -12,6 +12,8 @@ type Backend interface {
NodeName() string
Info(ctx context.Context) (*models.Info, error)
GetWalletBalance(context.Context) (*models.WalletBalance, error)
GetChannelBalance(context.Context) (*models.ChannelBalance, error)

@ -39,6 +39,20 @@ func (l Backend) NodeName() string {
return l.cfg.ID
}
func (l Backend) Info(ctx context.Context) (*models.Info, error) {
clt, err := l.Client(ctx)
if err != nil {
return nil, err
}
resp, err := clt.GetInfo(ctx, &lnrpc.GetInfoRequest{})
if err != nil {
return nil, err
}
return infoProtoToInfo(resp), nil
}
func (l Backend) SubscribeInvoice(ctx context.Context, channelInvoice chan *models.Invoice) error {
clt, err := l.Client(ctx)
if err != nil {

@ -139,3 +139,22 @@ func sendPaymentProtoToPayment(payreq *models.PayReq, resp *lnrpc.SendResponse)
return payment
}
func infoProtoToInfo(resp *lnrpc.GetInfoResponse) *models.Info {
if resp == nil {
return nil
}
return &models.Info{
PubKey: resp.IdentityPubkey,
Alias: resp.Alias,
NumPendingChannels: resp.NumPendingChannels,
NumActiveChannels: resp.NumActiveChannels,
NumInactiveChannels: resp.NumInactiveChannels,
NumPeers: resp.NumPeers,
BlockHeight: resp.BlockHeight,
BlockHash: resp.BlockHash,
Synced: resp.SyncedToChain,
Version: resp.Version,
}
}

@ -22,6 +22,10 @@ type Backend struct {
sync.RWMutex
}
func (b *Backend) Info(ctx context.Context) (*models.Info, error) {
return nil, nil
}
func (l *Backend) SendPayment(ctx context.Context, payreq *models.PayReq) (*models.Payment, error) {
return nil, nil
}

@ -0,0 +1,22 @@
package models
import "github.com/edouardparis/lntop/logging"
type Info struct {
PubKey string
Alias string
NumPendingChannels uint32
NumActiveChannels uint32
NumInactiveChannels uint32
NumPeers uint32
BlockHeight uint32
BlockHash string
Synced bool
Version string
}
func (i Info) MarshalLogObject(enc logging.ObjectEncoder) error {
enc.AddString("pubkey", i.PubKey)
enc.AddString("Alias", i.Alias)
return nil
}

@ -53,11 +53,12 @@ func (c *Channels) Set(g *gocui.Gui, x0, y0, x1, y1 int) error {
}
func displayChannelsColumns(v *gocui.View) {
fmt.Fprintln(v, fmt.Sprintf("%-9s %-26s %12s %12s",
fmt.Fprintln(v, fmt.Sprintf("%-9s %-26s %12s %12s %5s",
"Status",
"Gauge",
"Local",
"Capacity",
"pHTLC",
))
}
@ -68,11 +69,12 @@ func (c *Channels) Update(items []*models.Channel) {
func (c *Channels) display() {
c.Clear()
for _, item := range c.items {
line := fmt.Sprintf("%s %s %s %12d",
line := fmt.Sprintf("%s %s %s %12d %5d",
active(item),
gauge(item),
color.Cyan(fmt.Sprintf("%12d", item.LocalBalance)),
item.Capacity,
len(item.PendingHTLC),
)
fmt.Fprintln(c.View, line)
}

Loading…
Cancel
Save