From 914159cb87e0700d8e795098137ffadc3f74d73d Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 22 Jun 2016 22:22:40 -0700 Subject: [PATCH] lnd: list active channels in response to `listpeers` cmd --- rpcserver.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/rpcserver.go b/rpcserver.go index 14c2aa52..50ae2d50 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -222,8 +222,10 @@ func (r *rpcServer) ListPeers(ctx context.Context, for _, serverPeer := range serverPeers { // TODO(roasbeef): add a snapshot method which grabs peer read mtx + + lnID := hex.EncodeToString(serverPeer.lightningID[:]) peer := &lnrpc.Peer{ - LightningId: hex.EncodeToString(serverPeer.lightningID[:]), + LightningId: lnID, PeerId: serverPeer.id, Address: serverPeer.conn.RemoteAddr().String(), Inbound: serverPeer.inbound, @@ -231,6 +233,20 @@ func (r *rpcServer) ListPeers(ctx context.Context, BytesSent: atomic.LoadUint64(&serverPeer.bytesSent), } + chanSnapshots := serverPeer.ChannelSnapshots() + peer.Channels = make([]*lnrpc.ActiveChannel, 0, len(chanSnapshots)) + for _, chanSnapshot := range chanSnapshots { + channel := &lnrpc.ActiveChannel{ + RemoteId: lnID, + ChannelPoint: chanSnapshot.ChannelPoint.String(), + Capacity: int64(chanSnapshot.Capacity), + LocalBalance: int64(chanSnapshot.LocalBalance), + RemoteBalance: int64(chanSnapshot.RemoteBalance), + NumUpdates: chanSnapshot.NumUpdates, + } + peer.Channels = append(peer.Channels, channel) + } + resp.Peers = append(resp.Peers, peer) }