mirror of
https://github.com/lightninglabs/loop
synced 2024-11-09 19:10:47 +00:00
cmd/loop: warn user if fee estimation fails
This commit is contained in:
parent
3dd10f14dc
commit
acdd2a22b2
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
|
"github.com/lightninglabs/loop"
|
||||||
"github.com/lightninglabs/loop/looprpc"
|
"github.com/lightninglabs/loop/looprpc"
|
||||||
"github.com/lightninglabs/loop/swap"
|
"github.com/lightninglabs/loop/swap"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
@ -76,6 +77,18 @@ func loopIn(ctx *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For loop in, the fee estimation is handed to lnd which tries to
|
||||||
|
// construct a real transaction to sample realistic fees to pay to the
|
||||||
|
// HTLC. If the wallet doesn't have enough funds to create this TX, we
|
||||||
|
// know it won't have enough to pay the real transaction either. It
|
||||||
|
// makes sense to abort the loop in this case.
|
||||||
|
if !external && quote.MinerFee == int64(loop.MinerFeeEstimationFailed) {
|
||||||
|
return fmt.Errorf("miner fee estimation not " +
|
||||||
|
"possible, lnd has insufficient funds to " +
|
||||||
|
"create a sample transaction for selected " +
|
||||||
|
"amount")
|
||||||
|
}
|
||||||
|
|
||||||
limits := getInLimits(amt, quote)
|
limits := getInLimits(amt, quote)
|
||||||
err = displayLimits(swap.TypeIn, amt, limits, external, "")
|
err = displayLimits(swap.TypeIn, amt, limits, external, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -159,9 +159,8 @@ func displayLimits(swapType swap.Type, amt btcutil.Amount, l *limits,
|
|||||||
"wallet.\n\n")
|
"wallet.\n\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Max swap fees for %d Loop %v: %d\n",
|
fmt.Printf("Max swap fees for %d Loop %v: %d\n", amt, swapType,
|
||||||
amt, swapType, totalSuccessMax,
|
totalSuccessMax)
|
||||||
)
|
|
||||||
|
|
||||||
if warning != "" {
|
if warning != "" {
|
||||||
fmt.Println(warning)
|
fmt.Println(warning)
|
||||||
|
@ -2,8 +2,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/lightninglabs/loop"
|
||||||
"github.com/lightninglabs/loop/looprpc"
|
"github.com/lightninglabs/loop/looprpc"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
@ -59,6 +62,18 @@ func quoteIn(ctx *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For loop in, the fee estimation is handed to lnd which tries to
|
||||||
|
// construct a real transaction to sample realistic fees to pay to the
|
||||||
|
// HTLC. If the wallet doesn't have enough funds to create this TX, we
|
||||||
|
// don't want to fail the quote. But the user should still be informed
|
||||||
|
// why the fee shows as -1.
|
||||||
|
if quoteResp.MinerFee == int64(loop.MinerFeeEstimationFailed) {
|
||||||
|
_, _ = fmt.Fprintf(os.Stderr, "Warning: Miner fee estimation "+
|
||||||
|
"not possible, lnd has insufficient funds to "+
|
||||||
|
"create a sample transaction for selected "+
|
||||||
|
"amount.\n")
|
||||||
|
}
|
||||||
|
|
||||||
printRespJSON(quoteResp)
|
printRespJSON(quoteResp)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user