@@ -16,6 +16,7 @@ import (
1616 proxy "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
1717 "github.com/lightninglabs/lndclient"
1818 "github.com/lightninglabs/loop"
19+ "github.com/lightninglabs/loop/hyperloop"
1920 "github.com/lightninglabs/loop/instantout"
2021 "github.com/lightninglabs/loop/instantout/reservation"
2122 "github.com/lightninglabs/loop/loopd/perms"
@@ -450,6 +451,11 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
450451 swapClient .Conn ,
451452 )
452453
454+ // Create a hyperloop server client.
455+ hyperloopClient := loop_swaprpc .NewHyperloopServerClient (
456+ swapClient .Conn ,
457+ )
458+
453459 // Both the client RPC server and the swap server client should stop
454460 // on main context cancel. So we create it early and pass it down.
455461 d .mainCtx , d .mainCtxCancel = context .WithCancel (context .Background ())
@@ -529,6 +535,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
529535 var (
530536 reservationManager * reservation.Manager
531537 instantOutManager * instantout.Manager
538+ hyperloopManager * hyperloop.Manager
532539 )
533540
534541 // Create the reservation and instantout managers.
@@ -569,6 +576,16 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
569576 instantOutManager = instantout .NewInstantOutManager (
570577 instantOutConfig ,
571578 )
579+
580+ hyperloopConfig := & hyperloop.Config {
581+ Wallet : d .lnd .WalletKit ,
582+ ChainNotifier : d .lnd .ChainNotifier ,
583+ Signer : d .lnd .Signer ,
584+ Router : d .lnd .Router ,
585+ HyperloopClient : hyperloopClient ,
586+ ChainParams : d .lnd .ChainParams ,
587+ }
588+ hyperloopManager = hyperloop .NewManager (hyperloopConfig )
572589 }
573590
574591 // Now finally fully initialize the swap client RPC server instance.
@@ -584,6 +601,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
584601 mainCtx : d .mainCtx ,
585602 reservationManager : reservationManager ,
586603 instantOutManager : instantOutManager ,
604+ hyperloopManager : hyperloopManager ,
587605 }
588606
589607 // Retrieve all currently existing swaps from the database.
@@ -728,6 +746,34 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
728746 }
729747 }
730748
749+ // Start the hyperloop manager.
750+ if d .hyperloopManager != nil {
751+ d .wg .Add (1 )
752+ go func () {
753+ defer d .wg .Done ()
754+
755+ log .Info ("Starting hyperloop manager" )
756+ defer log .Info ("Hyperloop manager stopped" )
757+
758+ // We need to know the current block height to properly
759+ // initialize the hyperloop manager.
760+ getInfo , err := d .lnd .Client .GetInfo (d .mainCtx )
761+ if err != nil {
762+ d .internalErrChan <- err
763+ return
764+ }
765+
766+ err = d .hyperloopManager .Run (
767+ d .mainCtx , int32 (getInfo .BlockHeight ),
768+ )
769+ if err != nil && ! errors .Is (err , context .Canceled ) {
770+ log .Errorf ("Error running hyperloop manager:" +
771+ " %v" , err )
772+ d .internalErrChan <- err
773+ }
774+ }()
775+ }
776+
731777 // Last, start our internal error handler. This will return exactly one
732778 // error or nil on the main error channel to inform the caller that
733779 // something went wrong or that shutdown is complete. We don't add to
0 commit comments