@@ -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 ()
@@ -438,6 +432,11 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
438432 swapClient .Conn ,
439433 )
440434
435+ // Create a static address server client.
436+ staticAddressClient := loop_swaprpc .NewStaticAddressServerClient (
437+ swapClient .Conn ,
438+ )
439+
441440 // Both the client RPC server and the swap server client should stop
442441 // on main context cancel. So we create it early and pass it down.
443442 d .mainCtx , d .mainCtxCancel = context .WithCancel (context .Background ())
@@ -498,6 +497,9 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
498497 var (
499498 reservationManager * reservation.Manager
500499 instantOutManager * instantout.Manager
500+
501+ staticAddressManager * address.Manager
502+ depositManager * deposit.Manager
501503 )
502504 // Create the reservation and instantout managers.
503505 if d .cfg .EnableExperimental {
@@ -534,43 +536,50 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
534536 instantOutManager = instantout .NewInstantOutManager (
535537 instantOutConfig ,
536538 )
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 )
537564 }
538565
539566 // Now finally fully initialize the swap client RPC server instance.
540567 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 ,
552581 }
553582
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-
574583 // Retrieve all currently existing swaps from the database.
575584 swapsList , err := d .impl .FetchSwaps (d .mainCtx )
576585 if err != nil {
@@ -662,20 +671,43 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
662671 }
663672
664673 // 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 ()
668678
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+ }
674687
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 ()
677693
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+ }
679711
680712 // Last, start our internal error handler. This will return exactly one
681713 // error or nil on the main error channel to inform the caller that
0 commit comments