From 01c017d9138feefade594fef617321f7a5bf2211 Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Fri, 10 May 2024 17:08:26 +0200 Subject: [PATCH] cli: add payment_timeout option to the CLI as well --- cmd/loop/loopout.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/cmd/loop/loopout.go b/cmd/loop/loopout.go index a2ceb98..6ff24ce 100644 --- a/cmd/loop/loopout.go +++ b/cmd/loop/loopout.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "math" "strconv" "strings" "time" @@ -92,6 +93,14 @@ var loopOutCommand = cli.Command{ "Not setting this flag therefore might " + "result in a lower swap fee", }, + cli.DurationFlag{ + Name: "payment_timeout", + Usage: "the timeout for each individual off-chain " + + "payment attempt. If not set, the default " + + "timeout of 1 hour will be used. As the " + + "payment might be retried, the actual total " + + "time may be longer", + }, forceFlag, labelFlag, verboseFlag, @@ -235,6 +244,25 @@ func loopOut(ctx *cli.Context) error { } } + var paymentTimeout int64 + if ctx.IsSet("payment_timeout") { + parsedTimeout := ctx.Duration("payment_timeout") + if parsedTimeout.Truncate(time.Second) != parsedTimeout { + return fmt.Errorf("payment timeout must be a " + + "whole number of seconds") + } + + paymentTimeout = int64(parsedTimeout.Seconds()) + if paymentTimeout <= 0 { + return fmt.Errorf("payment timeout must be a " + + "positive value") + } + + if paymentTimeout > math.MaxUint32 { + return fmt.Errorf("payment timeout is too large") + } + } + resp, err := client.LoopOut(context.Background(), &looprpc.LoopOutRequest{ Amt: int64(amt), Dest: destAddr, @@ -252,6 +280,7 @@ func loopOut(ctx *cli.Context) error { SwapPublicationDeadline: uint64(swapDeadline.Unix()), Label: label, Initiator: defaultInitiator, + PaymentTimeout: uint32(paymentTimeout), }) if err != nil { return err