@@ -23,6 +23,7 @@ import (
23
23
loop_looprpc "github.com/lightninglabs/loop/looprpc"
24
24
"github.com/lightninglabs/loop/staticaddr/address"
25
25
"github.com/lightninglabs/loop/staticaddr/deposit"
26
+ "github.com/lightninglabs/loop/staticaddr/withdraw"
26
27
loop_swaprpc "github.com/lightninglabs/loop/swapserverrpc"
27
28
"github.com/lightninglabs/loop/sweepbatcher"
28
29
"github.com/lightningnetwork/lnd/clock"
@@ -437,6 +438,12 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
437
438
swapClient .Conn ,
438
439
)
439
440
441
+ // Create a static address client that cooperatively closes deposits
442
+ // with the server.
443
+ withdrawalClient := loop_swaprpc .NewWithdrawalServerClient (
444
+ swapClient .Conn ,
445
+ )
446
+
440
447
// Both the client RPC server and the swap server client should stop
441
448
// on main context cancel. So we create it early and pass it down.
442
449
d .mainCtx , d .mainCtxCancel = context .WithCancel (context .Background ())
@@ -500,6 +507,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
500
507
501
508
staticAddressManager * address.Manager
502
509
depositManager * deposit.Manager
510
+ withdrawalManager * withdraw.Manager
503
511
)
504
512
// Create the reservation and instantout managers.
505
513
if d .cfg .EnableExperimental {
@@ -561,6 +569,17 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
561
569
Signer : d .lnd .Signer ,
562
570
}
563
571
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 )
564
583
}
565
584
566
585
// Now finally fully initialize the swap client RPC server instance.
@@ -578,6 +597,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
578
597
instantOutManager : instantOutManager ,
579
598
staticAddressManager : staticAddressManager ,
580
599
depositManager : depositManager ,
600
+ withdrawalManager : withdrawalManager ,
581
601
}
582
602
583
603
// Retrieve all currently existing swaps from the database.
@@ -709,6 +729,32 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
709
729
depositManager .WaitInitComplete ()
710
730
}
711
731
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
+
712
758
// Last, start our internal error handler. This will return exactly one
713
759
// error or nil on the main error channel to inform the caller that
714
760
// something went wrong or that shutdown is complete. We don't add to
0 commit comments