From 9eb2a4219f8b3ddbd7b2a03c4e0ce581df934c51 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 30 Aug 2016 16:54:49 -0700 Subject: [PATCH] lncli: update response handling for open/close channel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit updates the response handling of the steaming RPC’s to account for the fact that multiple messages from the server (state updates) can now be sent over the stream instead of a single final update. Currently, all updates other than the “final” update are ignored by the cli. --- cmd/lncli/commands.go | 46 ++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index 08a9f413..2cd6ecfc 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -234,19 +234,22 @@ func openChannel(ctx *cli.Context) error { return err } - txid, err := wire.NewShaHash(resp.ChannelPoint.FundingTxid) - if err != nil { - return err + switch update := resp.Update.(type) { + case *lnrpc.OpenStatusUpdate_ChanOpen: + channelPoint := update.ChanOpen.ChannelPoint + txid, err := wire.NewShaHash(channelPoint.FundingTxid) + if err != nil { + return err + } + + index := channelPoint.OutputIndex + printRespJson(struct { + ChannelPoint string `json:"channel_point"` + }{ + ChannelPoint: fmt.Sprintf("%v:%v", txid, index), + }, + ) } - - index := resp.ChannelPoint.OutputIndex - printRespJson(struct { - ChannelPoint string `json:"channel_point"` - }{ - ChannelPoint: fmt.Sprintf("%v:%v", txid, index), - }, - ) - } return nil @@ -318,7 +321,22 @@ func closeChannel(ctx *cli.Context) error { } else if err != nil { return err } - printRespJson(resp) + + switch update := resp.Update.(type) { + case *lnrpc.CloseStatusUpdate_ChanClose: + closingHash := update.ChanClose.ClosingTxid + txid, err := wire.NewShaHash(closingHash) + if err != nil { + return err + } + + printRespJson(struct { + ClosingTXID string `json:"closing_txid"` + }{ + ClosingTXID: txid.String(), + }) + } + } return nil @@ -522,4 +540,4 @@ func showRoutingTable(ctx *cli.Context) error { printRespJson(resp) return nil -} \ No newline at end of file +}