network: pending channels

pull/1/head
Edouard Paris 5 years ago
parent f4a930d2e6
commit c8fad86d94

@ -109,17 +109,40 @@ func htlcProtoToHTLC(h *lnrpc.HTLC) *models.HTLC {
} }
func pendingChannelsProtoToChannels(r *lnrpc.PendingChannelsResponse) []*models.Channel { func pendingChannelsProtoToChannels(r *lnrpc.PendingChannelsResponse) []*models.Channel {
resp := r.GetPendingOpenChannels() respPending := r.GetPendingOpenChannels()
channels := make([]*models.Channel, len(resp)) pending := make([]*models.Channel, len(respPending))
for i := range resp { for i := range respPending {
channels[i] = openingProtoToChannel(resp[i]) pending[i] = openingChannelProtoToChannel(respPending[i])
} }
return channels respClosing := r.GetPendingClosingChannels()
closing := make([]*models.Channel, len(respClosing))
for i := range respClosing {
closing[i] = closingChannelProtoToChannel(respClosing[i])
}
channels := append(pending, closing...)
respForceClosing := r.GetPendingForceClosingChannels()
forceClosing := make([]*models.Channel, len(respForceClosing))
for i := range respForceClosing {
forceClosing[i] = forceClosingChannelProtoToChannel(respForceClosing[i])
}
channels = append(channels, forceClosing...)
respWaitingClose := r.GetWaitingCloseChannels()
waitingClose := make([]*models.Channel, len(respWaitingClose))
for i := range respWaitingClose {
waitingClose[i] = waitingCloseChannelProtoToChannel(respWaitingClose[i])
}
return append(channels, waitingClose...)
} }
func openingProtoToChannel(c *lnrpc.PendingChannelsResponse_PendingOpenChannel) *models.Channel { func openingChannelProtoToChannel(c *lnrpc.PendingChannelsResponse_PendingOpenChannel) *models.Channel {
return &models.Channel{ return &models.Channel{
Status: models.ChannelOpening,
RemotePubKey: c.Channel.RemoteNodePub, RemotePubKey: c.Channel.RemoteNodePub,
Capacity: c.Channel.Capacity, Capacity: c.Channel.Capacity,
LocalBalance: c.Channel.LocalBalance, LocalBalance: c.Channel.LocalBalance,
@ -132,6 +155,39 @@ func openingProtoToChannel(c *lnrpc.PendingChannelsResponse_PendingOpenChannel)
} }
} }
func closingChannelProtoToChannel(c *lnrpc.PendingChannelsResponse_ClosedChannel) *models.Channel {
return &models.Channel{
Status: models.ChannelClosing,
RemotePubKey: c.Channel.RemoteNodePub,
Capacity: c.Channel.Capacity,
LocalBalance: c.Channel.LocalBalance,
RemoteBalance: c.Channel.RemoteBalance,
ChannelPoint: c.Channel.ChannelPoint,
}
}
func forceClosingChannelProtoToChannel(c *lnrpc.PendingChannelsResponse_ForceClosedChannel) *models.Channel {
return &models.Channel{
Status: models.ChannelClosing,
RemotePubKey: c.Channel.RemoteNodePub,
Capacity: c.Channel.Capacity,
LocalBalance: c.Channel.LocalBalance,
RemoteBalance: c.Channel.RemoteBalance,
ChannelPoint: c.Channel.ChannelPoint,
}
}
func waitingCloseChannelProtoToChannel(c *lnrpc.PendingChannelsResponse_WaitingCloseChannel) *models.Channel {
return &models.Channel{
Status: models.ChannelWaitingClose,
RemotePubKey: c.Channel.RemoteNodePub,
Capacity: c.Channel.Capacity,
LocalBalance: c.Channel.LocalBalance,
RemoteBalance: c.Channel.RemoteBalance,
ChannelPoint: c.Channel.ChannelPoint,
}
}
func payreqProtoToPayReq(h *lnrpc.PayReq, payreq string) *models.PayReq { func payreqProtoToPayReq(h *lnrpc.PayReq, payreq string) *models.PayReq {
if h == nil { if h == nil {
return nil return nil

@ -12,6 +12,7 @@ const (
ChannelOpening ChannelOpening
ChannelClosing ChannelClosing
ChannelForceClosing ChannelForceClosing
ChannelWaitingClose
) )
type ChannelsBalance struct { type ChannelsBalance struct {

@ -10,9 +10,7 @@ type ChannelOptions struct {
Pending bool Pending bool
} }
func WithChannelPending() Channel { func WithChannelPending(c *ChannelOptions) { c.Pending = true }
return func(c *ChannelOptions) { c.Pending = true }
}
func WithChannelPublic(v bool) Channel { func WithChannelPublic(v bool) Channel {
return func(c *ChannelOptions) { c.Public = v } return func(c *ChannelOptions) { c.Public = v }

@ -70,25 +70,43 @@ func (c *controller) SetModels(ctx context.Context) error {
func (c *controller) Listen(ctx context.Context, g *gocui.Gui, sub chan *events.Event) { func (c *controller) Listen(ctx context.Context, g *gocui.Gui, sub chan *events.Event) {
c.logger.Debug("Listening...") c.logger.Debug("Listening...")
refresh := func(fn ...func(context.Context) error) {
for i := range fn {
err := fn[i](ctx)
if err != nil {
c.logger.Error("failed", logging.Error(err))
}
}
}
for event := range sub { for event := range sub {
var err error c.logger.Debug("event received", logging.String("type", event.Type))
switch event.Type { switch event.Type {
case events.BlockReceived: case events.BlockReceived:
err = c.models.RefreshInfo(ctx) refresh(c.models.RefreshInfo)
case events.ChannelPending: case events.ChannelPending:
err = c.models.RefreshInfo(ctx) refresh(
c.models.RefreshInfo,
c.models.RefreshChannelsBalance,
c.models.RefreshChannels,
)
case events.ChannelActive: case events.ChannelActive:
err = c.models.RefreshInfo(ctx) refresh(
c.models.RefreshInfo,
c.models.RefreshChannelsBalance,
c.models.RefreshChannels,
)
case events.ChannelInactive: case events.ChannelInactive:
err = c.models.RefreshInfo(ctx) refresh(
c.models.RefreshInfo,
c.models.RefreshChannelsBalance,
c.models.RefreshChannels,
)
case events.PeerUpdated: case events.PeerUpdated:
err = c.models.RefreshInfo(ctx) refresh(c.models.RefreshInfo)
default: default:
c.logger.Info("event received", logging.String("type", event.Type)) c.logger.Info("event received", logging.String("type", event.Type))
} }
if err != nil {
c.logger.Error("failed", logging.String("event", event.Type))
}
} }
} }

@ -5,6 +5,7 @@ import (
"github.com/edouardparis/lntop/app" "github.com/edouardparis/lntop/app"
"github.com/edouardparis/lntop/network/models" "github.com/edouardparis/lntop/network/models"
"github.com/edouardparis/lntop/network/options"
) )
type Models struct { type Models struct {
@ -41,7 +42,7 @@ func (m *Models) RefreshInfo(ctx context.Context) error {
} }
func (m *Models) RefreshChannels(ctx context.Context) error { func (m *Models) RefreshChannels(ctx context.Context) error {
channels, err := m.App.Network.ListChannels(ctx) channels, err := m.App.Network.ListChannels(ctx, options.WithChannelPending)
if err != nil { if err != nil {
return err return err
} }

@ -80,7 +80,7 @@ func (c *Channels) Set(g *gocui.Gui, x0, y0, x1, y1 int) error {
func displayChannelsColumns(v *gocui.View) { func displayChannelsColumns(v *gocui.View) {
v.Clear() v.Clear()
fmt.Fprintln(v, fmt.Sprintf("%-9s %-20s %-21s %12s %12s %5s %-15s %s", fmt.Fprintln(v, fmt.Sprintf("%-13s %-20s %-21s %12s %12s %5s %-15s %s",
"STATUS", "STATUS",
"ALIAS", "ALIAS",
"GAUGE", "GAUGE",
@ -130,15 +130,17 @@ func lastUpdate(c *netmodels.Channel) string {
func status(c *netmodels.Channel) string { func status(c *netmodels.Channel) string {
switch c.Status { switch c.Status {
case netmodels.ChannelActive: case netmodels.ChannelActive:
return color.Green(fmt.Sprintf("%-9s", "active")) return color.Green(fmt.Sprintf("%-13s", "active"))
case netmodels.ChannelInactive: case netmodels.ChannelInactive:
return color.Red(fmt.Sprintf("%-9s", "inactive")) return color.Red(fmt.Sprintf("%-13s", "inactive"))
case netmodels.ChannelOpening: case netmodels.ChannelOpening:
return color.Yellow(fmt.Sprintf("%-9s", "opening")) return color.Yellow(fmt.Sprintf("%-13s", "opening"))
case netmodels.ChannelClosing: case netmodels.ChannelClosing:
return color.Yellow(fmt.Sprintf("%-9s", "closing")) return color.Yellow(fmt.Sprintf("%-13s", "closing"))
case netmodels.ChannelForceClosing: case netmodels.ChannelForceClosing:
return color.Yellow(fmt.Sprintf("%-9s", "closing -f")) return color.Yellow(fmt.Sprintf("%-13s", "force closing"))
case netmodels.ChannelWaitingClose:
return color.Yellow(fmt.Sprintf("%-13s", "waiting close"))
} }
return "" return ""
} }

Loading…
Cancel
Save