@@ -2,6 +2,7 @@ package liquidity
22
33import (
44 "context"
5+ "encoding/hex"
56
67 "github.com/btcsuite/btcd/btcutil"
78 "github.com/lightninglabs/loop"
@@ -84,6 +85,33 @@ func (b *loopOutBuilder) inUse(traffic *swapTraffic, peer route.Vertex,
8485 return nil
8586}
8687
88+ type assetSwapInfo struct {
89+ assetID string
90+ peerPubkey []byte
91+ }
92+
93+ // buildSwapOpts contains the options for building a swap.
94+ type buildSwapOpts struct {
95+ assetSwap * assetSwapInfo
96+ }
97+
98+ // defaultBuildSwapOpts returns the default options for building a swap.
99+ func defaultBuildSwapOpts () * buildSwapOpts {
100+ return & buildSwapOpts {}
101+ }
102+
103+ // buildSwapOption is a functional option that can be passed to the buildSwap
104+ // method.
105+ type buildSwapOption func (* buildSwapOpts )
106+
107+ // withAssetSwapInfo is an option to provide asset swap information to the
108+ // builder.
109+ func withAssetSwapInfo (assetSwapInfo * assetSwapInfo ) buildSwapOption {
110+ return func (o * buildSwapOpts ) {
111+ o .assetSwap = assetSwapInfo
112+ }
113+ }
114+
87115// buildSwap creates a swap for the target peer/channels provided. The autoloop
88116// boolean indicates whether this swap will actually be executed, because there
89117// are some calls we can leave out if this swap is just for a dry run (ie, when
@@ -94,14 +122,42 @@ func (b *loopOutBuilder) inUse(traffic *swapTraffic, peer route.Vertex,
94122// dry-run, and we do not add the autoloop label to the recommended swap.
95123func (b * loopOutBuilder ) buildSwap (ctx context.Context , pubkey route.Vertex ,
96124 channels []lnwire.ShortChannelID , amount btcutil.Amount ,
97- params Parameters ) (swapSuggestion , error ) {
125+ params Parameters , swapOpts ... buildSwapOption ) (swapSuggestion ,
126+ error ) {
127+
128+ var (
129+ assetRfqRequest * loop.AssetRFQRequest
130+ assetIDBytes []byte
131+ err error
132+ )
133+
134+ opts := defaultBuildSwapOpts ()
135+ for _ , opt := range swapOpts {
136+ opt (opts )
137+ }
138+
139+ initatior := getInitiator (params )
140+
141+ if opts .assetSwap != nil {
142+ assetSwap := opts .assetSwap
143+ assetIDBytes , err = hex .DecodeString (assetSwap .assetID )
144+ if err != nil {
145+ return nil , err
146+ }
147+ assetRfqRequest = & loop.AssetRFQRequest {
148+ AssetId : assetIDBytes ,
149+ AssetEdgeNode : assetSwap .peerPubkey ,
150+ }
151+ initatior += "-" + assetSwap .assetID
152+ }
98153
99154 quote , err := b .cfg .LoopOutQuote (
100155 ctx , & loop.LoopOutQuoteRequest {
101156 Amount : amount ,
102157 SweepConfTarget : params .SweepConfTarget ,
103158 SwapPublicationDeadline : b .cfg .Clock .Now (),
104- Initiator : getInitiator (params ),
159+ Initiator : initatior ,
160+ AssetRFQRequest : assetRfqRequest ,
105161 },
106162 )
107163 if err != nil {
@@ -146,7 +202,13 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
146202 MaxSwapFee : quote .SwapFee ,
147203 MaxPrepayAmount : quote .PrepayAmount ,
148204 SweepConfTarget : params .SweepConfTarget ,
149- Initiator : getInitiator (params ),
205+ Initiator : initatior ,
206+ }
207+
208+ if opts .assetSwap != nil {
209+ request .AssetId = assetIDBytes
210+ request .AssetPrepayRfqId = quote .LoopOutRfq .PrepayRfqId
211+ request .AssetSwapRfqId = quote .LoopOutRfq .SwapRfqId
150212 }
151213
152214 if params .Autoloop {
0 commit comments