Skip to content

Commit 01c017d

Browse files
committed
cli: add payment_timeout option to the CLI as well
1 parent 0d0af5b commit 01c017d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

cmd/loop/loopout.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"fmt"
6+
"math"
67
"strconv"
78
"strings"
89
"time"
@@ -92,6 +93,14 @@ var loopOutCommand = cli.Command{
9293
"Not setting this flag therefore might " +
9394
"result in a lower swap fee",
9495
},
96+
cli.DurationFlag{
97+
Name: "payment_timeout",
98+
Usage: "the timeout for each individual off-chain " +
99+
"payment attempt. If not set, the default " +
100+
"timeout of 1 hour will be used. As the " +
101+
"payment might be retried, the actual total " +
102+
"time may be longer",
103+
},
95104
forceFlag,
96105
labelFlag,
97106
verboseFlag,
@@ -235,6 +244,25 @@ func loopOut(ctx *cli.Context) error {
235244
}
236245
}
237246

247+
var paymentTimeout int64
248+
if ctx.IsSet("payment_timeout") {
249+
parsedTimeout := ctx.Duration("payment_timeout")
250+
if parsedTimeout.Truncate(time.Second) != parsedTimeout {
251+
return fmt.Errorf("payment timeout must be a " +
252+
"whole number of seconds")
253+
}
254+
255+
paymentTimeout = int64(parsedTimeout.Seconds())
256+
if paymentTimeout <= 0 {
257+
return fmt.Errorf("payment timeout must be a " +
258+
"positive value")
259+
}
260+
261+
if paymentTimeout > math.MaxUint32 {
262+
return fmt.Errorf("payment timeout is too large")
263+
}
264+
}
265+
238266
resp, err := client.LoopOut(context.Background(), &looprpc.LoopOutRequest{
239267
Amt: int64(amt),
240268
Dest: destAddr,
@@ -252,6 +280,7 @@ func loopOut(ctx *cli.Context) error {
252280
SwapPublicationDeadline: uint64(swapDeadline.Unix()),
253281
Label: label,
254282
Initiator: defaultInitiator,
283+
PaymentTimeout: uint32(paymentTimeout),
255284
})
256285
if err != nil {
257286
return err

0 commit comments

Comments
 (0)