@@ -248,6 +248,8 @@ func (d *Daemon) startWebServers() error {
248
248
)
249
249
loop_looprpc .RegisterSwapClientServer (d .grpcServer , d )
250
250
251
+ loop_looprpc .RegisterAssetsClientServer (d .grpcServer , d .assetsServer )
252
+
251
253
// Register our debug server if it is compiled in.
252
254
d .registerDebugServer ()
253
255
@@ -494,6 +496,11 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
494
496
swapClient .Conn ,
495
497
)
496
498
499
+ // Create a assets server client.
500
+ assetsClient := loop_swaprpc .NewAssetsSwapServerClient (
501
+ swapClient .Conn ,
502
+ )
503
+
497
504
// Both the client RPC server and the swap server client should stop
498
505
// on main context cancel. So we create it early and pass it down.
499
506
d .mainCtx , d .mainCtxCancel = context .WithCancel (context .Background ())
@@ -643,6 +650,8 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
643
650
var (
644
651
reservationManager * reservation.Manager
645
652
instantOutManager * instantout.Manager
653
+ assetManager * assets.AssetsSwapManager
654
+ assetClientServer * assets.AssetsClientServer
646
655
)
647
656
648
657
// Create the reservation and instantout managers.
@@ -683,6 +692,27 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
683
692
instantOutManager = instantout .NewInstantOutManager (
684
693
instantOutConfig , int32 (blockHeight ),
685
694
)
695
+
696
+ tapdClient , err := assets .NewTapdClient (
697
+ d .cfg .TapdConfig ,
698
+ )
699
+ if err != nil {
700
+ return err
701
+ }
702
+ assetsStore := assets .NewPostgresStore (baseDb )
703
+ assetsConfig := & assets.Config {
704
+ ServerClient : assetsClient ,
705
+ Store : assetsStore ,
706
+ AssetClient : tapdClient ,
707
+ LndClient : d .lnd .Client ,
708
+ Router : d .lnd .Router ,
709
+ ChainNotifier : d .lnd .ChainNotifier ,
710
+ Signer : d .lnd .Signer ,
711
+ Wallet : d .lnd .WalletKit ,
712
+ ExchangeRateProvider : assets .NewFixedExchangeRateProvider (),
713
+ }
714
+ assetManager = assets .NewAssetSwapServer (assetsConfig )
715
+ assetClientServer = assets .NewAssetsServer (assetManager )
686
716
}
687
717
688
718
// Now finally fully initialize the swap client RPC server instance.
@@ -703,6 +733,8 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
703
733
withdrawalManager : withdrawalManager ,
704
734
staticLoopInManager : staticLoopInManager ,
705
735
assetClient : d .assetClient ,
736
+ assetManager : assetManager ,
737
+ assetsServer : assetClientServer ,
706
738
}
707
739
708
740
// Retrieve all currently existing swaps from the database.
@@ -897,6 +929,20 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
897
929
staticLoopInManager .WaitInitComplete ()
898
930
}
899
931
932
+ // Start the asset manager.
933
+ if d .assetManager != nil {
934
+ d .wg .Add (1 )
935
+ go func () {
936
+ defer d .wg .Done ()
937
+ infof ("Starting asset manager" )
938
+ defer infof ("Asset manager stopped" )
939
+ err := d .assetManager .Run (d .mainCtx , int32 (getInfo .BlockHeight ))
940
+ if err != nil && ! errors .Is (err , context .Canceled ) {
941
+ d .internalErrChan <- err
942
+ }
943
+ }()
944
+ }
945
+
900
946
// Last, start our internal error handler. This will return exactly one
901
947
// error or nil on the main error channel to inform the caller that
902
948
// something went wrong or that shutdown is complete. We don't add to
@@ -942,6 +988,9 @@ func (d *Daemon) Stop() {
942
988
943
989
// stop does the actual shutdown and blocks until all goroutines have exit.
944
990
func (d * Daemon ) stop () {
991
+ // Sleep a second in order to fix a blocking issue when having a
992
+ // startup error.
993
+ <- time .After (time .Second )
945
994
// First of all, we can cancel the main context that all event handlers
946
995
// are using. This should stop all swap activity and all event handlers
947
996
// should exit.
@@ -959,6 +1008,7 @@ func (d *Daemon) stop() {
959
1008
if d .restServer != nil {
960
1009
// Don't return the error here, we first want to give everything
961
1010
// else a chance to shut down cleanly.
1011
+
962
1012
err := d .restServer .Close ()
963
1013
if err != nil {
964
1014
errorf ("Error stopping REST server: %v" , err )
0 commit comments