cmd/lncli: always consume first message for openchannel/closechannel

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.
This commit is contained in:
Olaoluwa Osuntokun 2017-02-07 19:36:15 -08:00
parent a094681dae
commit 926f5c84d0
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

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