You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lntop/ui/models/channels.go

82 lines
1.9 KiB
Go

package models
import "github.com/edouardparis/lntop/network/models"
type Channels struct {
index map[uint64]*models.Channel
list []*models.Channel
}
func (c Channels) List() []*models.Channel {
return c.list
}
func (c *Channels) Get(index int) *models.Channel {
if index < 0 || index > len(c.list)-1 {
return nil
}
return c.list[index]
}
func (c *Channels) GetByID(id uint64) *models.Channel {
return c.index[id]
}
func (c Channels) Contains(channel *models.Channel) bool {
_, ok := c.index[channel.ID]
return ok
}
func (c *Channels) Add(channel *models.Channel) {
if c.Contains(channel) {
return
}
c.index[channel.ID] = channel
c.list = append(c.list, channel)
}
func (c *Channels) Update(newChannel *models.Channel) {
oldChannel, ok := c.index[newChannel.ID]
if !ok {
c.Add(newChannel)
return
}
oldChannel.Status = newChannel.Status
oldChannel.LocalBalance = newChannel.LocalBalance
oldChannel.RemoteBalance = newChannel.RemoteBalance
oldChannel.CommitFee = newChannel.CommitFee
oldChannel.CommitWeight = newChannel.CommitWeight
oldChannel.FeePerKiloWeight = newChannel.FeePerKiloWeight
oldChannel.UnsettledBalance = newChannel.UnsettledBalance
oldChannel.TotalAmountSent = newChannel.TotalAmountSent
oldChannel.TotalAmountReceived = newChannel.TotalAmountReceived
oldChannel.UpdatesCount = newChannel.UpdatesCount
oldChannel.CSVDelay = newChannel.CSVDelay
oldChannel.Private = newChannel.Private
oldChannel.PendingHTLC = newChannel.PendingHTLC
if newChannel.LastUpdate != nil {
oldChannel.LastUpdate = newChannel.LastUpdate
}
if newChannel.Policy1 != nil {
oldChannel.Policy1 = newChannel.Policy1
}
if newChannel.Policy2 != nil {
oldChannel.Policy2 = newChannel.Policy2
}
}
func NewChannels() *Channels {
return &Channels{
list: []*models.Channel{},
index: make(map[uint64]*models.Channel),
}
}
type Channel struct {
Item *models.Channel
}