diff --git a/network/backend/lnd/proto.go b/network/backend/lnd/proto.go index da93e44..0f5b2ed 100644 --- a/network/backend/lnd/proto.go +++ b/network/backend/lnd/proto.go @@ -72,9 +72,15 @@ func channelProtoToChannel(c *lnrpc.Channel) *models.Channel { for i := range htlcs { HTLCs[i] = htlcProtoToHTLC(htlcs[i]) } + + status := models.ChannelInactive + if c.Active { + status = models.ChannelActive + } + return &models.Channel{ ID: c.GetChanId(), - Active: c.GetActive(), + Status: status, RemotePubKey: c.GetRemotePubkey(), ChannelPoint: c.GetChannelPoint(), Capacity: c.GetCapacity(), @@ -114,8 +120,15 @@ func pendingChannelsProtoToChannels(r *lnrpc.PendingChannelsResponse) []*models. func openingProtoToChannel(c *lnrpc.PendingChannelsResponse_PendingOpenChannel) *models.Channel { return &models.Channel{ - CommitWeight: c.GetCommitWeight(), - FeePerKiloWeight: c.GetFeePerKw(), + RemotePubKey: c.Channel.RemoteNodePub, + Capacity: c.Channel.Capacity, + LocalBalance: c.Channel.LocalBalance, + RemoteBalance: c.Channel.RemoteBalance, + ChannelPoint: c.Channel.ChannelPoint, + CommitWeight: c.CommitWeight, + CommitFee: c.CommitFee, + ConfirmationHeight: &c.ConfirmationHeight, + FeePerKiloWeight: c.FeePerKw, } } diff --git a/network/models/channel.go b/network/models/channel.go index 567af6b..8bf537d 100644 --- a/network/models/channel.go +++ b/network/models/channel.go @@ -6,6 +6,14 @@ import ( "github.com/edouardparis/lntop/logging" ) +const ( + ChannelActive = iota + 1 + ChannelInactive + ChannelOpening + ChannelClosing + ChannelForceClosing +) + type ChannelsBalance struct { Balance int64 PendingOpenBalance int64 @@ -20,7 +28,7 @@ func (m ChannelsBalance) MarshalLogObject(enc logging.ObjectEncoder) error { type Channel struct { ID uint64 - Active bool + Status int RemotePubKey string ChannelPoint string Capacity int64 @@ -32,6 +40,7 @@ type Channel struct { UnsettledBalance int64 TotalAmountSent int64 TotalAmountReceived int64 + ConfirmationHeight *uint32 UpdatesCount uint64 CSVDelay uint32 Private bool @@ -44,7 +53,7 @@ type Channel struct { func (m Channel) MarshalLogObject(enc logging.ObjectEncoder) error { enc.AddUint64("id", m.ID) - enc.AddBool("active", m.Active) + enc.AddInt("status", m.Status) enc.AddString("remote_pubkey", m.RemotePubKey) enc.AddString("channel_point", m.ChannelPoint) enc.AddInt64("capacity", m.Capacity) diff --git a/ui/models/channels.go b/ui/models/channels.go index 977deb4..f49a027 100644 --- a/ui/models/channels.go +++ b/ui/models/channels.go @@ -42,7 +42,7 @@ func (c *Channels) Update(newChannel *models.Channel) { c.Add(newChannel) return } - oldChannel.Active = newChannel.Active + oldChannel.Status = newChannel.Status oldChannel.LocalBalance = newChannel.LocalBalance oldChannel.RemoteBalance = newChannel.RemoteBalance oldChannel.CommitFee = newChannel.CommitFee diff --git a/ui/views/channels.go b/ui/views/channels.go index 2fa0a38..920ef92 100644 --- a/ui/views/channels.go +++ b/ui/views/channels.go @@ -97,7 +97,7 @@ func (c *Channels) display(v *gocui.View) { v.Clear() for _, item := range c.channels.List() { line := fmt.Sprintf("%s %-20s %s %s %s %5d %15s %d %500s", - active(item), + status(item), alias(item), gauge(item), color.Cyan(p.Sprintf("%12d", item.LocalBalance)), @@ -127,11 +127,20 @@ func lastUpdate(c *netmodels.Channel) string { return "" } -func active(c *netmodels.Channel) string { - if c.Active { +func status(c *netmodels.Channel) string { + switch c.Status { + case netmodels.ChannelActive: return color.Green(fmt.Sprintf("%-9s", "active")) + case netmodels.ChannelInactive: + return color.Red(fmt.Sprintf("%-9s", "inactive")) + case netmodels.ChannelOpening: + return color.Yellow(fmt.Sprintf("%-9s", "opening")) + case netmodels.ChannelClosing: + return color.Yellow(fmt.Sprintf("%-9s", "closing")) + case netmodels.ChannelForceClosing: + return color.Yellow(fmt.Sprintf("%-9s", "closing -f")) } - return color.Red(fmt.Sprintf("%-9s", "inactive")) + return "" } func gauge(c *netmodels.Channel) string { @@ -223,7 +232,7 @@ func (c *Channel) display(v *gocui.View) { channel := c.channel.Item fmt.Fprintln(v, color.Green(" [ Channel ]")) fmt.Fprintln(v, fmt.Sprintf("%s %s", - color.Cyan(" Status:"), active(channel))) + color.Cyan(" Status:"), status(channel))) fmt.Fprintln(v, fmt.Sprintf("%s %d", color.Cyan(" ID:"), channel.ID)) fmt.Fprintln(v, p.Sprintf("%s %d",