@@ -21,7 +21,8 @@ import (
21
21
"github.com/lightninglabs/loop/loopd/perms"
22
22
"github.com/lightninglabs/loop/loopdb"
23
23
loop_looprpc "github.com/lightninglabs/loop/looprpc"
24
- "github.com/lightninglabs/loop/staticaddr"
24
+ "github.com/lightninglabs/loop/staticaddr/address"
25
+ "github.com/lightninglabs/loop/staticaddr/deposit"
25
26
loop_swaprpc "github.com/lightninglabs/loop/swapserverrpc"
26
27
"github.com/lightninglabs/loop/sweepbatcher"
27
28
"github.com/lightningnetwork/lnd/clock"
@@ -68,12 +69,6 @@ type Daemon struct {
68
69
// same process.
69
70
swapClientServer
70
71
71
- // AddressServer is the embedded RPC server that satisfies the
72
- // static address client RPC interface. We embed this struct so the
73
- // Daemon itself can be registered to an existing grpc.Server to run as
74
- // a subserver in the same process.
75
- * staticaddr.AddressServer
76
-
77
72
// ErrChan is an error channel that users of the Daemon struct must use
78
73
// to detect runtime errors and also whether a shutdown is fully
79
74
// completed.
@@ -239,7 +234,6 @@ func (d *Daemon) startWebServers() error {
239
234
grpc .StreamInterceptor (streamInterceptor ),
240
235
)
241
236
loop_looprpc .RegisterSwapClientServer (d .grpcServer , d )
242
- loop_looprpc .RegisterStaticAddressClientServer (d .grpcServer , d )
243
237
244
238
// Register our debug server if it is compiled in.
245
239
d .registerDebugServer ()
@@ -438,6 +432,11 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
438
432
swapClient .Conn ,
439
433
)
440
434
435
+ // Create a static address server client.
436
+ staticAddressClient := loop_swaprpc .NewStaticAddressServerClient (
437
+ swapClient .Conn ,
438
+ )
439
+
441
440
// Both the client RPC server and the swap server client should stop
442
441
// on main context cancel. So we create it early and pass it down.
443
442
d .mainCtx , d .mainCtxCancel = context .WithCancel (context .Background ())
@@ -498,6 +497,9 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
498
497
var (
499
498
reservationManager * reservation.Manager
500
499
instantOutManager * instantout.Manager
500
+
501
+ staticAddressManager * address.Manager
502
+ depositManager * deposit.Manager
501
503
)
502
504
// Create the reservation and instantout managers.
503
505
if d .cfg .EnableExperimental {
@@ -534,43 +536,50 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
534
536
instantOutManager = instantout .NewInstantOutManager (
535
537
instantOutConfig ,
536
538
)
539
+
540
+ // Static address manager setup.
541
+ staticAddressStore := address .NewSqlStore (baseDb )
542
+ addrCfg := & address.ManagerConfig {
543
+ AddressClient : staticAddressClient ,
544
+ FetchL402 : swapClient .Server .FetchL402 ,
545
+ Store : staticAddressStore ,
546
+ WalletKit : d .lnd .WalletKit ,
547
+ ChainParams : d .lnd .ChainParams ,
548
+ }
549
+ staticAddressManager = address .NewManager (addrCfg )
550
+
551
+ // Static address deposit manager setup.
552
+ depositStore := deposit .NewSqlStore (baseDb )
553
+ depoCfg := & deposit.ManagerConfig {
554
+ AddressClient : staticAddressClient ,
555
+ AddressManager : staticAddressManager ,
556
+ SwapClient : swapClient ,
557
+ Store : depositStore ,
558
+ WalletKit : d .lnd .WalletKit ,
559
+ ChainParams : d .lnd .ChainParams ,
560
+ ChainNotifier : d .lnd .ChainNotifier ,
561
+ Signer : d .lnd .Signer ,
562
+ }
563
+ depositManager = deposit .NewManager (depoCfg )
537
564
}
538
565
539
566
// Now finally fully initialize the swap client RPC server instance.
540
567
d .swapClientServer = swapClientServer {
541
- config : d .cfg ,
542
- network : lndclient .Network (d .cfg .Network ),
543
- impl : swapClient ,
544
- liquidityMgr : getLiquidityManager (swapClient ),
545
- lnd : & d .lnd .LndServices ,
546
- swaps : make (map [lntypes.Hash ]loop.SwapInfo ),
547
- subscribers : make (map [int ]chan <- interface {}),
548
- statusChan : make (chan loop.SwapInfo ),
549
- mainCtx : d .mainCtx ,
550
- reservationManager : reservationManager ,
551
- instantOutManager : instantOutManager ,
568
+ config : d .cfg ,
569
+ network : lndclient .Network (d .cfg .Network ),
570
+ impl : swapClient ,
571
+ liquidityMgr : getLiquidityManager (swapClient ),
572
+ lnd : & d .lnd .LndServices ,
573
+ swaps : make (map [lntypes.Hash ]loop.SwapInfo ),
574
+ subscribers : make (map [int ]chan <- interface {}),
575
+ statusChan : make (chan loop.SwapInfo ),
576
+ mainCtx : d .mainCtx ,
577
+ reservationManager : reservationManager ,
578
+ instantOutManager : instantOutManager ,
579
+ staticAddressManager : staticAddressManager ,
580
+ depositManager : depositManager ,
552
581
}
553
582
554
- // Create a static address server client.
555
- staticAddressClient := loop_swaprpc .NewStaticAddressServerClient (
556
- swapClient .Conn ,
557
- )
558
-
559
- store := staticaddr .NewSqlStore (baseDb )
560
-
561
- cfg := & staticaddr.ManagerConfig {
562
- AddressClient : staticAddressClient ,
563
- SwapClient : swapClient ,
564
- Store : store ,
565
- WalletKit : d .lnd .WalletKit ,
566
- ChainParams : d .lnd .ChainParams ,
567
- }
568
- staticAddressManager := staticaddr .NewAddressManager (cfg )
569
-
570
- d .AddressServer = staticaddr .NewAddressServer (
571
- staticAddressClient , staticAddressManager ,
572
- )
573
-
574
583
// Retrieve all currently existing swaps from the database.
575
584
swapsList , err := d .impl .FetchSwaps (d .mainCtx )
576
585
if err != nil {
@@ -662,20 +671,43 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
662
671
}
663
672
664
673
// Start the static address manager.
665
- d .wg .Add (1 )
666
- go func () {
667
- defer d .wg .Done ()
674
+ if staticAddressManager != nil {
675
+ d .wg .Add (1 )
676
+ go func () {
677
+ defer d .wg .Done ()
668
678
669
- log .Info ("Starting static address manager..." )
670
- err = staticAddressManager .Run (d .mainCtx )
671
- if err != nil && ! errors .Is (context .Canceled , err ) {
672
- d .internalErrChan <- err
673
- }
679
+ log .Info ("Starting static address manager..." )
680
+ err = staticAddressManager .Run (d .mainCtx )
681
+ if err != nil && ! errors .Is (context .Canceled , err ) {
682
+ d .internalErrChan <- err
683
+ }
684
+ log .Info ("Static address manager stopped" )
685
+ }()
686
+ }
674
687
675
- log .Info ("Static address manager stopped" )
676
- }()
688
+ // Start the static address deposit manager.
689
+ if depositManager != nil {
690
+ d .wg .Add (1 )
691
+ go func () {
692
+ defer d .wg .Done ()
677
693
678
- staticAddressManager .WaitInitComplete ()
694
+ // Lnd's GetInfo call supplies us with the current block
695
+ // height.
696
+ info , err := d .lnd .Client .GetInfo (d .mainCtx )
697
+ if err != nil {
698
+ d .internalErrChan <- err
699
+ return
700
+ }
701
+
702
+ log .Info ("Starting static address deposit manager..." )
703
+ err = depositManager .Run (d .mainCtx , info .BlockHeight )
704
+ if err != nil && ! errors .Is (context .Canceled , err ) {
705
+ d .internalErrChan <- err
706
+ }
707
+ log .Info ("Static address deposit manager stopped" )
708
+ }()
709
+ depositManager .WaitInitComplete ()
710
+ }
679
711
680
712
// Last, start our internal error handler. This will return exactly one
681
713
// error or nil on the main error channel to inform the caller that
0 commit comments