From 011568bdc2cd6bc93ba85010e880aa0b58f605f9 Mon Sep 17 00:00:00 2001 From: Slyghtning Date: Mon, 9 Mar 2026 12:37:16 +0100 Subject: [PATCH 1/2] cmd/commands: add --qr flag to addinvoice for terminal QR display Add a `--qr` flag to the `addinvoice` CLI command that renders the payment request as a QR code directly in the terminal using the qrterminal library. This makes it convenient to scan invoices from a mobile wallet without needing to copy-paste the payment request string. --- cmd/commands/cmd_invoice.go | 16 ++++++++++++++++ go.mod | 2 ++ go.sum | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/cmd/commands/cmd_invoice.go b/cmd/commands/cmd_invoice.go index 24f6aa8bd2d..bf7a06ac319 100644 --- a/cmd/commands/cmd_invoice.go +++ b/cmd/commands/cmd_invoice.go @@ -3,10 +3,12 @@ package commands import ( "encoding/hex" "fmt" + "os" "strconv" "strings" "github.com/lightningnetwork/lnd/lnrpc" + qrterminal "github.com/mdp/qrterminal/v3" "github.com/urfave/cli" "google.golang.org/protobuf/proto" ) @@ -124,6 +126,11 @@ var AddInvoiceCommand = cli.Command{ "id (separated by commas), starting from a " + "channel which points to the self node.", }, + cli.BoolFlag{ + Name: "qr", + Usage: "display a QR code of the payment request " + + "in the terminal", + }, }, Action: actionDecorator(addInvoice), } @@ -202,6 +209,15 @@ func addInvoice(ctx *cli.Context) error { printRespJSON(resp) + if ctx.Bool("qr") { + // If the user requested it, we'll also print a QR code that + // encodes the payment request for easy scanning. + fmt.Println() + qrterminal.GenerateHalfBlock( + resp.PaymentRequest, qrterminal.L, os.Stdout, + ) + } + return nil } diff --git a/go.mod b/go.mod index df232d9d488..38564d2e047 100644 --- a/go.mod +++ b/go.mod @@ -125,6 +125,7 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect + github.com/mdp/qrterminal/v3 v3.2.1 github.com/moby/docker-image-spec v1.3.1 // indirect github.com/moby/term v0.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect @@ -194,6 +195,7 @@ require ( modernc.org/sqlite v1.29.10 // indirect modernc.org/strutil v1.2.0 // indirect modernc.org/token v1.1.0 // indirect + rsc.io/qr v0.2.0 // indirect sigs.k8s.io/yaml v1.2.0 // indirect ) diff --git a/go.sum b/go.sum index 553ec7d9b81..809f12a9ea6 100644 --- a/go.sum +++ b/go.sum @@ -343,6 +343,8 @@ github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4 github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mdp/qrterminal/v3 v3.2.1 h1:6+yQjiiOsSuXT5n9/m60E54vdgFsw0zhADHhHLrFet4= +github.com/mdp/qrterminal/v3 v3.2.1/go.mod h1:jOTmXvnBsMy5xqLniO0R++Jmjs2sTm9dFSuQ5kpz/SU= github.com/miekg/dns v1.1.43 h1:JKfpVSCB84vrAmHzyrsxB5NAr5kLoMXZArPSw7Qlgyg= github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4= github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= @@ -713,5 +715,7 @@ modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y= modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM= pgregory.net/rapid v1.2.0 h1:keKAYRcjm+e1F0oAuU5F5+YPAWcyxNNRK2wud503Gnk= pgregory.net/rapid v1.2.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= +rsc.io/qr v0.2.0 h1:6vBLea5/NRMVTz8V66gipeLycZMl/+UlFmk8DvqQ6WY= +rsc.io/qr v0.2.0/go.mod h1:IF+uZjkb9fqyeF/4tlBoynqmQxUoPfWEKh921coOuXs= sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q= sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= From 663d4cbc1b97195d53a6d8383fbfbdc9a96d1ea7 Mon Sep 17 00:00:00 2001 From: Slyghtning Date: Mon, 9 Mar 2026 13:57:30 +0100 Subject: [PATCH 2/2] docs: add release notes for addinvoice --qr flag --- docs/release-notes/release-notes-0.21.0.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/release-notes/release-notes-0.21.0.md b/docs/release-notes/release-notes-0.21.0.md index 2daafe61e3e..6d61765f926 100644 --- a/docs/release-notes/release-notes-0.21.0.md +++ b/docs/release-notes/release-notes-0.21.0.md @@ -286,6 +286,11 @@ * The `encryptdebugpackage` command now supports an `--include_log` flag. When set, the log file content is included in the encrypted debug package. +* The `addinvoice` command now supports a [`--qr` + flag](https://github.com/lightningnetwork/lnd/pull/10638) that renders the + payment request as a QR code directly in the terminal, making it easy to scan + from a mobile wallet. + ## Breaking Changes * [Increased MinCLTVDelta from 18 to