Skip to content

Commit 1c9dab5

Browse files
committed
lightning_client: add peer option to ListChannels
1 parent a91ba5d commit 1c9dab5

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

lightning_client.go

+24-7
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ type LightningClient interface {
118118
opts ...ListTransactionsOption) ([]Transaction, error)
119119

120120
// ListChannels retrieves all channels of the backing lnd node.
121-
ListChannels(ctx context.Context, activeOnly, publicOnly bool) ([]ChannelInfo, error)
121+
ListChannels(ctx context.Context, activeOnly, publicOnly bool,
122+
opts ...ListChannelsOption) ([]ChannelInfo, error)
122123

123124
// PendingChannels returns a list of lnd's pending channels.
124125
PendingChannels(ctx context.Context) (*PendingChannels, error)
@@ -1964,19 +1965,35 @@ func unmarshallTransaction(rpcTx *lnrpc.Transaction) (Transaction, error) {
19641965
}, nil
19651966
}
19661967

1968+
// ListChannelsOption is a functional type for an option that modifies a
1969+
// ListChannelsRequest.
1970+
type ListChannelsOption func(r *lnrpc.ListChannelsRequest)
1971+
1972+
// WithPeer is an option for setting the account on a ListChannelsRequest.
1973+
func WithPeer(peer []byte) ListChannelsOption {
1974+
return func(r *lnrpc.ListChannelsRequest) {
1975+
r.Peer = peer
1976+
}
1977+
}
1978+
19671979
// ListChannels retrieves all channels of the backing lnd node.
19681980
func (s *lightningClient) ListChannels(ctx context.Context, activeOnly,
1969-
publicOnly bool) ([]ChannelInfo, error) {
1981+
publicOnly bool, opts ...ListChannelsOption) ([]ChannelInfo, error) {
19701982

19711983
rpcCtx, cancel := context.WithTimeout(ctx, s.timeout)
19721984
defer cancel()
19731985

1986+
request := &lnrpc.ListChannelsRequest{
1987+
ActiveOnly: activeOnly,
1988+
PublicOnly: publicOnly,
1989+
}
1990+
1991+
for _, opt := range opts {
1992+
opt(request)
1993+
}
1994+
19741995
response, err := s.client.ListChannels(
1975-
s.adminMac.WithMacaroonAuth(rpcCtx),
1976-
&lnrpc.ListChannelsRequest{
1977-
ActiveOnly: activeOnly,
1978-
PublicOnly: publicOnly,
1979-
},
1996+
s.adminMac.WithMacaroonAuth(rpcCtx), request,
19801997
)
19811998
if err != nil {
19821999
return nil, err

0 commit comments

Comments
 (0)