cmd/lncli: add --peer flag to list channels

This commit adds a flag to listchannels that filters by remote pubkey.
This commit is contained in:
Conner Fromknecht
2020-03-03 05:11:33 -08:00
parent c2ec4a450d
commit 11532df5f3
5 changed files with 685 additions and 628 deletions

View File

@@ -2948,6 +2948,11 @@ func (r *rpcServer) ListChannels(ctx context.Context,
"`private_only` can be set, but not both")
}
if len(in.Peer) > 0 && len(in.Peer) != 33 {
_, err := route.NewVertexFromBytes(in.Peer)
return nil, fmt.Errorf("invalid `peer` key: %v", err)
}
resp := &lnrpc.ListChannelsResponse{}
graph := r.server.chanDB.ChannelGraph()
@@ -2962,8 +2967,15 @@ func (r *rpcServer) ListChannels(ctx context.Context,
for _, dbChannel := range dbChannels {
nodePub := dbChannel.IdentityPub
nodePubBytes := nodePub.SerializeCompressed()
chanPoint := dbChannel.FundingOutpoint
// If the caller requested channels for a target node, skip any
// that don't match the provided pubkey.
if len(in.Peer) > 0 && !bytes.Equal(nodePubBytes, in.Peer) {
continue
}
var peerOnline bool
if _, err := r.server.FindPeer(nodePub); err == nil {
peerOnline = true