@@ -21,7 +21,8 @@ import (
2121 "github.com/lightninglabs/loop/loopd/perms"
2222 "github.com/lightninglabs/loop/loopdb"
2323 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"
2526 loop_swaprpc "github.com/lightninglabs/loop/swapserverrpc"
2627 "github.com/lightninglabs/loop/sweepbatcher"
2728 "github.com/lightningnetwork/lnd/clock"
@@ -68,12 +69,6 @@ type Daemon struct {
6869 // same process.
6970 swapClientServer
7071
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-
7772 // ErrChan is an error channel that users of the Daemon struct must use
7873 // to detect runtime errors and also whether a shutdown is fully
7974 // completed.
@@ -239,7 +234,6 @@ func (d *Daemon) startWebServers() error {
239234 grpc .StreamInterceptor (streamInterceptor ),
240235 )
241236 loop_looprpc .RegisterSwapClientServer (d .grpcServer , d )
242- loop_looprpc .RegisterStaticAddressClientServer (d .grpcServer , d )
243237
244238 // Register our debug server if it is compiled in.
245239 d .registerDebugServer ()
@@ -444,6 +438,11 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
444438 swapClient .Conn ,
445439 )
446440
441+ // Create a static address server client.
442+ staticAddressClient := loop_swaprpc .NewStaticAddressServerClient (
443+ swapClient .Conn ,
444+ )
445+
447446 // Both the client RPC server and the swap server client should stop
448447 // on main context cancel. So we create it early and pass it down.
449448 d .mainCtx , d .mainCtxCancel = context .WithCancel (context .Background ())
@@ -504,6 +503,9 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
504503 var (
505504 reservationManager * reservation.Manager
506505 instantOutManager * instantout.Manager
506+
507+ staticAddressManager * address.Manager
508+ depositManager * deposit.Manager
507509 )
508510 // Create the reservation and instantout managers.
509511 if d .cfg .EnableExperimental {
@@ -540,43 +542,50 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
540542 instantOutManager = instantout .NewInstantOutManager (
541543 instantOutConfig ,
542544 )
545+
546+ // Static address manager setup.
547+ staticAddressStore := address .NewSqlStore (baseDb )
548+ addrCfg := & address.ManagerConfig {
549+ AddressClient : staticAddressClient ,
550+ FetchL402 : swapClient .Server .FetchL402 ,
551+ Store : staticAddressStore ,
552+ WalletKit : d .lnd .WalletKit ,
553+ ChainParams : d .lnd .ChainParams ,
554+ }
555+ staticAddressManager = address .NewManager (addrCfg )
556+
557+ // Static address deposit manager setup.
558+ depositStore := deposit .NewSqlStore (baseDb )
559+ depoCfg := & deposit.ManagerConfig {
560+ AddressClient : staticAddressClient ,
561+ AddressManager : staticAddressManager ,
562+ SwapClient : swapClient ,
563+ Store : depositStore ,
564+ WalletKit : d .lnd .WalletKit ,
565+ ChainParams : d .lnd .ChainParams ,
566+ ChainNotifier : d .lnd .ChainNotifier ,
567+ Signer : d .lnd .Signer ,
568+ }
569+ depositManager = deposit .NewManager (depoCfg )
543570 }
544571
545572 // Now finally fully initialize the swap client RPC server instance.
546573 d .swapClientServer = swapClientServer {
547- config : d .cfg ,
548- network : lndclient .Network (d .cfg .Network ),
549- impl : swapClient ,
550- liquidityMgr : getLiquidityManager (swapClient ),
551- lnd : & d .lnd .LndServices ,
552- swaps : make (map [lntypes.Hash ]loop.SwapInfo ),
553- subscribers : make (map [int ]chan <- interface {}),
554- statusChan : make (chan loop.SwapInfo ),
555- mainCtx : d .mainCtx ,
556- reservationManager : reservationManager ,
557- instantOutManager : instantOutManager ,
574+ config : d .cfg ,
575+ network : lndclient .Network (d .cfg .Network ),
576+ impl : swapClient ,
577+ liquidityMgr : getLiquidityManager (swapClient ),
578+ lnd : & d .lnd .LndServices ,
579+ swaps : make (map [lntypes.Hash ]loop.SwapInfo ),
580+ subscribers : make (map [int ]chan <- interface {}),
581+ statusChan : make (chan loop.SwapInfo ),
582+ mainCtx : d .mainCtx ,
583+ reservationManager : reservationManager ,
584+ instantOutManager : instantOutManager ,
585+ staticAddressManager : staticAddressManager ,
586+ depositManager : depositManager ,
558587 }
559588
560- // Create a static address server client.
561- staticAddressClient := loop_swaprpc .NewStaticAddressServerClient (
562- swapClient .Conn ,
563- )
564-
565- store := staticaddr .NewSqlStore (baseDb )
566-
567- cfg := & staticaddr.ManagerConfig {
568- AddressClient : staticAddressClient ,
569- SwapClient : swapClient ,
570- Store : store ,
571- WalletKit : d .lnd .WalletKit ,
572- ChainParams : d .lnd .ChainParams ,
573- }
574- staticAddressManager := staticaddr .NewAddressManager (cfg )
575-
576- d .AddressServer = staticaddr .NewAddressServer (
577- staticAddressClient , staticAddressManager ,
578- )
579-
580589 // Retrieve all currently existing swaps from the database.
581590 swapsList , err := d .impl .FetchSwaps (d .mainCtx )
582591 if err != nil {
@@ -668,20 +677,43 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
668677 }
669678
670679 // Start the static address manager.
671- d .wg .Add (1 )
672- go func () {
673- defer d .wg .Done ()
680+ if staticAddressManager != nil {
681+ d .wg .Add (1 )
682+ go func () {
683+ defer d .wg .Done ()
674684
675- log .Info ("Starting static address manager..." )
676- err = staticAddressManager .Run (d .mainCtx )
677- if err != nil && ! errors .Is (context .Canceled , err ) {
678- d .internalErrChan <- err
679- }
685+ log .Info ("Starting static address manager..." )
686+ err = staticAddressManager .Run (d .mainCtx )
687+ if err != nil && ! errors .Is (context .Canceled , err ) {
688+ d .internalErrChan <- err
689+ }
690+ log .Info ("Static address manager stopped" )
691+ }()
692+ }
680693
681- log .Info ("Static address manager stopped" )
682- }()
694+ // Start the static address deposit manager.
695+ if depositManager != nil {
696+ d .wg .Add (1 )
697+ go func () {
698+ defer d .wg .Done ()
683699
684- staticAddressManager .WaitInitComplete ()
700+ // Lnd's GetInfo call supplies us with the current block
701+ // height.
702+ info , err := d .lnd .Client .GetInfo (d .mainCtx )
703+ if err != nil {
704+ d .internalErrChan <- err
705+ return
706+ }
707+
708+ log .Info ("Starting static address deposit manager..." )
709+ err = depositManager .Run (d .mainCtx , info .BlockHeight )
710+ if err != nil && ! errors .Is (context .Canceled , err ) {
711+ d .internalErrChan <- err
712+ }
713+ log .Info ("Static address deposit manager stopped" )
714+ }()
715+ depositManager .WaitInitComplete ()
716+ }
685717
686718 // Last, start our internal error handler. This will return exactly one
687719 // error or nil on the main error channel to inform the caller that
0 commit comments