cmd/loop: delay swap by 30 minutes by default, add --fast to loopout command

We now delay the swap by up to 30 minutes by deafult. To keep the
current imemdiate swap, --fast flag is added.
pull/75/head
Johan T. Halseth 5 years ago
parent ea1f9ff8ba
commit 7ea0e35299
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -68,7 +68,7 @@ func loopIn(ctx *cli.Context) error {
}
limits := getInLimits(amt, quote)
err = displayLimits(swap.TypeIn, amt, limits, external)
err = displayLimits(swap.TypeIn, amt, limits, external, "")
if err != nil {
return err
}

@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"time"
"github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/looprpc"
@ -44,6 +45,16 @@ var loopOutCommand = cli.Command{
"should be swept within",
Value: uint64(loop.DefaultSweepConfTarget),
},
cli.BoolFlag{
Name: "fast",
Usage: "Indicate you want to swap immediately, " +
"paying potentially a higher fee. If not " +
"set the swap server might choose to wait up " +
"to 30 minutes before publishing the swap " +
"HTLC on-chain, to save on chain fees. Not " +
"setting this flag might result in a lower " +
"swap fee.",
},
},
Action: loopOut,
}
@ -92,9 +103,19 @@ func loopOut(ctx *cli.Context) error {
return err
}
limits := getLimits(amt, quote)
// Show a warning if a slow swap was requested.
fast := ctx.Bool("fast")
warning := ""
if fast {
warning = "Fast swap requested."
} else {
warning = fmt.Sprintf("Regular swap speed requested, it "+
"might take up to %v for the swap to be executed.",
defaultSwapWaitTime)
}
err = displayLimits(swap.TypeOut, amt, limits, false)
limits := getLimits(amt, quote)
err = displayLimits(swap.TypeOut, amt, limits, false, warning)
if err != nil {
return err
}
@ -104,16 +125,24 @@ func loopOut(ctx *cli.Context) error {
unchargeChannel = ctx.Uint64("channel")
}
// Set our maximum swap wait time. If a fast swap is requested we set
// it to now, otherwise to 30 minutes in the future.
swapDeadline := time.Now()
if !fast {
swapDeadline = time.Now().Add(defaultSwapWaitTime)
}
resp, err := client.LoopOut(context.Background(), &looprpc.LoopOutRequest{
Amt: int64(amt),
Dest: destAddr,
MaxMinerFee: int64(limits.maxMinerFee),
MaxPrepayAmt: int64(*limits.maxPrepayAmt),
MaxSwapFee: int64(limits.maxSwapFee),
MaxPrepayRoutingFee: int64(*limits.maxPrepayRoutingFee),
MaxSwapRoutingFee: int64(*limits.maxSwapRoutingFee),
LoopOutChannel: unchargeChannel,
SweepConfTarget: sweepConfTarget,
Amt: int64(amt),
Dest: destAddr,
MaxMinerFee: int64(limits.maxMinerFee),
MaxPrepayAmt: int64(*limits.maxPrepayAmt),
MaxSwapFee: int64(limits.maxSwapFee),
MaxPrepayRoutingFee: int64(*limits.maxPrepayRoutingFee),
MaxSwapRoutingFee: int64(*limits.maxSwapRoutingFee),
LoopOutChannel: unchargeChannel,
SweepConfTarget: sweepConfTarget,
SwapPublicationDeadline: uint64(swapDeadline.Unix()),
})
if err != nil {
return err

@ -26,6 +26,8 @@ var (
maxRoutingFeeBase = btcutil.Amount(10)
maxRoutingFeeRate = int64(20000)
defaultSwapWaitTime = 30 * time.Minute
)
func printRespJSON(resp proto.Message) {
@ -117,7 +119,7 @@ func getLimits(amt btcutil.Amount, quote *looprpc.QuoteResponse) *limits {
}
func displayLimits(swapType swap.Type, amt btcutil.Amount, l *limits,
externalHtlc bool) error {
externalHtlc bool, warning string) error {
totalSuccessMax := l.maxMinerFee + l.maxSwapFee
if l.maxSwapRoutingFee != nil {
@ -138,6 +140,10 @@ func displayLimits(swapType swap.Type, amt btcutil.Amount, l *limits,
amt, swapType, totalSuccessMax,
)
if warning != "" {
fmt.Println(warning)
}
fmt.Printf("CONTINUE SWAP? (y/n), expand fee detail (x): ")
var answer string

Loading…
Cancel
Save