Skip to content

Commit 5335c16

Browse files
committed
commands: use StringSliceFlag for chan ids
In this commit we 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.
1 parent f09c7ae commit 5335c16

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

cmd/commands/cmd_payments.go

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,13 +1585,13 @@ var forwardingHistoryCommand = cli.Command{
15851585
Usage: "skip the peer alias lookup per forwarding " +
15861586
"event in order to improve performance",
15871587
},
1588-
cli.Int64SliceFlag{
1588+
cli.StringSliceFlag{
15891589
Name: "incoming_chan_ids",
15901590
Usage: "the short channel id of the incoming " +
15911591
"channel to filter events by; can be " +
15921592
"specified multiple times in the same command",
15931593
},
1594-
cli.Int64SliceFlag{
1594+
cli.StringSliceFlag{
15951595
Name: "outgoing_chan_ids",
15961596
Usage: "the short channel id of the outgoing " +
15971597
"channel to filter events by; can be " +
@@ -1677,21 +1677,29 @@ func forwardingHistory(ctx *cli.Context) error {
16771677
NumMaxEvents: maxEvents,
16781678
PeerAliasLookup: lookupPeerAlias,
16791679
}
1680-
outgoingChannelIDs := ctx.Int64Slice("outgoing_chan_ids")
1680+
1681+
outgoingChannelIDs := ctx.StringSlice("outgoing_chan_ids")
16811682
if len(outgoingChannelIDs) != 0 {
1682-
req.OutgoingChanIds = make([]uint64, len(outgoingChannelIDs))
1683-
for i, c := range outgoingChannelIDs {
1684-
req.OutgoingChanIds[i] = uint64(c)
1683+
chanIDs, err := parseChanIDs(outgoingChannelIDs)
1684+
if err != nil {
1685+
return fmt.Errorf("unable to decode "+
1686+
"outgoing_chan_ids: %w", err)
16851687
}
1688+
1689+
req.OutgoingChanIds = chanIDs
16861690
}
16871691

1688-
incomingChannelIDs := ctx.Int64Slice("incoming_chan_ids")
1692+
incomingChannelIDs := ctx.StringSlice("incoming_chan_ids")
16891693
if len(incomingChannelIDs) != 0 {
1690-
req.IncomingChanIds = make([]uint64, len(incomingChannelIDs))
1691-
for i, c := range incomingChannelIDs {
1692-
req.IncomingChanIds[i] = uint64(c)
1694+
chanIDs, err := parseChanIDs(incomingChannelIDs)
1695+
if err != nil {
1696+
return fmt.Errorf("unable to decode "+
1697+
"incoming_chan_ids: %w", err)
16931698
}
1699+
1700+
req.IncomingChanIds = chanIDs
16941701
}
1702+
16951703
resp, err := client.ForwardingHistory(ctxc, req)
16961704
if err != nil {
16971705
return err
@@ -2060,3 +2068,19 @@ func ordinalNumber(num uint32) string {
20602068
return fmt.Sprintf("%dth", num)
20612069
}
20622070
}
2071+
2072+
// parseChanIDs parses a slice of strings containing short channel IDs into a
2073+
// slice of uint64 values.
2074+
func parseChanIDs(idStrings []string) ([]uint64, error) {
2075+
chanIDs := make([]uint64, len(idStrings))
2076+
for i, idStr := range idStrings {
2077+
scid, err := strconv.ParseUint(idStr, 10, 64)
2078+
if err != nil {
2079+
return nil, err
2080+
}
2081+
2082+
chanIDs[i] = scid
2083+
}
2084+
2085+
return chanIDs, nil
2086+
}

0 commit comments

Comments
 (0)