@@ -17,14 +17,13 @@ import (
17
17
"github.com/lightninglabs/lndclient"
18
18
"github.com/lightninglabs/loop"
19
19
"github.com/lightninglabs/loop/instantout"
20
+ "github.com/lightninglabs/loop/instantout/reservation"
20
21
"github.com/lightninglabs/loop/loopd/perms"
21
22
"github.com/lightninglabs/loop/loopdb"
22
- "github.com/lightninglabs/loop/sweepbatcher"
23
-
24
- "github.com/lightninglabs/loop/instantout/reservation"
25
23
loop_looprpc "github.com/lightninglabs/loop/looprpc"
26
-
24
+ "github.com/lightninglabs/loop/staticaddr"
27
25
loop_swaprpc "github.com/lightninglabs/loop/swapserverrpc"
26
+ "github.com/lightninglabs/loop/sweepbatcher"
28
27
"github.com/lightningnetwork/lnd/clock"
29
28
"github.com/lightningnetwork/lnd/lntypes"
30
29
"github.com/lightningnetwork/lnd/macaroons"
@@ -69,6 +68,12 @@ type Daemon struct {
69
68
// same process.
70
69
swapClientServer
71
70
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
+
72
77
// ErrChan is an error channel that users of the Daemon struct must use
73
78
// to detect runtime errors and also whether a shutdown is fully
74
79
// completed.
@@ -234,6 +239,7 @@ func (d *Daemon) startWebServers() error {
234
239
grpc .StreamInterceptor (streamInterceptor ),
235
240
)
236
241
loop_looprpc .RegisterSwapClientServer (d .grpcServer , d )
242
+ loop_looprpc .RegisterStaticAddressClientServer (d .grpcServer , d )
237
243
238
244
// Register our debug server if it is compiled in.
239
245
d .registerDebugServer ()
@@ -545,6 +551,26 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
545
551
instantOutManager : instantOutManager ,
546
552
}
547
553
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
+
548
574
// Retrieve all currently existing swaps from the database.
549
575
swapsList , err := d .impl .FetchSwaps (d .mainCtx )
550
576
if err != nil {
@@ -635,42 +661,21 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
635
661
}()
636
662
}
637
663
638
- // Start the instant out manager.
639
- if d .instantOutManager != nil {
640
- d .wg .Add (1 )
641
- initChan := make (chan struct {})
642
- go func () {
643
- defer d .wg .Done ()
644
-
645
- getInfo , err := d .lnd .Client .GetInfo (d .mainCtx )
646
- if err != nil {
647
- d .internalErrChan <- err
648
- return
649
- }
664
+ // Start the static address manager.
665
+ d .wg .Add (1 )
666
+ go func () {
667
+ defer d .wg .Done ()
650
668
651
- log .Info ("Starting instantout manager" )
652
- defer log .Info ("Instantout manager stopped" )
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
+ }
653
674
654
- err = d .instantOutManager .Run (
655
- d .mainCtx , initChan , int32 (getInfo .BlockHeight ),
656
- )
657
- if err != nil && ! errors .Is (err , context .Canceled ) {
658
- d .internalErrChan <- err
659
- }
660
- }()
675
+ log .Info ("Static address manager stopped" )
676
+ }()
661
677
662
- // Wait for the instantout server to be ready before starting the
663
- // grpc server.
664
- timeOutCtx , cancel := context .WithTimeout (d .mainCtx , 10 * time .Second )
665
- select {
666
- case <- timeOutCtx .Done ():
667
- cancel ()
668
- return fmt .Errorf ("reservation server not ready: %v" ,
669
- timeOutCtx .Err ())
670
- case <- initChan :
671
- cancel ()
672
- }
673
- }
678
+ staticAddressManager .WaitInitComplete ()
674
679
675
680
// Last, start our internal error handler. This will return exactly one
676
681
// error or nil on the main error channel to inform the caller that
0 commit comments