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