rpcserver: determine which channels to return based on passed params
This commit is contained in:
parent
95997b9c6c
commit
85b03780f3
33
rpcserver.go
33
rpcserver.go
@ -1472,6 +1472,16 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
|
|||||||
func (r *rpcServer) ListChannels(ctx context.Context,
|
func (r *rpcServer) ListChannels(ctx context.Context,
|
||||||
in *lnrpc.ListChannelsRequest) (*lnrpc.ListChannelsResponse, error) {
|
in *lnrpc.ListChannelsRequest) (*lnrpc.ListChannelsResponse, error) {
|
||||||
|
|
||||||
|
if in.ActiveOnly && in.InactiveOnly {
|
||||||
|
return nil, fmt.Errorf("either `active_only` or " +
|
||||||
|
"`inactive_only` can be set, but not both")
|
||||||
|
}
|
||||||
|
|
||||||
|
if in.PublicOnly && in.PrivateOnly {
|
||||||
|
return nil, fmt.Errorf("either `public_only` or " +
|
||||||
|
"`private_only` can be set, but not both")
|
||||||
|
}
|
||||||
|
|
||||||
resp := &lnrpc.ListChannelsResponse{}
|
resp := &lnrpc.ListChannelsResponse{}
|
||||||
|
|
||||||
graph := r.server.chanDB.ChannelGraph()
|
graph := r.server.chanDB.ChannelGraph()
|
||||||
@ -1512,6 +1522,24 @@ func (r *rpcServer) ListChannels(ctx context.Context,
|
|||||||
linkActive = link.EligibleToForward()
|
linkActive = link.EligibleToForward()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Next, we'll determine whether we should add this channel to
|
||||||
|
// our list depending on the type of channels requested to us.
|
||||||
|
isActive := peerOnline && linkActive
|
||||||
|
isPublic := dbChannel.ChannelFlags&lnwire.FFAnnounceChannel != 0
|
||||||
|
|
||||||
|
// We'll only skip returning this channel if we were requested
|
||||||
|
// for a specific kind and this channel doesn't satisfy it.
|
||||||
|
switch {
|
||||||
|
case in.ActiveOnly && !isActive:
|
||||||
|
continue
|
||||||
|
case in.InactiveOnly && isActive:
|
||||||
|
continue
|
||||||
|
case in.PublicOnly && !isPublic:
|
||||||
|
continue
|
||||||
|
case in.PrivateOnly && isPublic:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// As this is required for display purposes, we'll calculate
|
// As this is required for display purposes, we'll calculate
|
||||||
// the weight of the commitment transaction. We also add on the
|
// the weight of the commitment transaction. We also add on the
|
||||||
// estimated weight of the witness to calculate the weight of
|
// estimated weight of the witness to calculate the weight of
|
||||||
@ -1538,8 +1566,9 @@ func (r *rpcServer) ListChannels(ctx context.Context,
|
|||||||
}
|
}
|
||||||
externalCommitFee := dbChannel.Capacity - sumOutputs
|
externalCommitFee := dbChannel.Capacity - sumOutputs
|
||||||
|
|
||||||
channel := &lnrpc.ActiveChannel{
|
channel := &lnrpc.Channel{
|
||||||
Active: peerOnline && linkActive,
|
Active: isActive,
|
||||||
|
Private: !isPublic,
|
||||||
RemotePubkey: nodeID,
|
RemotePubkey: nodeID,
|
||||||
ChannelPoint: chanPoint.String(),
|
ChannelPoint: chanPoint.String(),
|
||||||
ChanId: chanID,
|
ChanId: chanID,
|
||||||
|
Loading…
Reference in New Issue
Block a user