@@ -2,12 +2,14 @@ package loopd
2
2
3
3
import (
4
4
"context"
5
+ "encoding/hex"
5
6
"errors"
6
7
"fmt"
7
8
"sort"
8
9
"sync"
9
10
"time"
10
11
12
+ "github.com/btcsuite/btcd/btcec"
11
13
"github.com/btcsuite/btcd/chaincfg"
12
14
"github.com/btcsuite/btcutil"
13
15
"github.com/lightninglabs/lndclient"
@@ -22,6 +24,7 @@ import (
22
24
"github.com/lightningnetwork/lnd/lnwire"
23
25
"github.com/lightningnetwork/lnd/queue"
24
26
"github.com/lightningnetwork/lnd/routing/route"
27
+ "github.com/lightningnetwork/lnd/zpay32"
25
28
"google.golang.org/grpc/codes"
26
29
"google.golang.org/grpc/status"
27
30
)
@@ -480,10 +483,29 @@ func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
480
483
return nil , err
481
484
}
482
485
486
+ var lastHop * route.Vertex
487
+ if req .LoopInLastHop != nil {
488
+ lastHopVertex , err := route .NewVertexFromBytes (
489
+ req .LoopInLastHop ,
490
+ )
491
+ if err != nil {
492
+ return nil , err
493
+ }
494
+
495
+ lastHop = & lastHopVertex
496
+ }
497
+
498
+ routeHints , err := unmarshallRouteHints (req .LoopInRouteHints )
499
+ if err != nil {
500
+ return nil , err
501
+ }
502
+
483
503
quote , err := s .impl .LoopInQuote (ctx , & loop.LoopInQuoteRequest {
484
504
Amount : btcutil .Amount (req .Amt ),
485
505
HtlcConfTarget : htlcConfTarget ,
486
506
ExternalHtlc : req .ExternalHtlc ,
507
+ LastHop : lastHop ,
508
+ RouteHints : routeHints ,
487
509
})
488
510
if err != nil {
489
511
return nil , err
@@ -495,6 +517,84 @@ func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
495
517
}, nil
496
518
}
497
519
520
+ // unmarshallRouteHints unmarshalls a list of route hints.
521
+ func unmarshallRouteHints (rpcRouteHints []* looprpc.RouteHint ) (
522
+ [][]zpay32.HopHint , error ) {
523
+
524
+ routeHints := make ([][]zpay32.HopHint , 0 , len (rpcRouteHints ))
525
+ for _ , rpcRouteHint := range rpcRouteHints {
526
+ routeHint := make (
527
+ []zpay32.HopHint , 0 , len (rpcRouteHint .HopHints ),
528
+ )
529
+ for _ , rpcHint := range rpcRouteHint .HopHints {
530
+ hint , err := unmarshallHopHint (rpcHint )
531
+ if err != nil {
532
+ return nil , err
533
+ }
534
+
535
+ routeHint = append (routeHint , hint )
536
+ }
537
+ routeHints = append (routeHints , routeHint )
538
+ }
539
+
540
+ return routeHints , nil
541
+ }
542
+
543
+ // unmarshallHopHint unmarshalls a single hop hint.
544
+ func unmarshallHopHint (rpcHint * looprpc.HopHint ) (zpay32.HopHint , error ) {
545
+ pubBytes , err := hex .DecodeString (rpcHint .NodeId )
546
+ if err != nil {
547
+ return zpay32.HopHint {}, err
548
+ }
549
+
550
+ pubkey , err := btcec .ParsePubKey (pubBytes , btcec .S256 ())
551
+ if err != nil {
552
+ return zpay32.HopHint {}, err
553
+ }
554
+
555
+ return zpay32.HopHint {
556
+ NodeID : pubkey ,
557
+ ChannelID : rpcHint .ChanId ,
558
+ FeeBaseMSat : rpcHint .FeeBaseMsat ,
559
+ FeeProportionalMillionths : rpcHint .FeeProportionalMillionths ,
560
+ CLTVExpiryDelta : uint16 (rpcHint .CltvExpiryDelta ),
561
+ }, nil
562
+ }
563
+
564
+ // Probe requests the server to probe the client's node to test inbound
565
+ // liquidity.
566
+ func (s * swapClientServer ) Probe (ctx context.Context ,
567
+ req * looprpc.ProbeRequest ) (* looprpc.ProbeResponse , error ) {
568
+
569
+ log .Infof ("Probe request received" )
570
+
571
+ var lastHop * route.Vertex
572
+ if req .LastHop != nil {
573
+ lastHopVertex , err := route .NewVertexFromBytes (req .LastHop )
574
+ if err != nil {
575
+ return nil , err
576
+ }
577
+
578
+ lastHop = & lastHopVertex
579
+ }
580
+
581
+ routeHints , err := unmarshallRouteHints (req .RouteHints )
582
+ if err != nil {
583
+ return nil , err
584
+ }
585
+
586
+ err = s .impl .Probe (ctx , & loop.ProbeRequest {
587
+ Amount : btcutil .Amount (req .Amt ),
588
+ LastHop : lastHop ,
589
+ RouteHints : routeHints ,
590
+ })
591
+ if err != nil {
592
+ return nil , err
593
+ }
594
+
595
+ return & looprpc.ProbeResponse {}, nil
596
+ }
597
+
498
598
func (s * swapClientServer ) LoopIn (ctx context.Context ,
499
599
in * looprpc.LoopInRequest ) (
500
600
* looprpc.SwapResponse , error ) {
0 commit comments