2020-09-03 08:36:41 +00:00
|
|
|
package liquidity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/btcsuite/btcutil"
|
2020-09-03 08:36:43 +00:00
|
|
|
"github.com/lightninglabs/lndclient"
|
2020-09-03 08:36:42 +00:00
|
|
|
"github.com/lightningnetwork/lnd/lnwire"
|
2021-02-16 11:31:49 +00:00
|
|
|
"github.com/lightningnetwork/lnd/routing/route"
|
2020-09-03 08:36:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// balances summarizes the state of the balances of a channel. Channel reserve,
|
|
|
|
// fees and pending htlc balances are not included in these balances.
|
|
|
|
type balances struct {
|
|
|
|
// capacity is the total capacity of the channel.
|
|
|
|
capacity btcutil.Amount
|
|
|
|
|
|
|
|
// incoming is the remote balance of the channel.
|
|
|
|
incoming btcutil.Amount
|
|
|
|
|
|
|
|
// outgoing is the local balance of the channel.
|
|
|
|
outgoing btcutil.Amount
|
2020-09-03 08:36:42 +00:00
|
|
|
|
2021-02-16 11:31:51 +00:00
|
|
|
// channels is the channel that has these balances represent. This may
|
|
|
|
// be more than one channel in the case where we are examining a peer's
|
|
|
|
// liquidity as a whole.
|
|
|
|
channels []lnwire.ShortChannelID
|
2021-02-16 11:31:49 +00:00
|
|
|
|
|
|
|
// pubkey is the public key of the peer we have this balances set with.
|
|
|
|
pubkey route.Vertex
|
2020-09-03 08:36:41 +00:00
|
|
|
}
|
2020-09-03 08:36:43 +00:00
|
|
|
|
|
|
|
// newBalances creates a balances struct from lndclient channel information.
|
|
|
|
func newBalances(info lndclient.ChannelInfo) *balances {
|
|
|
|
return &balances{
|
2021-02-16 11:31:51 +00:00
|
|
|
capacity: info.Capacity,
|
|
|
|
incoming: info.RemoteBalance,
|
|
|
|
outgoing: info.LocalBalance,
|
|
|
|
channels: []lnwire.ShortChannelID{
|
|
|
|
lnwire.NewShortChanIDFromInt(info.ChannelID),
|
|
|
|
},
|
|
|
|
pubkey: info.PubKeyBytes,
|
2020-09-03 08:36:43 +00:00
|
|
|
}
|
|
|
|
}
|