Skip to content

Commit 0e04cd5

Browse files
committed
litcli: drop unused flags from addinvoice command
The litcli `ln addinvoice` command inherits all of lncli's addinvoice flags but its action only acts on a subset. The blinded-path flags and cltv_expiry_delta are never read and don't apply to Taproot Asset invoices, yet they still show up in `litcli ln addinvoice -h`, which is confusing. Filter those flags out so the help output only lists options that have an effect, and add a test asserting the command keeps the flags it uses and drops the unsupported ones. Addresses #1121 Signed-off-by: 0xfandom <kashyapshivank01@gmail.com>
1 parent 4ed4b03 commit 0e04cd5

2 files changed

Lines changed: 75 additions & 1 deletion

File tree

cmd/litcli/ln.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,41 @@ func payInvoice(cliCtx *cli.Context) error {
692692
)
693693
}
694694

695+
// addInvoiceUnsupportedFlags is the set of flags that are inherited from
696+
// lncli's addinvoice command but don't apply to Taproot Asset invoices. The
697+
// addInvoice action below never reads these, so we strip them to avoid
698+
// presenting options that have no effect.
699+
var addInvoiceUnsupportedFlags = map[string]struct{}{
700+
// The final-hop CLTV delta isn't applied to asset invoices.
701+
"cltv_expiry_delta": {},
702+
703+
// Blinded paths aren't supported for asset invoices; the relevant hop
704+
// hints are added as part of the RFQ process instead.
705+
"blind": {},
706+
"min_real_blinded_hops": {},
707+
"num_blinded_hops": {},
708+
"max_blinded_paths": {},
709+
"blinded_path_omit_node": {},
710+
"blinded_path_incoming_channel_list": {},
711+
}
712+
713+
// withoutUnsupportedAddInvoiceFlags returns the given flags with the ones that
714+
// don't apply to Taproot Asset invoices (see addInvoiceUnsupportedFlags)
715+
// removed.
716+
func withoutUnsupportedAddInvoiceFlags(flags []cli.Flag) []cli.Flag {
717+
filtered := make([]cli.Flag, 0, len(flags))
718+
for _, flag := range flags {
719+
_, unsupported := addInvoiceUnsupportedFlags[flag.GetName()]
720+
if unsupported {
721+
continue
722+
}
723+
724+
filtered = append(filtered, flag)
725+
}
726+
727+
return filtered
728+
}
729+
695730
var addInvoiceCommand = cli.Command{
696731
Name: "addinvoice",
697732
Category: commands.AddInvoiceCommand.Category,
@@ -703,7 +738,9 @@ var addInvoiceCommand = cli.Command{
703738
ArgsUsage: "[--asset_id=X | --group_key=X] --asset_amount=Y " +
704739
"[--rfq_peer_pubkey=Z] ",
705740
Flags: append(
706-
commands.AddInvoiceCommand.Flags,
741+
withoutUnsupportedAddInvoiceFlags(
742+
commands.AddInvoiceCommand.Flags,
743+
),
707744
cli.StringFlag{
708745
Name: "asset_id",
709746
Usage: "the asset ID of the asset to receive; cannot " +

cmd/litcli/ln_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
// TestAddInvoiceCommandFlags ensures that the litcli addinvoice command keeps
10+
// the flags its action actually reads (including the asset-specific ones it
11+
// adds) while dropping the inherited lncli flags that don't apply to Taproot
12+
// Asset invoices.
13+
func TestAddInvoiceCommandFlags(t *testing.T) {
14+
t.Parallel()
15+
16+
flagNames := make(map[string]struct{})
17+
for _, flag := range addInvoiceCommand.Flags {
18+
flagNames[flag.GetName()] = struct{}{}
19+
}
20+
21+
// Flags that the addInvoice action reads must remain available.
22+
expected := []string{
23+
"memo", "preimage", "amt", "amt_msat", "description_hash",
24+
"fallback_addr", "expiry", "private", "amp",
25+
"asset_id", "group_key", "asset_amount", "rfq_peer_pubkey",
26+
}
27+
for _, name := range expected {
28+
_, ok := flagNames[name]
29+
require.Truef(t, ok, "expected flag %q to be present", name)
30+
}
31+
32+
// Flags that don't apply to asset invoices must be removed.
33+
for name := range addInvoiceUnsupportedFlags {
34+
_, ok := flagNames[name]
35+
require.Falsef(t, ok, "expected flag %q to be removed", name)
36+
}
37+
}

0 commit comments

Comments
 (0)