@@ -249,6 +249,8 @@ func (d *Daemon) startWebServers() error {
249
249
)
250
250
loop_looprpc .RegisterSwapClientServer (d .grpcServer , d )
251
251
252
+ loop_looprpc .RegisterAssetsClientServer (d .grpcServer , d .assetsServer )
253
+
252
254
// Register our debug server if it is compiled in.
253
255
d .registerDebugServer ()
254
256
@@ -332,7 +334,7 @@ func (d *Daemon) startWebServers() error {
332
334
d .wg .Add (1 )
333
335
go func () {
334
336
defer d .wg .Done ()
335
-
337
+ defer log . Info ( "REST proxy stopped" )
336
338
log .Infof ("REST proxy listening on %s" ,
337
339
d .restListener .Addr ())
338
340
err := d .restServer .Serve (d .restListener )
@@ -354,7 +356,7 @@ func (d *Daemon) startWebServers() error {
354
356
d .wg .Add (1 )
355
357
go func () {
356
358
defer d .wg .Done ()
357
-
359
+ defer log . Info ( "RPC server stopped" )
358
360
log .Infof ("RPC server listening on %s" , d .grpcListener .Addr ())
359
361
err = d .grpcServer .Serve (d .grpcListener )
360
362
if err != nil && ! errors .Is (err , grpc .ErrServerStopped ) {
@@ -487,6 +489,11 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
487
489
swapClient .Conn ,
488
490
)
489
491
492
+ // Create a assets server client.
493
+ assetsClient := loop_swaprpc .NewAssetsSwapServerClient (
494
+ swapClient .Conn ,
495
+ )
496
+
490
497
// Both the client RPC server and the swap server client should stop
491
498
// on main context cancel. So we create it early and pass it down.
492
499
d .mainCtx , d .mainCtxCancel = context .WithCancel (context .Background ())
@@ -636,6 +643,8 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
636
643
var (
637
644
reservationManager * reservation.Manager
638
645
instantOutManager * instantout.Manager
646
+ assetManager * assets.AssetsSwapManager
647
+ assetClientServer * assets.AssetsClientServer
639
648
)
640
649
641
650
// Create the reservation and instantout managers.
@@ -676,6 +685,27 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
676
685
instantOutManager = instantout .NewInstantOutManager (
677
686
instantOutConfig ,
678
687
)
688
+
689
+ tapdClient , err := assets .NewTapdClient (
690
+ d .cfg .TapdConfig ,
691
+ )
692
+ if err != nil {
693
+ return err
694
+ }
695
+ assetsStore := assets .NewPostgresStore (baseDb )
696
+ assetsConfig := & assets.Config {
697
+ ServerClient : assetsClient ,
698
+ Store : assetsStore ,
699
+ AssetClient : tapdClient ,
700
+ LndClient : d .lnd .Client ,
701
+ Router : d .lnd .Router ,
702
+ ChainNotifier : d .lnd .ChainNotifier ,
703
+ Signer : d .lnd .Signer ,
704
+ Wallet : d .lnd .WalletKit ,
705
+ ExchangeRateProvider : assets .NewFixedExchangeRateProvider (),
706
+ }
707
+ assetManager = assets .NewAssetSwapServer (assetsConfig )
708
+ assetClientServer = assets .NewAssetsServer (assetManager )
679
709
}
680
710
681
711
// Now finally fully initialize the swap client RPC server instance.
@@ -696,6 +726,8 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
696
726
withdrawalManager : withdrawalManager ,
697
727
staticLoopInManager : staticLoopInManager ,
698
728
assetClient : d .assetClient ,
729
+ assetManager : assetManager ,
730
+ assetsServer : assetClientServer ,
699
731
}
700
732
701
733
// Retrieve all currently existing swaps from the database.
@@ -801,6 +833,10 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
801
833
cancel ()
802
834
}
803
835
}
836
+ getInfo , err := d .lnd .Client .GetInfo (d .mainCtx )
837
+ if err != nil {
838
+ return err
839
+ }
804
840
805
841
// Start the instant out manager.
806
842
if d .instantOutManager != nil {
@@ -809,12 +845,6 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
809
845
go func () {
810
846
defer d .wg .Done ()
811
847
812
- getInfo , err := d .lnd .Client .GetInfo (d .mainCtx )
813
- if err != nil {
814
- d .internalErrChan <- err
815
- return
816
- }
817
-
818
848
log .Info ("Starting instantout manager" )
819
849
defer log .Info ("Instantout manager stopped" )
820
850
@@ -933,6 +963,20 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
933
963
staticLoopInManager .WaitInitComplete ()
934
964
}
935
965
966
+ // Start the asset manager.
967
+ if d .assetManager != nil {
968
+ d .wg .Add (1 )
969
+ go func () {
970
+ defer d .wg .Done ()
971
+ log .Infof ("Starting asset manager" )
972
+ defer log .Infof ("Asset manager stopped" )
973
+ err := d .assetManager .Run (d .mainCtx , int32 (getInfo .BlockHeight ))
974
+ if err != nil && ! errors .Is (err , context .Canceled ) {
975
+ d .internalErrChan <- err
976
+ }
977
+ }()
978
+ }
979
+
936
980
// Last, start our internal error handler. This will return exactly one
937
981
// error or nil on the main error channel to inform the caller that
938
982
// something went wrong or that shutdown is complete. We don't add to
@@ -978,6 +1022,9 @@ func (d *Daemon) Stop() {
978
1022
979
1023
// stop does the actual shutdown and blocks until all goroutines have exit.
980
1024
func (d * Daemon ) stop () {
1025
+ // Sleep a second in order to fix a blocking issue when having a
1026
+ // startup error.
1027
+ <- time .After (time .Second )
981
1028
// First of all, we can cancel the main context that all event handlers
982
1029
// are using. This should stop all swap activity and all event handlers
983
1030
// should exit.
@@ -995,6 +1042,7 @@ func (d *Daemon) stop() {
995
1042
if d .restServer != nil {
996
1043
// Don't return the error here, we first want to give everything
997
1044
// else a chance to shut down cleanly.
1045
+
998
1046
err := d .restServer .Close ()
999
1047
if err != nil {
1000
1048
log .Errorf ("Error stopping REST server: %v" , err )
0 commit comments