mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
client: LoopInQuote to support v3 htlc for fee estimate
This commit is contained in:
parent
bf59159ddb
commit
ce3026daa9
1 changed files with 34 additions and 1 deletions
35
client.go
35
client.go
|
|
@ -682,7 +682,7 @@ func (s *Client) LoopInQuote(ctx context.Context,
|
|||
//
|
||||
// TODO(guggero): Thread through error code from lnd to avoid string
|
||||
// matching.
|
||||
minerFee, err := s.lndServices.Client.EstimateFeeToP2WSH(
|
||||
minerFee, err := s.estimateFee(
|
||||
ctx, request.Amount, request.HtlcConfTarget,
|
||||
)
|
||||
if err != nil && strings.Contains(err.Error(), "insufficient funds") {
|
||||
|
|
@ -703,6 +703,39 @@ func (s *Client) LoopInQuote(ctx context.Context,
|
|||
}, nil
|
||||
}
|
||||
|
||||
// estimateFee is a helper method to estimate the total fee for paying the
|
||||
// passed amount with the given conf target. It'll assume taproot destination
|
||||
// if the protocol version indicates that we're using taproot htlcs.
|
||||
func (s *Client) estimateFee(ctx context.Context, amt btcutil.Amount,
|
||||
confTarget int32) (btcutil.Amount, error) {
|
||||
|
||||
var (
|
||||
address btcutil.Address
|
||||
err error
|
||||
)
|
||||
// Generate a dummy address for fee estimation.
|
||||
witnessProg := [32]byte{}
|
||||
|
||||
scriptVersion := GetHtlcScriptVersion(
|
||||
loopdb.CurrentProtocolVersion(),
|
||||
)
|
||||
|
||||
if scriptVersion != swap.HtlcV3 {
|
||||
address, err = btcutil.NewAddressWitnessScriptHash(
|
||||
witnessProg[:], s.lndServices.ChainParams,
|
||||
)
|
||||
} else {
|
||||
address, err = btcutil.NewAddressTaproot(
|
||||
witnessProg[:], s.lndServices.ChainParams,
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return s.lndServices.Client.EstimateFee(ctx, address, amt, confTarget)
|
||||
}
|
||||
|
||||
// LoopInTerms returns the terms on which the server executes swaps.
|
||||
func (s *Client) LoopInTerms(ctx context.Context) (
|
||||
*LoopInTerms, error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue