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