From 47510168390c75a2e8b274e8b61fadf48aa848a8 Mon Sep 17 00:00:00 2001 From: Abdullahi Yunus Date: Mon, 21 Jul 2025 20:26:46 +0100 Subject: [PATCH] commands: use StringSliceFlag for chan ids In this commit we use stringSlice flag for incoming and outgoing channel ids args, for forwarding history command. The Int64Slice range does not cover all possible scids in the custom alias range. --- cmd/commands/cmd_payments.go | 47 +++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/cmd/commands/cmd_payments.go b/cmd/commands/cmd_payments.go index b746dbbfd..5b1343256 100644 --- a/cmd/commands/cmd_payments.go +++ b/cmd/commands/cmd_payments.go @@ -1585,13 +1585,13 @@ var forwardingHistoryCommand = cli.Command{ Usage: "skip the peer alias lookup per forwarding " + "event in order to improve performance", }, - cli.Int64SliceFlag{ + cli.StringSliceFlag{ Name: "incoming_chan_ids", Usage: "the short channel id of the incoming " + "channel to filter events by; can be " + "specified multiple times in the same command", }, - cli.Int64SliceFlag{ + cli.StringSliceFlag{ Name: "outgoing_chan_ids", Usage: "the short channel id of the outgoing " + "channel to filter events by; can be " + @@ -1677,21 +1677,19 @@ func forwardingHistory(ctx *cli.Context) error { NumMaxEvents: maxEvents, PeerAliasLookup: lookupPeerAlias, } - outgoingChannelIDs := ctx.Int64Slice("outgoing_chan_ids") - if len(outgoingChannelIDs) != 0 { - req.OutgoingChanIds = make([]uint64, len(outgoingChannelIDs)) - for i, c := range outgoingChannelIDs { - req.OutgoingChanIds[i] = uint64(c) - } + + outgoingChannelIDs := ctx.StringSlice("outgoing_chan_ids") + req.OutgoingChanIds, err = parseChanIDs(outgoingChannelIDs) + if err != nil { + return fmt.Errorf("unable to decode outgoing_chan_ids: %w", err) } - incomingChannelIDs := ctx.Int64Slice("incoming_chan_ids") - if len(incomingChannelIDs) != 0 { - req.IncomingChanIds = make([]uint64, len(incomingChannelIDs)) - for i, c := range incomingChannelIDs { - req.IncomingChanIds[i] = uint64(c) - } + incomingChannelIDs := ctx.StringSlice("incoming_chan_ids") + req.IncomingChanIds, err = parseChanIDs(incomingChannelIDs) + if err != nil { + return fmt.Errorf("unable to decode incoming_chan_ids: %w", err) } + resp, err := client.ForwardingHistory(ctxc, req) if err != nil { return err @@ -2060,3 +2058,24 @@ func ordinalNumber(num uint32) string { return fmt.Sprintf("%dth", num) } } + +// parseChanIDs parses a slice of strings containing short channel IDs into a +// slice of uint64 values. +func parseChanIDs(idStrings []string) ([]uint64, error) { + // Return early if no chan IDs are passed. + if len(idStrings) == 0 { + return nil, nil + } + + chanIDs := make([]uint64, len(idStrings)) + for i, idStr := range idStrings { + scid, err := strconv.ParseUint(idStr, 10, 64) + if err != nil { + return nil, err + } + + chanIDs[i] = scid + } + + return chanIDs, nil +}