cmd/lncli: add --peer flag to list channels

This commit adds a flag to listchannels that filters by remote pubkey.
This commit is contained in:
Conner Fromknecht committed 2020-03-05 20:44:18 -08:00
1 parent c2ec4a450d
commit 11532df5f3
5 files changed
+685 -628

No files matched your search

+21 -2
View File
@@ -1990,6 +1990,12 @@ var listChannelsCommand = cli.Command{
Name: "private_only",
Usage: "only list channels which are currently private",
},
cli.StringFlag{
Name: "peer",
Usage: "(optional) only display channels with a " +
"particular peer, accepts 66-byte, " +
"hex-encoded pubkeys",
},
},
Action: actionDecorator(listChannels),
}
@@ -1999,11 +2005,26 @@ func listChannels(ctx *cli.Context) error {
client, cleanUp := getClient(ctx)
defer cleanUp()
peer := ctx.String("peer")
// If the user requested channels with a particular key, parse the
// provided pubkey.
var peerKey []byte
if len(peer) > 0 {
pk, err := route.NewVertexFromStr(peer)
if err != nil {
return fmt.Errorf("invalid --peer pubkey: %v", err)
}
peerKey = pk[:]
}
req := &lnrpc.ListChannelsRequest{
ActiveOnly: ctx.Bool("active_only"),
InactiveOnly: ctx.Bool("inactive_only"),
PublicOnly: ctx.Bool("public_only"),
PrivateOnly: ctx.Bool("private_only"),
Peer: peerKey,
}
resp, err := client.ListChannels(ctxb, req)
@@ -2011,8 +2032,6 @@ func listChannels(ctx *cli.Context) error {
return err
}
// TODO(roasbeef): defer close the client for the all
printRespJSON(resp)
return nil