Add channel age column

pull/85/head
rkfg 2 years ago
parent 9954fd5704
commit 9cdac2a3d4

@ -82,6 +82,7 @@ columns = [
"UNSETTLED", # the amount unsettled in the channel
"CFEE", # the commit fee
"LAST UPDATE", # last update of the channel
# "AGE", # approximate channel age
"PRIVATE", # true if channel is private
"ID", # the id of the channel
# "SCID", # short channel id (BxTxO formatted)

@ -43,6 +43,7 @@ columns = [
"UNSETTLED", # the amount unsettled in the channel
"CFEE", # the commit fee
"LAST UPDATE", # last update of the channel
# "AGE", # approximate channel age
"PRIVATE", # true if channel is private
"ID", # the id of the channel
# "SCID", # short channel id (BxTxO formatted)

@ -45,6 +45,7 @@ type Channel struct {
TotalAmountReceived int64
UpdatesCount uint64
CSVDelay uint32
Age uint32
Private bool
PendingHTLC []*HTLC
LastUpdate *time.Time

@ -62,6 +62,7 @@ func (m *Models) RefreshChannels(ctx context.Context) error {
if channel != nil &&
(channel.UpdatesCount < channels[i].UpdatesCount ||
channel.LastUpdate == nil || channel.LocalPolicy == nil || channel.RemotePolicy == nil) {
channels[i].Age = m.Info.BlockHeight - uint32(channels[i].ID>>40)
err := m.network.GetChannelInfo(ctx, channels[i])
if err != nil {
return err

@ -40,6 +40,13 @@ func Float64Sort(a, b float64, o Order) bool {
return a > b
}
func UInt32Sort(a, b uint32, o Order) bool {
if o == Asc {
return a < b
}
return a > b
}
func UInt64Sort(a, b uint64, o Order) bool {
if o == Asc {
return a < b

@ -638,6 +638,23 @@ func NewChannels(cfg *config.View, chans *models.Channels) *Channels {
return color.White(opts...)(printer.Sprintf("%7d", val))
},
}
case "AGE":
channels.columns[i] = channelsColumn{
width: 8,
name: fmt.Sprintf("%10s", columns[i]),
sort: func(order models.Order) models.ChannelsSort {
return func(c1, c2 *netmodels.Channel) bool {
return models.UInt32Sort(c1.Age, c2.Age, order)
}
},
display: func(c *netmodels.Channel, opts ...color.Option) string {
if c.ID == 0 {
return fmt.Sprintf("%10s", "")
}
return color.White(opts...)(fmt.Sprintf("%10s", FormatAge(c.Age)))
},
}
default:
channels.columns[i] = channelsColumn{
width: 21,

@ -116,3 +116,19 @@ func ToScid(id uint64) string {
return fmt.Sprintf("%dx%dx%d", blocknum, txnum, outnum)
}
func FormatAge(age uint32) string {
if age < 6 {
return fmt.Sprintf("%02dm", age*10)
}
if age < 144 {
return fmt.Sprintf("%02dh", age/6)
}
if age < 4383 {
return fmt.Sprintf("%02dd%02dh", age/144, (age%144)/6)
}
if age < 52596 {
return fmt.Sprintf("%02dm%02dd%02dh", age/4383, (age%4383)/144, (age%144)/6)
}
return fmt.Sprintf("%02dy%02dm%02dd", age/52596, (age%52596)/4383, (age%4383)/144)
}

Loading…
Cancel
Save