From 926f5c84d03ea6f0f3b3e7b1bd1dc9625521313b Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 7 Feb 2017 19:36:15 -0800 Subject: [PATCH] cmd/lncli: always consume first message for openchannel/closechannel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit modifies the behavior for the commands which open and close channels on the command line. Previsouly a user needed to use the `—block` flag in order to get information about any possible errors or the full progress of a request. This commit alters the behavior slightly to block until the _first_ message or error is returned from the gRPC stream. With this change, the command line usage has a better UX as users instantly get more information without having to peer into the logs. --- cmd/lncli/commands.go | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index 69b3d258..4ef4237c 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -274,10 +274,6 @@ func openChannel(ctx *cli.Context) error { return err } - if !ctx.Bool("block") { - return nil - } - for { resp, err := stream.Recv() if err == io.EOF { @@ -287,6 +283,23 @@ func openChannel(ctx *cli.Context) error { } switch update := resp.Update.(type) { + case *lnrpc.OpenStatusUpdate_ChanPending: + txid, err := chainhash.NewHash(update.ChanPending.Txid) + if err != nil { + return err + } + + printJson(struct { + FundingTxid string `json:"funding_txid"` + }{ + FundingTxid: txid.String(), + }, + ) + + if !ctx.Bool("block") { + return nil + } + case *lnrpc.OpenStatusUpdate_ChanOpen: channelPoint := update.ChanOpen.ChannelPoint txid, err := chainhash.NewHash(channelPoint.FundingTxid) @@ -365,10 +378,6 @@ func closeChannel(ctx *cli.Context) error { return err } - if !ctx.Bool("block") { - return nil - } - for { resp, err := stream.Recv() if err == io.EOF { @@ -378,6 +387,23 @@ func closeChannel(ctx *cli.Context) error { } switch update := resp.Update.(type) { + case *lnrpc.CloseStatusUpdate_ClosePending: + closingHash := update.ClosePending.Txid + txid, err := chainhash.NewHash(closingHash) + if err != nil { + return err + } + + printJson(struct { + ClosingTXID string `json:"closing_txid"` + }{ + ClosingTXID: txid.String(), + }) + + if !ctx.Bool("block") { + return nil + } + case *lnrpc.CloseStatusUpdate_ChanClose: closingHash := update.ChanClose.ClosingTxid txid, err := chainhash.NewHash(closingHash) @@ -391,7 +417,6 @@ func closeChannel(ctx *cli.Context) error { ClosingTXID: txid.String(), }) } - } return nil