cmd/loop: warn user if fee estimation fails

pull/158/head
Oliver Gugger 4 years ago
parent 3dd10f14dc
commit acdd2a22b2
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/btcsuite/btcutil"
"github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/looprpc"
"github.com/lightninglabs/loop/swap"
"github.com/lightningnetwork/lnd/routing/route"
@ -76,6 +77,18 @@ func loopIn(ctx *cli.Context) error {
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)
err = displayLimits(swap.TypeIn, amt, limits, external, "")
if err != nil {

@ -159,9 +159,8 @@ func displayLimits(swapType swap.Type, amt btcutil.Amount, l *limits,
"wallet.\n\n")
}
fmt.Printf("Max swap fees for %d Loop %v: %d\n",
amt, swapType, totalSuccessMax,
)
fmt.Printf("Max swap fees for %d Loop %v: %d\n", amt, swapType,
totalSuccessMax)
if warning != "" {
fmt.Println(warning)

@ -2,8 +2,11 @@ package main
import (
"context"
"fmt"
"os"
"time"
"github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/looprpc"
"github.com/urfave/cli"
)
@ -59,6 +62,18 @@ func quoteIn(ctx *cli.Context) error {
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)
return nil
}

Loading…
Cancel
Save