@@ -71,8 +71,10 @@ type ManagerConfig struct {
7171// newWithdrawalRequest is used to send withdrawal request to the manager main
7272// loop.
7373type newWithdrawalRequest struct {
74- outpoints []wire.OutPoint
75- respChan chan * newWithdrawalResponse
74+ outpoints []wire.OutPoint
75+ respChan chan * newWithdrawalResponse
76+ destAddr string
77+ satPerVbyte int64
7678}
7779
7880// 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 {
156158
157159 case request := <- m .newWithdrawalRequestChan :
158160 txHash , pkScript , err = m .WithdrawDeposits (
159- ctx , request .outpoints ,
161+ ctx , request .outpoints , request .destAddr ,
162+ request .satPerVbyte ,
160163 )
161164 if err != nil {
162165 log .Errorf ("Error withdrawing deposits: %v" ,
@@ -258,7 +261,8 @@ func (m *Manager) WaitInitComplete() {
258261
259262// WithdrawDeposits starts a deposits withdrawal flow.
260263func (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 ) {
262266
263267 if len (outpoints ) == 0 {
264268 return "" , "" , fmt .Errorf ("no outpoints selected to " +
@@ -274,17 +278,32 @@ func (m *Manager) WithdrawDeposits(ctx context.Context,
274278 return "" , "" , ErrWithdrawingInactiveDeposits
275279 }
276280
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
281284 )
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+ }
284303 }
285304
286305 finalizedTx , err := m .createFinalizedWithdrawalTx (
287- ctx , deposits , withdrawalAddress ,
306+ ctx , deposits , withdrawalAddress , satPerVbyte ,
288307 )
289308 if err != nil {
290309 return "" , "" , err
@@ -335,8 +354,8 @@ func (m *Manager) WithdrawDeposits(ctx context.Context,
335354}
336355
337356func (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 ) {
340359
341360 // Create a musig2 session for each deposit.
342361 withdrawalSessions , clientNonces , err := m .createMusig2Sessions (
@@ -346,12 +365,19 @@ func (m *Manager) createFinalizedWithdrawalTx(ctx context.Context,
346365 return nil , err
347366 }
348367
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 ()
355381 }
356382
357383 outpoints := toOutpoints (deposits )
@@ -788,11 +814,14 @@ func (m *Manager) republishWithdrawals(ctx context.Context) error {
788814// DeliverWithdrawalRequest forwards a withdrawal request to the manager main
789815// loop.
790816func (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 ) {
792819
793820 request := newWithdrawalRequest {
794- outpoints : outpoints ,
795- respChan : make (chan * newWithdrawalResponse ),
821+ outpoints : outpoints ,
822+ destAddr : destAddr ,
823+ satPerVbyte : satPerVbyte ,
824+ respChan : make (chan * newWithdrawalResponse ),
796825 }
797826
798827 // Send the new loop-in request to the manager run loop.
0 commit comments