@@ -71,8 +71,10 @@ type ManagerConfig struct {
71
71
// newWithdrawalRequest is used to send withdrawal request to the manager main
72
72
// loop.
73
73
type newWithdrawalRequest struct {
74
- outpoints []wire.OutPoint
75
- respChan chan * newWithdrawalResponse
74
+ outpoints []wire.OutPoint
75
+ respChan chan * newWithdrawalResponse
76
+ destAddr string
77
+ satPerVbyte int64
76
78
}
77
79
78
80
// newWithdrawalResponse is used to return withdrawal info and error to the
@@ -156,7 +158,8 @@ func (m *Manager) Run(ctx context.Context, currentHeight uint32) error {
156
158
157
159
case request := <- m .newWithdrawalRequestChan :
158
160
txHash , pkScript , err = m .WithdrawDeposits (
159
- ctx , request .outpoints ,
161
+ ctx , request .outpoints , request .destAddr ,
162
+ request .satPerVbyte ,
160
163
)
161
164
if err != nil {
162
165
log .Errorf ("Error withdrawing deposits: %v" ,
@@ -258,7 +261,8 @@ func (m *Manager) WaitInitComplete() {
258
261
259
262
// WithdrawDeposits starts a deposits withdrawal flow.
260
263
func (m * Manager ) WithdrawDeposits (ctx context.Context ,
261
- outpoints []wire.OutPoint ) (string , string , error ) {
264
+ outpoints []wire.OutPoint , destAddr string , satPerVbyte int64 ) (string ,
265
+ string , error ) {
262
266
263
267
if len (outpoints ) == 0 {
264
268
return "" , "" , fmt .Errorf ("no outpoints selected to " +
@@ -274,17 +278,32 @@ func (m *Manager) WithdrawDeposits(ctx context.Context,
274
278
return "" , "" , ErrWithdrawingInactiveDeposits
275
279
}
276
280
277
- // Generate the withdrawal address from our local lnd wallet.
278
- withdrawalAddress , err := m .cfg .WalletKit .NextAddr (
279
- ctx , lnwallet .DefaultAccountName ,
280
- walletrpc .AddressType_TAPROOT_PUBKEY , false ,
281
+ var (
282
+ withdrawalAddress btcutil.Address
283
+ err error
281
284
)
282
- if err != nil {
283
- return "" , "" , err
285
+
286
+ // Check if the user provided an address to withdraw to. If not, we'll
287
+ // generate a new address for them.
288
+ if destAddr != "" {
289
+ withdrawalAddress , err = btcutil .DecodeAddress (
290
+ destAddr , m .cfg .ChainParams ,
291
+ )
292
+ if err != nil {
293
+ return "" , "" , err
294
+ }
295
+ } else {
296
+ withdrawalAddress , err = m .cfg .WalletKit .NextAddr (
297
+ ctx , lnwallet .DefaultAccountName ,
298
+ walletrpc .AddressType_TAPROOT_PUBKEY , false ,
299
+ )
300
+ if err != nil {
301
+ return "" , "" , err
302
+ }
284
303
}
285
304
286
305
finalizedTx , err := m .createFinalizedWithdrawalTx (
287
- ctx , deposits , withdrawalAddress ,
306
+ ctx , deposits , withdrawalAddress , satPerVbyte ,
288
307
)
289
308
if err != nil {
290
309
return "" , "" , err
@@ -335,8 +354,8 @@ func (m *Manager) WithdrawDeposits(ctx context.Context,
335
354
}
336
355
337
356
func (m * Manager ) createFinalizedWithdrawalTx (ctx context.Context ,
338
- deposits []* deposit.Deposit , withdrawalAddress btcutil.Address ) (
339
- * wire.MsgTx , error ) {
357
+ deposits []* deposit.Deposit , withdrawalAddress btcutil.Address ,
358
+ satPerVbyte int64 ) ( * wire.MsgTx , error ) {
340
359
341
360
// Create a musig2 session for each deposit.
342
361
withdrawalSessions , clientNonces , err := m .createMusig2Sessions (
@@ -346,12 +365,19 @@ func (m *Manager) createFinalizedWithdrawalTx(ctx context.Context,
346
365
return nil , err
347
366
}
348
367
349
- // Get the fee rate for the withdrawal sweep.
350
- withdrawalSweepFeeRate , err := m .cfg .WalletKit .EstimateFeeRate (
351
- ctx , defaultConfTarget ,
352
- )
353
- if err != nil {
354
- return nil , err
368
+ var withdrawalSweepFeeRate chainfee.SatPerKWeight
369
+ if satPerVbyte == 0 {
370
+ // Get the fee rate for the withdrawal sweep.
371
+ withdrawalSweepFeeRate , err = m .cfg .WalletKit .EstimateFeeRate (
372
+ ctx , defaultConfTarget ,
373
+ )
374
+ if err != nil {
375
+ return nil , err
376
+ }
377
+ } else {
378
+ withdrawalSweepFeeRate = chainfee .SatPerKVByte (
379
+ satPerVbyte * 1000 ,
380
+ ).FeePerKWeight ()
355
381
}
356
382
357
383
outpoints := toOutpoints (deposits )
@@ -788,11 +814,14 @@ func (m *Manager) republishWithdrawals(ctx context.Context) error {
788
814
// DeliverWithdrawalRequest forwards a withdrawal request to the manager main
789
815
// loop.
790
816
func (m * Manager ) DeliverWithdrawalRequest (ctx context.Context ,
791
- outpoints []wire.OutPoint ) (string , string , error ) {
817
+ outpoints []wire.OutPoint , destAddr string , satPerVbyte int64 ) (string ,
818
+ string , error ) {
792
819
793
820
request := newWithdrawalRequest {
794
- outpoints : outpoints ,
795
- respChan : make (chan * newWithdrawalResponse ),
821
+ outpoints : outpoints ,
822
+ destAddr : destAddr ,
823
+ satPerVbyte : satPerVbyte ,
824
+ respChan : make (chan * newWithdrawalResponse ),
796
825
}
797
826
798
827
// Send the new loop-in request to the manager run loop.
0 commit comments