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.
This commit is contained in:
Abdullahi Yunus
2025-07-21 20:26:46 +01:00
parent f09c7aee4e
commit 4751016839

View File

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