From 40d9f0da3187ef0fa3bc45727ccf5523dd3ca6d9 Mon Sep 17 00:00:00 2001
From: Olaoluwa Osuntokun <laolu32@gmail.com>
Date: Thu, 7 Jul 2016 15:35:58 -0700
Subject: [PATCH] cmd/lncli: implement pendingchannels for the cli client

---
 cmd/lncli/commands.go | 49 +++++++++++++++++++++++++++++++++++++++++++
 cmd/lncli/main.go     |  1 +
 2 files changed, 50 insertions(+)

diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go
index d9902c6f4..b32b06157 100644
--- a/cmd/lncli/commands.go
+++ b/cmd/lncli/commands.go
@@ -388,3 +388,52 @@ func getInfo(ctx *cli.Context) error {
 	printRespJson(resp)
 	return nil
 }
+
+var PendingChannelsCommand = cli.Command{
+	Name:        "pendingchannels",
+	Description: "display information pertaining to pending channels",
+	Usage:       "pendingchannels --status=[all|opening|closing]",
+	Flags: []cli.Flag{
+		cli.BoolFlag{
+			Name:  "open, o",
+			Usage: "display the status of new pending channels",
+		},
+		cli.BoolFlag{
+			Name:  "close, c",
+			Usage: "display the status of channels being closed",
+		},
+		cli.BoolFlag{
+			Name: "all, a",
+			Usage: "display the status of channels in the " +
+				"process of being opened or closed",
+		},
+	},
+	Action: pendingChannels,
+}
+
+func pendingChannels(ctx *cli.Context) error {
+	ctxb := context.Background()
+	client := getClient(ctx)
+
+	var channelStatus lnrpc.ChannelStatus
+	switch {
+	case ctx.Bool("all"):
+		channelStatus = lnrpc.ChannelStatus_ALL
+	case ctx.Bool("open"):
+		channelStatus = lnrpc.ChannelStatus_OPENING
+	case ctx.Bool("close"):
+		channelStatus = lnrpc.ChannelStatus_CLOSING
+	default:
+		channelStatus = lnrpc.ChannelStatus_ALL
+	}
+
+	req := &lnrpc.PendingChannelRequest{channelStatus}
+	resp, err := client.PendingChannels(ctxb, req)
+	if err != nil {
+		return err
+	}
+
+	printRespJson(resp)
+
+	return nil
+}
diff --git a/cmd/lncli/main.go b/cmd/lncli/main.go
index 45917c118..5bee7050a 100644
--- a/cmd/lncli/main.go
+++ b/cmd/lncli/main.go
@@ -58,6 +58,7 @@ func main() {
 		WalletBalanceCommand,
 		ShellCommand,
 		GetInfoCommand,
+		PendingChannelsCommand,
 	}
 
 	if err := app.Run(os.Args); err != nil {