diff --git a/lndclient.go b/lndclient.go index d67fbb3..944918f 100644 --- a/lndclient.go +++ b/lndclient.go @@ -255,6 +255,49 @@ func (l *lndclientGrpc) listChannels() (map[uint64]*channel, error) { return chans, nil } +func (l *lndclientGrpc) listClosedChannels() (map[uint64]*channel, error) { + ctx, cancel := context.WithTimeout(ctxb, rpcTimeout) + defer cancel() + + resp, err := l.main.ClosedChannels(ctx, &lnrpc.ClosedChannelsRequest{}) + if err != nil { + return nil, err + } + + chans := make(map[uint64]*channel) + for _, rpcChan := range resp.Channels { + peer, err := route.NewVertexFromStr(rpcChan.RemotePubkey) + if err != nil { + return nil, err + } + + channel := &channel{ + peer: peer, + } + + // LND didn't always store who initiated the channel, so in some cases + // we don't know who initiated the channel (for very old channels). We're + // unlikely to hit this case since we're dealing with channels related + // to current forwards, so we just log that we don't know this value and + // allow initiator to be true. + switch rpcChan.OpenInitiator { + case lnrpc.Initiator_INITIATOR_LOCAL: + channel.initiator = true + + case lnrpc.Initiator_INITIATOR_REMOTE: + + default: + channel.initiator = true + log.Debugf("Channel initiator for %v with %v unknown", + rpcChan.ChanId, peer) + } + + chans[rpcChan.ChanId] = channel + } + + return chans, nil +} + func (l *lndclientGrpc) subscribeHtlcEvents(ctx context.Context) ( htlcEventsClient, error) { diff --git a/lndclient_mock.go b/lndclient_mock.go index 3b73e61..b626510 100644 --- a/lndclient_mock.go +++ b/lndclient_mock.go @@ -50,6 +50,10 @@ func (l *lndclientMock) listChannels() (map[uint64]*channel, error) { return l.channels, nil } +func (l *lndclientMock) listClosedChannels() (map[uint64]*channel, error) { + return make(map[uint64]*channel), nil +} + func (l *lndclientMock) subscribeHtlcEvents(ctx context.Context) ( htlcEventsClient, error) { diff --git a/process.go b/process.go index e03dd2d..c80621b 100644 --- a/process.go +++ b/process.go @@ -26,6 +26,8 @@ type lndclient interface { listChannels() (map[uint64]*channel, error) + listClosedChannels() (map[uint64]*channel, error) + getNodeAlias(key route.Vertex) (string, error) subscribeHtlcEvents(ctx context.Context) (htlcEventsClient, error) diff --git a/stub.go b/stub.go index 3ce3b9a..10fd746 100644 --- a/stub.go +++ b/stub.go @@ -335,6 +335,10 @@ func (s *stubLndClient) listChannels() (map[uint64]*channel, error) { return allChannels, nil } +func (s *stubLndClient) listClosedChannels() (map[uint64]*channel, error) { + return make(map[uint64]*channel), nil +} + func (s *stubLndClient) getNodeAlias(key route.Vertex) (string, error) { peer, ok := s.peers[key] if !ok {