@@ -249,6 +249,8 @@ func (d *Daemon) startWebServers() error {
249249 )
250250 loop_looprpc .RegisterSwapClientServer (d .grpcServer , d )
251251
252+ loop_looprpc .RegisterAssetsClientServer (d .grpcServer , d .assetsServer )
253+
252254 // Register our debug server if it is compiled in.
253255 d .registerDebugServer ()
254256
@@ -332,7 +334,7 @@ func (d *Daemon) startWebServers() error {
332334 d .wg .Add (1 )
333335 go func () {
334336 defer d .wg .Done ()
335-
337+ defer log . Info ( "REST proxy stopped" )
336338 log .Infof ("REST proxy listening on %s" ,
337339 d .restListener .Addr ())
338340 err := d .restServer .Serve (d .restListener )
@@ -354,7 +356,7 @@ func (d *Daemon) startWebServers() error {
354356 d .wg .Add (1 )
355357 go func () {
356358 defer d .wg .Done ()
357-
359+ defer log . Info ( "RPC server stopped" )
358360 log .Infof ("RPC server listening on %s" , d .grpcListener .Addr ())
359361 err = d .grpcServer .Serve (d .grpcListener )
360362 if err != nil && ! errors .Is (err , grpc .ErrServerStopped ) {
@@ -487,6 +489,11 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
487489 swapClient .Conn ,
488490 )
489491
492+ // Create a assets server client.
493+ assetsClient := loop_swaprpc .NewAssetsSwapServerClient (
494+ swapClient .Conn ,
495+ )
496+
490497 // Both the client RPC server and the swap server client should stop
491498 // on main context cancel. So we create it early and pass it down.
492499 d .mainCtx , d .mainCtxCancel = context .WithCancel (context .Background ())
@@ -636,6 +643,8 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
636643 var (
637644 reservationManager * reservation.Manager
638645 instantOutManager * instantout.Manager
646+ assetManager * assets.AssetsSwapManager
647+ assetClientServer * assets.AssetsClientServer
639648 )
640649
641650 // Create the reservation and instantout managers.
@@ -676,6 +685,27 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
676685 instantOutManager = instantout .NewInstantOutManager (
677686 instantOutConfig ,
678687 )
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 )
679709 }
680710
681711 // Now finally fully initialize the swap client RPC server instance.
@@ -696,6 +726,8 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
696726 withdrawalManager : withdrawalManager ,
697727 staticLoopInManager : staticLoopInManager ,
698728 assetClient : d .assetClient ,
729+ assetManager : assetManager ,
730+ assetsServer : assetClientServer ,
699731 }
700732
701733 // Retrieve all currently existing swaps from the database.
@@ -801,6 +833,10 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
801833 cancel ()
802834 }
803835 }
836+ getInfo , err := d .lnd .Client .GetInfo (d .mainCtx )
837+ if err != nil {
838+ return err
839+ }
804840
805841 // Start the instant out manager.
806842 if d .instantOutManager != nil {
@@ -809,12 +845,6 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
809845 go func () {
810846 defer d .wg .Done ()
811847
812- getInfo , err := d .lnd .Client .GetInfo (d .mainCtx )
813- if err != nil {
814- d .internalErrChan <- err
815- return
816- }
817-
818848 log .Info ("Starting instantout manager" )
819849 defer log .Info ("Instantout manager stopped" )
820850
@@ -933,6 +963,20 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
933963 staticLoopInManager .WaitInitComplete ()
934964 }
935965
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+
936980 // Last, start our internal error handler. This will return exactly one
937981 // error or nil on the main error channel to inform the caller that
938982 // something went wrong or that shutdown is complete. We don't add to
@@ -978,6 +1022,9 @@ func (d *Daemon) Stop() {
9781022
9791023// stop does the actual shutdown and blocks until all goroutines have exit.
9801024func (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 )
9811028 // First of all, we can cancel the main context that all event handlers
9821029 // are using. This should stop all swap activity and all event handlers
9831030 // should exit.
@@ -995,6 +1042,7 @@ func (d *Daemon) stop() {
9951042 if d .restServer != nil {
9961043 // Don't return the error here, we first want to give everything
9971044 // else a chance to shut down cleanly.
1045+
9981046 err := d .restServer .Close ()
9991047 if err != nil {
10001048 log .Errorf ("Error stopping REST server: %v" , err )
0 commit comments