2
0
mirror of https://github.com/guggero/chantools synced 2024-11-15 06:12:49 +00:00
chantools/lnd/graph.go
2023-02-23 11:32:16 +01:00

54 lines
1.0 KiB
Go

package lnd
import (
"fmt"
"github.com/lightningnetwork/lnd/lnrpc"
)
func AllNodeChannels(graph *lnrpc.ChannelGraph,
nodePubKey string) []*lnrpc.ChannelEdge {
var result []*lnrpc.ChannelEdge //nolint:prealloc
for _, edge := range graph.Edges {
if edge.Node1Pub != nodePubKey && edge.Node2Pub != nodePubKey {
continue
}
result = append(result, edge)
}
return result
}
func FindCommonEdges(graph *lnrpc.ChannelGraph, node1,
node2 string) []*lnrpc.ChannelEdge {
var result []*lnrpc.ChannelEdge //nolint:prealloc
for _, edge := range graph.Edges {
if edge.Node1Pub != node1 && edge.Node2Pub != node1 {
continue
}
if edge.Node1Pub != node2 && edge.Node2Pub != node2 {
continue
}
result = append(result, edge)
}
return result
}
func FindNode(graph *lnrpc.ChannelGraph,
nodePubKey string) (*lnrpc.LightningNode, error) {
for _, node := range graph.Nodes {
if node.PubKey == nodePubKey {
return node, nil
}
}
return nil, fmt.Errorf("node %s not found in graph", nodePubKey)
}