Skip to content

Commit

Permalink
lncli: use OpenChannelSync.
Browse files Browse the repository at this point in the history
For the non-blocking case we use the the synchronous channel
opening call now.
  • Loading branch information
ziggie1984 committed Jul 11, 2024
1 parent e1e145b commit cef9954
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions cmd/lncli/cmd_open_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,20 @@ func openChannel(ctx *cli.Context) error {
"combination with the --psbt flag")
}

// In case we dont want to wait until the channel is fully confirmed
// onchain we use the `OpenChannelSync` rpc call.
if !ctx.Bool("block") {
pendingChan, err := client.OpenChannelSync(ctxc, req)
if err != nil {
return err
}

err = printPendingChan(pendingChan)
if err != nil {
return err
}
}

stream, err := client.OpenChannel(ctxc, req)
if err != nil {
return err
Expand All @@ -480,10 +494,6 @@ func openChannel(ctx *cli.Context) error {
return err
}

if !ctx.Bool("block") {
return nil
}

case *lnrpc.OpenStatusUpdate_ChanOpen:
return printChanOpen(update)
}
Expand Down Expand Up @@ -953,6 +963,37 @@ func printChanOpen(update *lnrpc.OpenStatusUpdate_ChanOpen) error {
return nil
}

// printPendingChan prints the funding txID of the pending channel opening.
func printPendingChan(pendingChan *lnrpc.ChannelPoint) error {
var txidHash []byte

switch pendingChan.GetFundingTxid().(type) {
case *lnrpc.ChannelPoint_FundingTxidBytes:
txidHash = pendingChan.GetFundingTxidBytes()
case *lnrpc.ChannelPoint_FundingTxidStr:
s := pendingChan.GetFundingTxidStr()
h, err := chainhash.NewHashFromStr(s)
if err != nil {
return err
}

txidHash = h[:]
}

txID, err := chainhash.NewHash(txidHash)
if err != nil {
return err
}

printJSON(struct {
FundingTxid string `json:"funding_txid"`
}{
FundingTxid: txID.String(),
})

return nil
}

// printChanPending prints the funding transaction ID of the channel pending
// message.
func printChanPending(update *lnrpc.OpenStatusUpdate_ChanPending) error {
Expand Down

0 comments on commit cef9954

Please sign in to comment.