rpcserver: add channels to GetNodeInfo response

This commit is contained in:
chokoboko 2018-12-10 17:37:08 +02:00
parent 6cd71b7f7a
commit 51dc422721
4 changed files with 531 additions and 491 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1735,8 +1735,14 @@ message NodeInfo {
*/
LightningNode node = 1 [json_name = "node"];
/// The total number of channels for the node.
uint32 num_channels = 2 [json_name = "num_channels"];
/// The sum of all channels capacity for the node, denominated in satoshis.
int64 total_capacity = 3 [json_name = "total_capacity"];
/// A list of all public channels for the node.
repeated ChannelEdge channels = 4 [json_name = "channels"];
}
/**

View File

@ -2617,11 +2617,20 @@
},
"num_channels": {
"type": "integer",
"format": "int64"
"format": "int64",
"description": "/ The total number of channels for the node."
},
"total_capacity": {
"type": "string",
"format": "int64"
"format": "int64",
"description": "/ The sum of all channels capacity for the node, denominated in satoshis."
},
"channels": {
"type": "array",
"items": {
"$ref": "#/definitions/lnrpcChannelEdge"
},
"description": "/ A list of all public channels for the node."
}
}
},

View File

@ -3820,12 +3820,25 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
var (
numChannels uint32
totalCapacity btcutil.Amount
channels []*lnrpc.ChannelEdge
)
if err := node.ForEachChannel(nil, func(_ *bbolt.Tx, edge *channeldb.ChannelEdgeInfo,
_, _ *channeldb.ChannelEdgePolicy) error {
c1, c2 *channeldb.ChannelEdgePolicy) error {
numChannels++
totalCapacity += edge.Capacity
// Do not include unannounced channels - private channels or public
// channels whose authentication proof were not confirmed yet.
if edge.AuthProof == nil {
return nil
}
// Convert the database's edge format into the network/RPC edge format.
channelEdge := marshalDbEdge(edge, c1, c2)
channels = append(channels, channelEdge)
return nil
}); err != nil {
return nil, err
@ -3839,7 +3852,6 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
}
nodeAddrs = append(nodeAddrs, nodeAddr)
}
// TODO(roasbeef): list channels as well?
return &lnrpc.NodeInfo{
Node: &lnrpc.LightningNode{
@ -3851,6 +3863,7 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
},
NumChannels: numChannels,
TotalCapacity: int64(totalCapacity),
Channels: channels,
}, nil
}