diff --git a/server_mock_test.go b/server_mock_test.go index e26f771..8162c89 100644 --- a/server_mock_test.go +++ b/server_mock_test.go @@ -242,3 +242,9 @@ func (s *serverMock) Probe(ctx context.Context, amt btcutil.Amount, return nil } + +func (s *serverMock) loopOutHints(_ context.Context, _ btcutil.Amount, + _ int) ([]*loopOutHint, error) { + + return nil, nil +} diff --git a/swap_server_client.go b/swap_server_client.go index aaabd1a..5624620 100644 --- a/swap_server_client.go +++ b/swap_server_client.go @@ -19,6 +19,7 @@ import ( "github.com/lightninglabs/loop/looprpc" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lntypes" + "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/routing/route" "github.com/lightningnetwork/lnd/tor" "github.com/lightningnetwork/lnd/zpay32" @@ -86,6 +87,9 @@ type swapServerClient interface { // CancelLoopOutSwap cancels a loop out swap. CancelLoopOutSwap(ctx context.Context, details *outCancelDetails) error + + loopOutHints(ctx context.Context, + amount btcutil.Amount, shards int) ([]*loopOutHint, error) } type grpcSwapServerClient struct { @@ -648,6 +652,53 @@ func rpcRouteCancel(details *outCancelDetails) ( return resp, nil } +type loopOutHint struct { + fromNode route.Vertex + toNode route.Vertex + failAmt lnwire.MilliSatoshi + successAmt lnwire.MilliSatoshi + timestamp time.Time +} + +// loopOutHints provides routing hints for loop out off-chain routing. +func (s *grpcSwapServerClient) loopOutHints(ctx context.Context, + amount btcutil.Amount, shards int) ([]*loopOutHint, error) { + + req := &looprpc.LoopOutHintsRequest{ + ProtocolVersion: loopdb.CurrentRPCProtocolVersion, + AmtSat: uint64(amount), + Shards: uint32(shards), + } + + resp, err := s.server.LoopOutHints(ctx, req) + if err != nil { + return nil, err + } + + hints := make([]*loopOutHint, len(resp.Hints)) + for i, hint := range resp.Hints { + from, err := route.NewVertexFromBytes(hint.FromNode) + if err != nil { + return nil, err + } + + to, err := route.NewVertexFromBytes(hint.ToNode) + if err != nil { + return nil, err + } + + hints[i] = &loopOutHint{ + fromNode: from, + toNode: to, + failAmt: lnwire.MilliSatoshi(hint.FailMsat), + successAmt: lnwire.MilliSatoshi(hint.SuccessMsat), + timestamp: time.Unix(int64(hint.Timestamp), 0), + } + } + + return hints, nil +} + // getSwapServerConn returns a connection to the swap server. A non-empty // proxyAddr indicates that a SOCKS proxy found at the address should be used to // establish the connection.