loop: alias import for swapserverrpc in swap server client

pull/446/head
carla 2 years ago
parent 167cef4f6b
commit 3b911cfd4f
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

@ -16,7 +16,7 @@ import (
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/lightninglabs/aperture/lsat" "github.com/lightninglabs/aperture/lsat"
"github.com/lightninglabs/loop/loopdb" "github.com/lightninglabs/loop/loopdb"
"github.com/lightninglabs/loop/swapserverrpc" looprpc "github.com/lightninglabs/loop/swapserverrpc"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/routing/route" "github.com/lightningnetwork/lnd/routing/route"
@ -89,7 +89,7 @@ type swapServerClient interface {
} }
type grpcSwapServerClient struct { type grpcSwapServerClient struct {
server swapserverrpc.SwapServerClient server looprpc.SwapServerClient
conn *grpc.ClientConn conn *grpc.ClientConn
wg sync.WaitGroup wg sync.WaitGroup
@ -124,7 +124,7 @@ func newSwapServerClient(cfg *ClientConfig, lsatStore lsat.Store) (
return nil, err return nil, err
} }
server := swapserverrpc.NewSwapServerClient(serverConn) server := looprpc.NewSwapServerClient(serverConn)
return &grpcSwapServerClient{ return &grpcSwapServerClient{
conn: serverConn, conn: serverConn,
@ -138,7 +138,7 @@ func (s *grpcSwapServerClient) GetLoopOutTerms(ctx context.Context) (
rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout) rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout)
defer rpcCancel() defer rpcCancel()
terms, err := s.server.LoopOutTerms(rpcCtx, terms, err := s.server.LoopOutTerms(rpcCtx,
&swapserverrpc.ServerLoopOutTermsRequest{ &looprpc.ServerLoopOutTermsRequest{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
}, },
) )
@ -161,7 +161,7 @@ func (s *grpcSwapServerClient) GetLoopOutQuote(ctx context.Context,
rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout) rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout)
defer rpcCancel() defer rpcCancel()
quoteResp, err := s.server.LoopOutQuote(rpcCtx, quoteResp, err := s.server.LoopOutQuote(rpcCtx,
&swapserverrpc.ServerLoopOutQuoteRequest{ &looprpc.ServerLoopOutQuoteRequest{
Amt: uint64(amt), Amt: uint64(amt),
SwapPublicationDeadline: swapPublicationDeadline.Unix(), SwapPublicationDeadline: swapPublicationDeadline.Unix(),
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
@ -195,7 +195,7 @@ func (s *grpcSwapServerClient) GetLoopInTerms(ctx context.Context) (
rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout) rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout)
defer rpcCancel() defer rpcCancel()
terms, err := s.server.LoopInTerms(rpcCtx, terms, err := s.server.LoopInTerms(rpcCtx,
&swapserverrpc.ServerLoopInTermsRequest{ &looprpc.ServerLoopInTermsRequest{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
}, },
) )
@ -221,7 +221,7 @@ func (s *grpcSwapServerClient) GetLoopInQuote(ctx context.Context,
rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout) rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout)
defer rpcCancel() defer rpcCancel()
req := &swapserverrpc.ServerLoopInQuoteRequest{ req := &looprpc.ServerLoopInQuoteRequest{
Amt: uint64(amt), Amt: uint64(amt),
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
Pubkey: pubKey[:], Pubkey: pubKey[:],
@ -252,12 +252,12 @@ func (s *grpcSwapServerClient) GetLoopInQuote(ctx context.Context,
// marshallRouteHints marshalls a list of route hints. // marshallRouteHints marshalls a list of route hints.
func marshallRouteHints(routeHints [][]zpay32.HopHint) ( func marshallRouteHints(routeHints [][]zpay32.HopHint) (
[]*swapserverrpc.RouteHint, error) { []*looprpc.RouteHint, error) {
rpcRouteHints := make([]*swapserverrpc.RouteHint, 0, len(routeHints)) rpcRouteHints := make([]*looprpc.RouteHint, 0, len(routeHints))
for _, routeHint := range routeHints { for _, routeHint := range routeHints {
rpcRouteHint := make( rpcRouteHint := make(
[]*swapserverrpc.HopHint, 0, len(routeHint), []*looprpc.HopHint, 0, len(routeHint),
) )
for _, hint := range routeHint { for _, hint := range routeHint {
rpcHint, err := marshallHopHint(hint) rpcHint, err := marshallHopHint(hint)
@ -267,7 +267,7 @@ func marshallRouteHints(routeHints [][]zpay32.HopHint) (
rpcRouteHint = append(rpcRouteHint, rpcHint) rpcRouteHint = append(rpcRouteHint, rpcHint)
} }
rpcRouteHints = append(rpcRouteHints, &swapserverrpc.RouteHint{ rpcRouteHints = append(rpcRouteHints, &looprpc.RouteHint{
HopHints: rpcRouteHint, HopHints: rpcRouteHint,
}) })
} }
@ -276,7 +276,7 @@ func marshallRouteHints(routeHints [][]zpay32.HopHint) (
} }
// marshallHopHint marshalls a single hop hint. // marshallHopHint marshalls a single hop hint.
func marshallHopHint(hint zpay32.HopHint) (*swapserverrpc.HopHint, error) { func marshallHopHint(hint zpay32.HopHint) (*looprpc.HopHint, error) {
nodeID, err := route.NewVertexFromBytes( nodeID, err := route.NewVertexFromBytes(
hint.NodeID.SerializeCompressed(), hint.NodeID.SerializeCompressed(),
) )
@ -284,7 +284,7 @@ func marshallHopHint(hint zpay32.HopHint) (*swapserverrpc.HopHint, error) {
return nil, err return nil, err
} }
return &swapserverrpc.HopHint{ return &looprpc.HopHint{
ChanId: hint.ChannelID, ChanId: hint.ChannelID,
CltvExpiryDelta: uint32(hint.CLTVExpiryDelta), CltvExpiryDelta: uint32(hint.CLTVExpiryDelta),
FeeBaseMsat: hint.FeeBaseMSat, FeeBaseMsat: hint.FeeBaseMSat,
@ -305,7 +305,7 @@ func (s *grpcSwapServerClient) Probe(ctx context.Context, amt btcutil.Amount,
return err return err
} }
req := &swapserverrpc.ServerProbeRequest{ req := &looprpc.ServerProbeRequest{
Amt: uint64(amt), Amt: uint64(amt),
Target: target[:], Target: target[:],
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
@ -328,7 +328,7 @@ func (s *grpcSwapServerClient) NewLoopOutSwap(ctx context.Context,
rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout) rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout)
defer rpcCancel() defer rpcCancel()
swapResp, err := s.server.NewLoopOutSwap(rpcCtx, swapResp, err := s.server.NewLoopOutSwap(rpcCtx,
&swapserverrpc.ServerLoopOutRequest{ &looprpc.ServerLoopOutRequest{
SwapHash: swapHash[:], SwapHash: swapHash[:],
Amt: uint64(amount), Amt: uint64(amount),
ReceiverKey: receiverKey[:], ReceiverKey: receiverKey[:],
@ -367,7 +367,7 @@ func (s *grpcSwapServerClient) PushLoopOutPreimage(ctx context.Context,
defer rpcCancel() defer rpcCancel()
_, err := s.server.LoopOutPushPreimage(rpcCtx, _, err := s.server.LoopOutPushPreimage(rpcCtx,
&swapserverrpc.ServerLoopOutPushPreimageRequest{ &looprpc.ServerLoopOutPushPreimageRequest{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
Preimage: preimage[:], Preimage: preimage[:],
}, },
@ -384,7 +384,7 @@ func (s *grpcSwapServerClient) NewLoopInSwap(ctx context.Context,
rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout) rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout)
defer rpcCancel() defer rpcCancel()
req := &swapserverrpc.ServerLoopInRequest{ req := &looprpc.ServerLoopInRequest{
SwapHash: swapHash[:], SwapHash: swapHash[:],
Amt: uint64(amount), Amt: uint64(amount),
SenderKey: senderKey[:], SenderKey: senderKey[:],
@ -421,7 +421,7 @@ func (s *grpcSwapServerClient) NewLoopInSwap(ctx context.Context,
// ServerUpdate summarizes an update from the swap server. // ServerUpdate summarizes an update from the swap server.
type ServerUpdate struct { type ServerUpdate struct {
// State is the state that the server has sent us. // State is the state that the server has sent us.
State swapserverrpc.ServerSwapState State looprpc.ServerSwapState
// Timestamp is the time of the server state update. // Timestamp is the time of the server state update.
Timestamp time.Time Timestamp time.Time
@ -433,7 +433,7 @@ func (s *grpcSwapServerClient) SubscribeLoopInUpdates(ctx context.Context,
hash lntypes.Hash) (<-chan *ServerUpdate, <-chan error, error) { hash lntypes.Hash) (<-chan *ServerUpdate, <-chan error, error) {
resp, err := s.server.SubscribeLoopInUpdates( resp, err := s.server.SubscribeLoopInUpdates(
ctx, &swapserverrpc.SubscribeUpdatesRequest{ ctx, &looprpc.SubscribeUpdatesRequest{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
SwapHash: hash[:], SwapHash: hash[:],
}, },
@ -464,7 +464,7 @@ func (s *grpcSwapServerClient) SubscribeLoopOutUpdates(ctx context.Context,
hash lntypes.Hash) (<-chan *ServerUpdate, <-chan error, error) { hash lntypes.Hash) (<-chan *ServerUpdate, <-chan error, error) {
resp, err := s.server.SubscribeLoopOutUpdates( resp, err := s.server.SubscribeLoopOutUpdates(
ctx, &swapserverrpc.SubscribeUpdatesRequest{ ctx, &looprpc.SubscribeUpdatesRequest{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
SwapHash: hash[:], SwapHash: hash[:],
}, },
@ -603,7 +603,7 @@ type outCancelDetails struct {
func (s *grpcSwapServerClient) CancelLoopOutSwap(ctx context.Context, func (s *grpcSwapServerClient) CancelLoopOutSwap(ctx context.Context,
details *outCancelDetails) error { details *outCancelDetails) error {
req := &swapserverrpc.CancelLoopOutSwapRequest{ req := &looprpc.CancelLoopOutSwapRequest{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
SwapHash: details.hash[:], SwapHash: details.hash[:],
PaymentAddress: details.paymentAddr[:], PaymentAddress: details.paymentAddr[:],
@ -620,24 +620,24 @@ func (s *grpcSwapServerClient) CancelLoopOutSwap(ctx context.Context,
} }
func rpcRouteCancel(details *outCancelDetails) ( func rpcRouteCancel(details *outCancelDetails) (
*swapserverrpc.CancelLoopOutSwapRequest_RouteCancel, error) { *looprpc.CancelLoopOutSwapRequest_RouteCancel, error) {
attempts := make( attempts := make(
[]*swapserverrpc.HtlcAttempt, len(details.metadata.attempts), []*looprpc.HtlcAttempt, len(details.metadata.attempts),
) )
for i, remaining := range details.metadata.attempts { for i, remaining := range details.metadata.attempts {
attempts[i] = &swapserverrpc.HtlcAttempt{ attempts[i] = &looprpc.HtlcAttempt{
RemainingHops: remaining, RemainingHops: remaining,
} }
} }
resp := &swapserverrpc.CancelLoopOutSwapRequest_RouteCancel{ resp := &looprpc.CancelLoopOutSwapRequest_RouteCancel{
RouteCancel: &swapserverrpc.RouteCancel{ RouteCancel: &looprpc.RouteCancel{
Attempts: attempts, Attempts: attempts,
// We can cast our lnd failure reason to a loop payment // We can cast our lnd failure reason to a loop payment
// failure reason because these values are copied 1:1 // failure reason because these values are copied 1:1
// from lnd. // from lnd.
Failure: swapserverrpc.PaymentFailureReason( Failure: looprpc.PaymentFailureReason(
details.metadata.failureReason, details.metadata.failureReason,
), ),
}, },
@ -645,10 +645,10 @@ func rpcRouteCancel(details *outCancelDetails) (
switch details.metadata.paymentType { switch details.metadata.paymentType {
case paymentTypePrepay: case paymentTypePrepay:
resp.RouteCancel.RouteType = swapserverrpc.RoutePaymentType_PREPAY_ROUTE resp.RouteCancel.RouteType = looprpc.RoutePaymentType_PREPAY_ROUTE
case paymentTypeInvoice: case paymentTypeInvoice:
resp.RouteCancel.RouteType = swapserverrpc.RoutePaymentType_INVOICE_ROUTE resp.RouteCancel.RouteType = looprpc.RoutePaymentType_INVOICE_ROUTE
default: default:
return nil, fmt.Errorf("unknown payment type: %v", return nil, fmt.Errorf("unknown payment type: %v",

Loading…
Cancel
Save