lnd: list active channels in response to listpeers cmd

This commit is contained in:
Olaoluwa Osuntokun 2016-06-22 22:22:40 -07:00
parent e61a03a372
commit 914159cb87
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -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)
}