@@ -23,6 +23,7 @@ import (
2323 loop_looprpc "github.com/lightninglabs/loop/looprpc"
2424 "github.com/lightninglabs/loop/staticaddr/address"
2525 "github.com/lightninglabs/loop/staticaddr/deposit"
26+ "github.com/lightninglabs/loop/staticaddr/withdraw"
2627 loop_swaprpc "github.com/lightninglabs/loop/swapserverrpc"
2728 "github.com/lightninglabs/loop/sweepbatcher"
2829 "github.com/lightningnetwork/lnd/clock"
@@ -437,6 +438,12 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
437438 swapClient .Conn ,
438439 )
439440
441+ // Create a static address client that cooperatively closes deposits
442+ // with the server.
443+ withdrawalClient := loop_swaprpc .NewWithdrawalServerClient (
444+ swapClient .Conn ,
445+ )
446+
440447 // Both the client RPC server and the swap server client should stop
441448 // on main context cancel. So we create it early and pass it down.
442449 d .mainCtx , d .mainCtxCancel = context .WithCancel (context .Background ())
@@ -500,6 +507,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
500507
501508 staticAddressManager * address.Manager
502509 depositManager * deposit.Manager
510+ withdrawalManager * withdraw.Manager
503511 )
504512 // Create the reservation and instantout managers.
505513 if d .cfg .EnableExperimental {
@@ -561,6 +569,17 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
561569 Signer : d .lnd .Signer ,
562570 }
563571 depositManager = deposit .NewManager (depoCfg )
572+
573+ // Static address deposit closure manager setup.
574+ closeCfg := & withdraw.ManagerConfig {
575+ WithdrawalServerClient : withdrawalClient ,
576+ AddressManager : staticAddressManager ,
577+ DepositManager : depositManager ,
578+ WalletKit : d .lnd .WalletKit ,
579+ ChainNotifier : d .lnd .ChainNotifier ,
580+ Signer : d .lnd .Signer ,
581+ }
582+ withdrawalManager = withdraw .NewManager (closeCfg )
564583 }
565584
566585 // Now finally fully initialize the swap client RPC server instance.
@@ -578,6 +597,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
578597 instantOutManager : instantOutManager ,
579598 staticAddressManager : staticAddressManager ,
580599 depositManager : depositManager ,
600+ withdrawalManager : withdrawalManager ,
581601 }
582602
583603 // Retrieve all currently existing swaps from the database.
@@ -709,6 +729,32 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
709729 depositManager .WaitInitComplete ()
710730 }
711731
732+ // Start the static address deposit withdrawal manager.
733+ if withdrawalManager != nil {
734+ d .wg .Add (1 )
735+ go func () {
736+ defer d .wg .Done ()
737+
738+ // Lnd's GetInfo call supplies us with the current block
739+ // height.
740+ info , err := d .lnd .Client .GetInfo (d .mainCtx )
741+ if err != nil {
742+ d .internalErrChan <- err
743+ return
744+ }
745+
746+ log .Info ("Starting static address deposit closure " +
747+ "manager..." )
748+ err = withdrawalManager .Run (d .mainCtx , info .BlockHeight )
749+ if err != nil && ! errors .Is (context .Canceled , err ) {
750+ d .internalErrChan <- err
751+ }
752+ log .Info ("Static address deposit closure " +
753+ "manager stopped" )
754+ }()
755+ withdrawalManager .WaitInitComplete ()
756+ }
757+
712758 // Last, start our internal error handler. This will return exactly one
713759 // error or nil on the main error channel to inform the caller that
714760 // something went wrong or that shutdown is complete. We don't add to
0 commit comments