loop/liquidity/loopout.go
Boris Nagaev d554b42ef6
multi: migrate to btcd v2 modules
Update LND, Aperture, and Taproot Assets to revisions using the
btcd v2 modules, and update lndclient to v0.21.0-3. Migrate Loop
chain, transaction, and address types to their corresponding v2
packages.

The lndclient release includes the migration from:
https://github.com/lightninglabs/lndclient/pull/280

Taproot Assets is temporarily replaced with its btcd v2 revision
because the v0.8 release branch has not adopted the new modules.

This raises the minimum Go version to 1.26 and changes exported
address types.
2026-08-12 23:39:26 +00:00

68 lines
1.8 KiB
Go

package liquidity
import (
"github.com/btcsuite/btcd/btcutil/v2"
"github.com/lightninglabs/loop"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing/route"
)
// Compile-time assertion that loopOutSwapSuggestion satisfies the
// swapSuggestion interface.
var _ swapSuggestion = (*loopOutSwapSuggestion)(nil)
// loopOutSwapSuggestion is an implementation of the swapSuggestion interface
// implemented to allow us to abstract away from the details of a specific
// swap.
type loopOutSwapSuggestion struct {
loop.OutRequest
}
// amount returns the amount being swapped.
func (l *loopOutSwapSuggestion) amount() btcutil.Amount {
return l.OutRequest.Amount
}
// fees returns the maximum fees we could possibly pay for this swap.
func (l *loopOutSwapSuggestion) fees() btcutil.Amount {
return worstCaseOutFees(
l.OutRequest.MaxPrepayRoutingFee, l.OutRequest.MaxSwapRoutingFee,
l.OutRequest.MaxSwapFee, l.OutRequest.MaxMinerFee,
)
}
// channels returns the set of channels the loop out swap is restricted to.
func (l *loopOutSwapSuggestion) channels() []lnwire.ShortChannelID {
channels := make(
[]lnwire.ShortChannelID, len(l.OutRequest.OutgoingChanSet),
)
for i, id := range l.OutRequest.OutgoingChanSet {
channels[i] = lnwire.NewShortChanIDFromInt(id)
}
return channels
}
// peers returns the set of peers that the loop out swap is restricted to.
func (l *loopOutSwapSuggestion) peers(
knownChans map[uint64]route.Vertex) []route.Vertex {
peers := make(map[route.Vertex]struct{}, len(knownChans))
for _, channel := range l.OutRequest.OutgoingChanSet {
peer, ok := knownChans[channel]
if !ok {
log.Warnf("peer for channel: %v unknown", channel)
}
peers[peer] = struct{}{}
}
peerList := make([]route.Vertex, 0, len(peers))
for peer := range peers {
peerList = append(peerList, peer)
}
return peerList
}