@@ -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 ()
@@ -446,6 +440,11 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
446440 swapClient .Conn ,
447441 )
448442
443+ // Create a static address server client.
444+ staticAddressClient := loop_swaprpc .NewStaticAddressServerClient (
445+ swapClient .Conn ,
446+ )
447+
449448 // Both the client RPC server and the swap server client should stop
450449 // on main context cancel. So we create it early and pass it down.
451450 d .mainCtx , d .mainCtxCancel = context .WithCancel (context .Background ())
@@ -506,6 +505,9 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
506505 var (
507506 reservationManager * reservation.Manager
508507 instantOutManager * instantout.Manager
508+
509+ staticAddressManager * address.Manager
510+ depositManager * deposit.Manager
509511 )
510512 // Create the reservation and instantout managers.
511513 if d .cfg .EnableExperimental {
@@ -542,43 +544,50 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
542544 instantOutManager = instantout .NewInstantOutManager (
543545 instantOutConfig ,
544546 )
547+
548+ // Static address manager setup.
549+ staticAddressStore := address .NewSqlStore (baseDb )
550+ addrCfg := & address.ManagerConfig {
551+ AddressClient : staticAddressClient ,
552+ FetchL402 : swapClient .Server .FetchL402 ,
553+ Store : staticAddressStore ,
554+ WalletKit : d .lnd .WalletKit ,
555+ ChainParams : d .lnd .ChainParams ,
556+ }
557+ staticAddressManager = address .NewManager (addrCfg )
558+
559+ // Static address deposit manager setup.
560+ depositStore := deposit .NewSqlStore (baseDb )
561+ depoCfg := & deposit.ManagerConfig {
562+ AddressClient : staticAddressClient ,
563+ AddressManager : staticAddressManager ,
564+ SwapClient : swapClient ,
565+ Store : depositStore ,
566+ WalletKit : d .lnd .WalletKit ,
567+ ChainParams : d .lnd .ChainParams ,
568+ ChainNotifier : d .lnd .ChainNotifier ,
569+ Signer : d .lnd .Signer ,
570+ }
571+ depositManager = deposit .NewManager (depoCfg )
545572 }
546573
547574 // Now finally fully initialize the swap client RPC server instance.
548575 d .swapClientServer = swapClientServer {
549- config : d .cfg ,
550- network : lndclient .Network (d .cfg .Network ),
551- impl : swapClient ,
552- liquidityMgr : getLiquidityManager (swapClient ),
553- lnd : & d .lnd .LndServices ,
554- swaps : make (map [lntypes.Hash ]loop.SwapInfo ),
555- subscribers : make (map [int ]chan <- interface {}),
556- statusChan : make (chan loop.SwapInfo ),
557- mainCtx : d .mainCtx ,
558- reservationManager : reservationManager ,
559- instantOutManager : instantOutManager ,
576+ config : d .cfg ,
577+ network : lndclient .Network (d .cfg .Network ),
578+ impl : swapClient ,
579+ liquidityMgr : getLiquidityManager (swapClient ),
580+ lnd : & d .lnd .LndServices ,
581+ swaps : make (map [lntypes.Hash ]loop.SwapInfo ),
582+ subscribers : make (map [int ]chan <- interface {}),
583+ statusChan : make (chan loop.SwapInfo ),
584+ mainCtx : d .mainCtx ,
585+ reservationManager : reservationManager ,
586+ instantOutManager : instantOutManager ,
587+ staticAddressManager : staticAddressManager ,
588+ depositManager : depositManager ,
560589 }
561590
562- // Create a static address server client.
563- staticAddressClient := loop_swaprpc .NewStaticAddressServerClient (
564- swapClient .Conn ,
565- )
566-
567- store := staticaddr .NewSqlStore (baseDb )
568-
569- cfg := & staticaddr.ManagerConfig {
570- AddressClient : staticAddressClient ,
571- SwapClient : swapClient ,
572- Store : store ,
573- WalletKit : d .lnd .WalletKit ,
574- ChainParams : d .lnd .ChainParams ,
575- }
576- staticAddressManager := staticaddr .NewAddressManager (cfg )
577-
578- d .AddressServer = staticaddr .NewAddressServer (
579- staticAddressClient , staticAddressManager ,
580- )
581-
582591 // Retrieve all currently existing swaps from the database.
583592 swapsList , err := d .impl .FetchSwaps (d .mainCtx )
584593 if err != nil {
@@ -670,20 +679,43 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
670679 }
671680
672681 // Start the static address manager.
673- d .wg .Add (1 )
674- go func () {
675- defer d .wg .Done ()
682+ if staticAddressManager != nil {
683+ d .wg .Add (1 )
684+ go func () {
685+ defer d .wg .Done ()
676686
677- log .Info ("Starting static address manager..." )
678- err = staticAddressManager .Run (d .mainCtx )
679- if err != nil && ! errors .Is (context .Canceled , err ) {
680- d .internalErrChan <- err
681- }
687+ log .Info ("Starting static address manager..." )
688+ err = staticAddressManager .Run (d .mainCtx )
689+ if err != nil && ! errors .Is (context .Canceled , err ) {
690+ d .internalErrChan <- err
691+ }
692+ log .Info ("Static address manager stopped" )
693+ }()
694+ }
682695
683- log .Info ("Static address manager stopped" )
684- }()
696+ // Start the static address deposit manager.
697+ if depositManager != nil {
698+ d .wg .Add (1 )
699+ go func () {
700+ defer d .wg .Done ()
685701
686- staticAddressManager .WaitInitComplete ()
702+ // Lnd's GetInfo call supplies us with the current block
703+ // height.
704+ info , err := d .lnd .Client .GetInfo (d .mainCtx )
705+ if err != nil {
706+ d .internalErrChan <- err
707+ return
708+ }
709+
710+ log .Info ("Starting static address deposit manager..." )
711+ err = depositManager .Run (d .mainCtx , info .BlockHeight )
712+ if err != nil && ! errors .Is (context .Canceled , err ) {
713+ d .internalErrChan <- err
714+ }
715+ log .Info ("Static address deposit manager stopped" )
716+ }()
717+ depositManager .WaitInitComplete ()
718+ }
687719
688720 // Last, start our internal error handler. This will return exactly one
689721 // error or nil on the main error channel to inform the caller that
0 commit comments