2
0
mirror of https://github.com/guggero/chantools synced 2024-11-03 09:40:19 +00:00
chantools/lnd/graph.go
2021-05-02 15:52:43 +02:00

34 lines
636 B
Go

package lnd
import (
"fmt"
"github.com/lightningnetwork/lnd/lnrpc"
)
func AllNodeChannels(graph *lnrpc.ChannelGraph,
nodePubKey string) []*lnrpc.ChannelEdge {
var result []*lnrpc.ChannelEdge
for _, edge := range graph.Edges {
if edge.Node1Pub != nodePubKey && edge.Node2Pub != nodePubKey {
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)
}