@@ -2,6 +2,7 @@ package liquidity
2
2
3
3
import (
4
4
"context"
5
+ "encoding/hex"
5
6
6
7
"github.com/btcsuite/btcd/btcutil"
7
8
"github.com/lightninglabs/loop"
@@ -84,6 +85,33 @@ func (b *loopOutBuilder) inUse(traffic *swapTraffic, peer route.Vertex,
84
85
return nil
85
86
}
86
87
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
+
87
115
// buildSwap creates a swap for the target peer/channels provided. The autoloop
88
116
// boolean indicates whether this swap will actually be executed, because there
89
117
// 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,
94
122
// dry-run, and we do not add the autoloop label to the recommended swap.
95
123
func (b * loopOutBuilder ) buildSwap (ctx context.Context , pubkey route.Vertex ,
96
124
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
+ initiator := 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
+ initiator += "-" + assetSwap .assetID
152
+ }
98
153
99
154
quote , err := b .cfg .LoopOutQuote (
100
155
ctx , & loop.LoopOutQuoteRequest {
101
156
Amount : amount ,
102
157
SweepConfTarget : params .SweepConfTarget ,
103
158
SwapPublicationDeadline : b .cfg .Clock .Now (),
104
- Initiator : getInitiator (params ),
159
+ Initiator : initiator ,
160
+ AssetRFQRequest : assetRfqRequest ,
105
161
},
106
162
)
107
163
if err != nil {
@@ -146,7 +202,13 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
146
202
MaxSwapFee : quote .SwapFee ,
147
203
MaxPrepayAmount : quote .PrepayAmount ,
148
204
SweepConfTarget : params .SweepConfTarget ,
149
- Initiator : getInitiator (params ),
205
+ Initiator : initiator ,
206
+ }
207
+
208
+ if opts .assetSwap != nil {
209
+ request .AssetId = assetIDBytes
210
+ request .AssetPrepayRfqId = quote .LoopOutRfq .PrepayRfqId
211
+ request .AssetSwapRfqId = quote .LoopOutRfq .SwapRfqId
150
212
}
151
213
152
214
if params .Autoloop {
0 commit comments