rpcserver: add ClosedChannels call
This commit is contained in:
1 parent
f07e2076f8
commit
f80ea51f69
1 file changed
+77
@@ -223,6 +223,10 @@ var (
|
|||||||
Entity: "offchain",
|
Entity: "offchain",
|
||||||
Action: "read",
|
Action: "read",
|
||||||
}},
|
}},
|
||||||
|
"/lnrpc.Lightning/ClosedChannels": {{
|
||||||
|
Entity: "offchain",
|
||||||
|
Action: "read",
|
||||||
|
}},
|
||||||
"/lnrpc.Lightning/SendPayment": {{
|
"/lnrpc.Lightning/SendPayment": {{
|
||||||
Entity: "offchain",
|
Entity: "offchain",
|
||||||
Action: "write",
|
Action: "write",
|
||||||
@@ -1579,6 +1583,79 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClosedChannels returns a list of all the channels have been closed.
|
||||||
|
// This does not include channels that are still in the process of closing.
|
||||||
|
func (r *rpcServer) ClosedChannels(ctx context.Context,
|
||||||
|
in *lnrpc.ClosedChannelsRequest) (*lnrpc.ClosedChannelsResponse,
|
||||||
|
error) {
|
||||||
|
|
||||||
|
// Show all channels when no filter flags are set.
|
||||||
|
filterResults := in.Cooperative || in.LocalForce ||
|
||||||
|
in.RemoteForce || in.Breach || in.FundingCanceled
|
||||||
|
|
||||||
|
resp := &lnrpc.ClosedChannelsResponse{}
|
||||||
|
|
||||||
|
dbChannels, err := r.server.chanDB.FetchClosedChannels(false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, dbChannel := range dbChannels {
|
||||||
|
if dbChannel.IsPending {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
nodePub := dbChannel.RemotePub
|
||||||
|
nodeID := hex.EncodeToString(nodePub.SerializeCompressed())
|
||||||
|
|
||||||
|
var closeType lnrpc.ChannelCloseSummary_ClosureType
|
||||||
|
switch dbChannel.CloseType {
|
||||||
|
case channeldb.CooperativeClose:
|
||||||
|
if filterResults && !in.Cooperative {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
closeType = lnrpc.ChannelCloseSummary_COOPERATIVE_CLOSE
|
||||||
|
case channeldb.LocalForceClose:
|
||||||
|
if filterResults && !in.LocalForce {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
closeType = lnrpc.ChannelCloseSummary_LOCAL_FORCE_CLOSE
|
||||||
|
case channeldb.RemoteForceClose:
|
||||||
|
if filterResults && !in.RemoteForce {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
closeType = lnrpc.ChannelCloseSummary_REMOTE_FORCE_CLOSE
|
||||||
|
case channeldb.BreachClose:
|
||||||
|
if filterResults && !in.Breach {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
closeType = lnrpc.ChannelCloseSummary_BREACH_CLOSE
|
||||||
|
case channeldb.FundingCanceled:
|
||||||
|
if filterResults && !in.FundingCanceled {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
closeType = lnrpc.ChannelCloseSummary_FUNDING_CANCELED
|
||||||
|
}
|
||||||
|
|
||||||
|
channel := &lnrpc.ChannelCloseSummary{
|
||||||
|
Capacity: int64(dbChannel.Capacity),
|
||||||
|
RemotePubkey: nodeID,
|
||||||
|
CloseHeight: dbChannel.CloseHeight,
|
||||||
|
CloseType: closeType,
|
||||||
|
ChannelPoint: dbChannel.ChanPoint.String(),
|
||||||
|
ChanId: dbChannel.ShortChanID.ToUint64(),
|
||||||
|
SettledBalance: int64(dbChannel.SettledBalance),
|
||||||
|
TimeLockedBalance: int64(dbChannel.TimeLockedBalance),
|
||||||
|
ChainHash: dbChannel.ChainHash.String(),
|
||||||
|
ClosingTxHash: dbChannel.ClosingTXID.String(),
|
||||||
|
}
|
||||||
|
|
||||||
|
resp.Channels = append(resp.Channels, channel)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ListChannels returns a description of all the open channels that this node
|
// ListChannels returns a description of all the open channels that this node
|
||||||
// is a participant in.
|
// is a participant in.
|
||||||
func (r *rpcServer) ListChannels(ctx context.Context,
|
func (r *rpcServer) ListChannels(ctx context.Context,
|
||||||
|
|||||||
Reference in new issue
Block a user