lncli: update response handling for open/close channel

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.
This commit is contained in:
Olaoluwa Osuntokun 2016-08-30 16:54:49 -07:00
parent 832fd248cd
commit 9eb2a4219f
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -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
}
}