Merge pull request #446 from carlaKC/alias-imports

multi: always alias swapserverrpc import for use as a package
pull/447/head
Carla Kirk-Cohen 2 years ago committed by GitHub
commit c523789f21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,9 +17,9 @@ import (
"github.com/lightninglabs/loop/labels" "github.com/lightninglabs/loop/labels"
"github.com/lightninglabs/loop/liquidity" "github.com/lightninglabs/loop/liquidity"
"github.com/lightninglabs/loop/loopdb" "github.com/lightninglabs/loop/loopdb"
"github.com/lightninglabs/loop/looprpc" clientrpc "github.com/lightninglabs/loop/looprpc"
"github.com/lightninglabs/loop/swap" "github.com/lightninglabs/loop/swap"
"github.com/lightninglabs/loop/swapserverrpc" looprpc "github.com/lightninglabs/loop/swapserverrpc"
"github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwallet/chainfee" "github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
@ -60,8 +60,8 @@ var (
// swapClientServer implements the grpc service exposed by loopd. // swapClientServer implements the grpc service exposed by loopd.
type swapClientServer struct { type swapClientServer struct {
// Required by the grpc-gateway/v2 library for forward compatibility. // Required by the grpc-gateway/v2 library for forward compatibility.
looprpc.UnimplementedSwapClientServer clientrpc.UnimplementedSwapClientServer
looprpc.UnimplementedDebugServer clientrpc.UnimplementedDebugServer
network lndclient.Network network lndclient.Network
impl *loop.Client impl *loop.Client
@ -80,8 +80,8 @@ type swapClientServer struct {
// onwards, progress can be tracked via the LoopOutStatus stream that is // onwards, progress can be tracked via the LoopOutStatus stream that is
// returned from Monitor(). // returned from Monitor().
func (s *swapClientServer) LoopOut(ctx context.Context, func (s *swapClientServer) LoopOut(ctx context.Context,
in *looprpc.LoopOutRequest) ( in *clientrpc.LoopOutRequest) (
*looprpc.SwapResponse, error) { *clientrpc.SwapResponse, error) {
log.Infof("Loop out request received") log.Infof("Loop out request received")
@ -146,7 +146,7 @@ func (s *swapClientServer) LoopOut(ctx context.Context,
return nil, err return nil, err
} }
return &looprpc.SwapResponse{ return &clientrpc.SwapResponse{
Id: info.SwapHash.String(), Id: info.SwapHash.String(),
IdBytes: info.SwapHash[:], IdBytes: info.SwapHash[:],
HtlcAddress: info.HtlcAddressP2WSH.String(), HtlcAddress: info.HtlcAddressP2WSH.String(),
@ -156,11 +156,11 @@ func (s *swapClientServer) LoopOut(ctx context.Context,
} }
func (s *swapClientServer) marshallSwap(loopSwap *loop.SwapInfo) ( func (s *swapClientServer) marshallSwap(loopSwap *loop.SwapInfo) (
*looprpc.SwapStatus, error) { *clientrpc.SwapStatus, error) {
var ( var (
state looprpc.SwapState state clientrpc.SwapState
failureReason = looprpc.FailureReason_FAILURE_REASON_NONE failureReason = clientrpc.FailureReason_FAILURE_REASON_NONE
) )
// Set our state var for non-failure states. If we get a failure, we // Set our state var for non-failure states. If we get a failure, we
@ -170,37 +170,37 @@ func (s *swapClientServer) marshallSwap(loopSwap *loop.SwapInfo) (
// states, and set our failed state for all of them. // states, and set our failed state for all of them.
switch loopSwap.State { switch loopSwap.State {
case loopdb.StateInitiated: case loopdb.StateInitiated:
state = looprpc.SwapState_INITIATED state = clientrpc.SwapState_INITIATED
case loopdb.StatePreimageRevealed: case loopdb.StatePreimageRevealed:
state = looprpc.SwapState_PREIMAGE_REVEALED state = clientrpc.SwapState_PREIMAGE_REVEALED
case loopdb.StateHtlcPublished: case loopdb.StateHtlcPublished:
state = looprpc.SwapState_HTLC_PUBLISHED state = clientrpc.SwapState_HTLC_PUBLISHED
case loopdb.StateInvoiceSettled: case loopdb.StateInvoiceSettled:
state = looprpc.SwapState_INVOICE_SETTLED state = clientrpc.SwapState_INVOICE_SETTLED
case loopdb.StateSuccess: case loopdb.StateSuccess:
state = looprpc.SwapState_SUCCESS state = clientrpc.SwapState_SUCCESS
case loopdb.StateFailOffchainPayments: case loopdb.StateFailOffchainPayments:
failureReason = looprpc.FailureReason_FAILURE_REASON_OFFCHAIN failureReason = clientrpc.FailureReason_FAILURE_REASON_OFFCHAIN
case loopdb.StateFailTimeout: case loopdb.StateFailTimeout:
failureReason = looprpc.FailureReason_FAILURE_REASON_TIMEOUT failureReason = clientrpc.FailureReason_FAILURE_REASON_TIMEOUT
case loopdb.StateFailSweepTimeout: case loopdb.StateFailSweepTimeout:
failureReason = looprpc.FailureReason_FAILURE_REASON_SWEEP_TIMEOUT failureReason = clientrpc.FailureReason_FAILURE_REASON_SWEEP_TIMEOUT
case loopdb.StateFailInsufficientValue: case loopdb.StateFailInsufficientValue:
failureReason = looprpc.FailureReason_FAILURE_REASON_INSUFFICIENT_VALUE failureReason = clientrpc.FailureReason_FAILURE_REASON_INSUFFICIENT_VALUE
case loopdb.StateFailTemporary: case loopdb.StateFailTemporary:
failureReason = looprpc.FailureReason_FAILURE_REASON_TEMPORARY failureReason = clientrpc.FailureReason_FAILURE_REASON_TEMPORARY
case loopdb.StateFailIncorrectHtlcAmt: case loopdb.StateFailIncorrectHtlcAmt:
failureReason = looprpc.FailureReason_FAILURE_REASON_INCORRECT_AMOUNT failureReason = clientrpc.FailureReason_FAILURE_REASON_INCORRECT_AMOUNT
default: default:
return nil, fmt.Errorf("unknown swap state: %v", loopSwap.State) return nil, fmt.Errorf("unknown swap state: %v", loopSwap.State)
@ -208,16 +208,16 @@ func (s *swapClientServer) marshallSwap(loopSwap *loop.SwapInfo) (
// If we have a failure reason, we have a failure state, so should use // If we have a failure reason, we have a failure state, so should use
// our catchall failed state. // our catchall failed state.
if failureReason != looprpc.FailureReason_FAILURE_REASON_NONE { if failureReason != clientrpc.FailureReason_FAILURE_REASON_NONE {
state = looprpc.SwapState_FAILED state = clientrpc.SwapState_FAILED
} }
var swapType looprpc.SwapType var swapType clientrpc.SwapType
var htlcAddress, htlcAddressP2WSH, htlcAddressNP2WSH string var htlcAddress, htlcAddressP2WSH, htlcAddressNP2WSH string
switch loopSwap.SwapType { switch loopSwap.SwapType {
case swap.TypeIn: case swap.TypeIn:
swapType = looprpc.SwapType_LOOP_IN swapType = clientrpc.SwapType_LOOP_IN
htlcAddressP2WSH = loopSwap.HtlcAddressP2WSH.EncodeAddress() htlcAddressP2WSH = loopSwap.HtlcAddressP2WSH.EncodeAddress()
if loopSwap.ExternalHtlc { if loopSwap.ExternalHtlc {
@ -228,7 +228,7 @@ func (s *swapClientServer) marshallSwap(loopSwap *loop.SwapInfo) (
} }
case swap.TypeOut: case swap.TypeOut:
swapType = looprpc.SwapType_LOOP_OUT swapType = clientrpc.SwapType_LOOP_OUT
htlcAddressP2WSH = loopSwap.HtlcAddressP2WSH.EncodeAddress() htlcAddressP2WSH = loopSwap.HtlcAddressP2WSH.EncodeAddress()
htlcAddress = htlcAddressP2WSH htlcAddress = htlcAddressP2WSH
@ -236,7 +236,7 @@ func (s *swapClientServer) marshallSwap(loopSwap *loop.SwapInfo) (
return nil, errors.New("unknown swap type") return nil, errors.New("unknown swap type")
} }
return &looprpc.SwapStatus{ return &clientrpc.SwapStatus{
Amt: int64(loopSwap.AmountRequested), Amt: int64(loopSwap.AmountRequested),
Id: loopSwap.SwapHash.String(), Id: loopSwap.SwapHash.String(),
IdBytes: loopSwap.SwapHash[:], IdBytes: loopSwap.SwapHash[:],
@ -256,8 +256,8 @@ func (s *swapClientServer) marshallSwap(loopSwap *loop.SwapInfo) (
} }
// Monitor will return a stream of swap updates for currently active swaps. // Monitor will return a stream of swap updates for currently active swaps.
func (s *swapClientServer) Monitor(in *looprpc.MonitorRequest, func (s *swapClientServer) Monitor(in *clientrpc.MonitorRequest,
server looprpc.SwapClient_MonitorServer) error { server clientrpc.SwapClient_MonitorServer) error {
log.Infof("Monitor request received") log.Infof("Monitor request received")
@ -358,10 +358,10 @@ func (s *swapClientServer) Monitor(in *looprpc.MonitorRequest,
// ListSwaps returns a list of all currently known swaps and their current // ListSwaps returns a list of all currently known swaps and their current
// status. // status.
func (s *swapClientServer) ListSwaps(_ context.Context, func (s *swapClientServer) ListSwaps(_ context.Context,
_ *looprpc.ListSwapsRequest) (*looprpc.ListSwapsResponse, error) { _ *clientrpc.ListSwapsRequest) (*clientrpc.ListSwapsResponse, error) {
var ( var (
rpcSwaps = make([]*looprpc.SwapStatus, len(s.swaps)) rpcSwaps = make([]*clientrpc.SwapStatus, len(s.swaps))
idx = 0 idx = 0
err error err error
) )
@ -381,12 +381,12 @@ func (s *swapClientServer) ListSwaps(_ context.Context,
} }
idx++ idx++
} }
return &looprpc.ListSwapsResponse{Swaps: rpcSwaps}, nil return &clientrpc.ListSwapsResponse{Swaps: rpcSwaps}, nil
} }
// SwapInfo returns all known details about a single swap. // SwapInfo returns all known details about a single swap.
func (s *swapClientServer) SwapInfo(_ context.Context, func (s *swapClientServer) SwapInfo(_ context.Context,
req *looprpc.SwapInfoRequest) (*looprpc.SwapStatus, error) { req *clientrpc.SwapInfoRequest) (*clientrpc.SwapStatus, error) {
swapHash, err := lntypes.MakeHash(req.Id) swapHash, err := lntypes.MakeHash(req.Id)
if err != nil { if err != nil {
@ -404,7 +404,7 @@ func (s *swapClientServer) SwapInfo(_ context.Context,
// LoopOutTerms returns the terms that the server enforces for loop out swaps. // LoopOutTerms returns the terms that the server enforces for loop out swaps.
func (s *swapClientServer) LoopOutTerms(ctx context.Context, func (s *swapClientServer) LoopOutTerms(ctx context.Context,
req *looprpc.TermsRequest) (*looprpc.OutTermsResponse, error) { req *clientrpc.TermsRequest) (*clientrpc.OutTermsResponse, error) {
log.Infof("Loop out terms request received") log.Infof("Loop out terms request received")
@ -414,7 +414,7 @@ func (s *swapClientServer) LoopOutTerms(ctx context.Context,
return nil, err return nil, err
} }
return &looprpc.OutTermsResponse{ return &clientrpc.OutTermsResponse{
MinSwapAmount: int64(terms.MinSwapAmount), MinSwapAmount: int64(terms.MinSwapAmount),
MaxSwapAmount: int64(terms.MaxSwapAmount), MaxSwapAmount: int64(terms.MaxSwapAmount),
MinCltvDelta: terms.MinCltvDelta, MinCltvDelta: terms.MinCltvDelta,
@ -425,7 +425,7 @@ func (s *swapClientServer) LoopOutTerms(ctx context.Context,
// LoopOutQuote returns a quote for a loop out swap with the provided // LoopOutQuote returns a quote for a loop out swap with the provided
// parameters. // parameters.
func (s *swapClientServer) LoopOutQuote(ctx context.Context, func (s *swapClientServer) LoopOutQuote(ctx context.Context,
req *looprpc.QuoteRequest) (*looprpc.OutQuoteResponse, error) { req *clientrpc.QuoteRequest) (*clientrpc.OutQuoteResponse, error) {
confTarget, err := validateConfTarget( confTarget, err := validateConfTarget(
req.ConfTarget, loop.DefaultSweepConfTarget, req.ConfTarget, loop.DefaultSweepConfTarget,
@ -444,7 +444,7 @@ func (s *swapClientServer) LoopOutQuote(ctx context.Context,
return nil, err return nil, err
} }
return &looprpc.OutQuoteResponse{ return &clientrpc.OutQuoteResponse{
HtlcSweepFeeSat: int64(quote.MinerFee), HtlcSweepFeeSat: int64(quote.MinerFee),
PrepayAmtSat: int64(quote.PrepayAmount), PrepayAmtSat: int64(quote.PrepayAmount),
SwapFeeSat: int64(quote.SwapFee), SwapFeeSat: int64(quote.SwapFee),
@ -455,7 +455,7 @@ func (s *swapClientServer) LoopOutQuote(ctx context.Context,
// GetTerms returns the terms that the server enforces for swaps. // GetTerms returns the terms that the server enforces for swaps.
func (s *swapClientServer) GetLoopInTerms(ctx context.Context, func (s *swapClientServer) GetLoopInTerms(ctx context.Context,
req *looprpc.TermsRequest) (*looprpc.InTermsResponse, error) { req *clientrpc.TermsRequest) (*clientrpc.InTermsResponse, error) {
log.Infof("Loop in terms request received") log.Infof("Loop in terms request received")
@ -465,7 +465,7 @@ func (s *swapClientServer) GetLoopInTerms(ctx context.Context,
return nil, err return nil, err
} }
return &looprpc.InTermsResponse{ return &clientrpc.InTermsResponse{
MinSwapAmount: int64(terms.MinSwapAmount), MinSwapAmount: int64(terms.MinSwapAmount),
MaxSwapAmount: int64(terms.MaxSwapAmount), MaxSwapAmount: int64(terms.MaxSwapAmount),
}, nil }, nil
@ -473,7 +473,7 @@ func (s *swapClientServer) GetLoopInTerms(ctx context.Context,
// GetQuote returns a quote for a swap with the provided parameters. // GetQuote returns a quote for a swap with the provided parameters.
func (s *swapClientServer) GetLoopInQuote(ctx context.Context, func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
req *looprpc.QuoteRequest) (*looprpc.InQuoteResponse, error) { req *clientrpc.QuoteRequest) (*clientrpc.InQuoteResponse, error) {
log.Infof("Loop in quote request received") log.Infof("Loop in quote request received")
@ -518,7 +518,7 @@ func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
return nil, err return nil, err
} }
return &looprpc.InQuoteResponse{ return &clientrpc.InQuoteResponse{
HtlcPublishFeeSat: int64(quote.MinerFee), HtlcPublishFeeSat: int64(quote.MinerFee),
SwapFeeSat: int64(quote.SwapFee), SwapFeeSat: int64(quote.SwapFee),
ConfTarget: htlcConfTarget, ConfTarget: htlcConfTarget,
@ -526,7 +526,7 @@ func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
} }
// unmarshallRouteHints unmarshalls a list of route hints. // unmarshallRouteHints unmarshalls a list of route hints.
func unmarshallRouteHints(rpcRouteHints []*swapserverrpc.RouteHint) ( func unmarshallRouteHints(rpcRouteHints []*looprpc.RouteHint) (
[][]zpay32.HopHint, error) { [][]zpay32.HopHint, error) {
routeHints := make([][]zpay32.HopHint, 0, len(rpcRouteHints)) routeHints := make([][]zpay32.HopHint, 0, len(rpcRouteHints))
@ -549,7 +549,7 @@ func unmarshallRouteHints(rpcRouteHints []*swapserverrpc.RouteHint) (
} }
// unmarshallHopHint unmarshalls a single hop hint. // unmarshallHopHint unmarshalls a single hop hint.
func unmarshallHopHint(rpcHint *swapserverrpc.HopHint) (zpay32.HopHint, error) { func unmarshallHopHint(rpcHint *looprpc.HopHint) (zpay32.HopHint, error) {
pubBytes, err := hex.DecodeString(rpcHint.NodeId) pubBytes, err := hex.DecodeString(rpcHint.NodeId)
if err != nil { if err != nil {
return zpay32.HopHint{}, err return zpay32.HopHint{}, err
@ -572,7 +572,7 @@ func unmarshallHopHint(rpcHint *swapserverrpc.HopHint) (zpay32.HopHint, error) {
// Probe requests the server to probe the client's node to test inbound // Probe requests the server to probe the client's node to test inbound
// liquidity. // liquidity.
func (s *swapClientServer) Probe(ctx context.Context, func (s *swapClientServer) Probe(ctx context.Context,
req *looprpc.ProbeRequest) (*looprpc.ProbeResponse, error) { req *clientrpc.ProbeRequest) (*clientrpc.ProbeResponse, error) {
log.Infof("Probe request received") log.Infof("Probe request received")
@ -600,12 +600,12 @@ func (s *swapClientServer) Probe(ctx context.Context,
return nil, err return nil, err
} }
return &looprpc.ProbeResponse{}, nil return &clientrpc.ProbeResponse{}, nil
} }
func (s *swapClientServer) LoopIn(ctx context.Context, func (s *swapClientServer) LoopIn(ctx context.Context,
in *looprpc.LoopInRequest) ( in *clientrpc.LoopInRequest) (
*looprpc.SwapResponse, error) { *clientrpc.SwapResponse, error) {
log.Infof("Loop in request received") log.Infof("Loop in request received")
@ -650,7 +650,7 @@ func (s *swapClientServer) LoopIn(ctx context.Context,
return nil, err return nil, err
} }
response := &looprpc.SwapResponse{ response := &clientrpc.SwapResponse{
Id: swapInfo.SwapHash.String(), Id: swapInfo.SwapHash.String(),
IdBytes: swapInfo.SwapHash[:], IdBytes: swapInfo.SwapHash[:],
HtlcAddressP2Wsh: swapInfo.HtlcAddressP2WSH.String(), HtlcAddressP2Wsh: swapInfo.HtlcAddressP2WSH.String(),
@ -669,7 +669,7 @@ func (s *swapClientServer) LoopIn(ctx context.Context,
// GetLsatTokens returns all tokens that are contained in the LSAT token store. // GetLsatTokens returns all tokens that are contained in the LSAT token store.
func (s *swapClientServer) GetLsatTokens(ctx context.Context, func (s *swapClientServer) GetLsatTokens(ctx context.Context,
_ *looprpc.TokensRequest) (*looprpc.TokensResponse, error) { _ *clientrpc.TokensRequest) (*clientrpc.TokensResponse, error) {
log.Infof("Get LSAT tokens request received") log.Infof("Get LSAT tokens request received")
@ -678,14 +678,14 @@ func (s *swapClientServer) GetLsatTokens(ctx context.Context,
return nil, err return nil, err
} }
rpcTokens := make([]*looprpc.LsatToken, len(tokens)) rpcTokens := make([]*clientrpc.LsatToken, len(tokens))
idx := 0 idx := 0
for key, token := range tokens { for key, token := range tokens {
macBytes, err := token.BaseMacaroon().MarshalBinary() macBytes, err := token.BaseMacaroon().MarshalBinary()
if err != nil { if err != nil {
return nil, err return nil, err
} }
rpcTokens[idx] = &looprpc.LsatToken{ rpcTokens[idx] = &clientrpc.LsatToken{
BaseMacaroon: macBytes, BaseMacaroon: macBytes,
PaymentHash: token.PaymentHash[:], PaymentHash: token.PaymentHash[:],
PaymentPreimage: token.Preimage[:], PaymentPreimage: token.Preimage[:],
@ -698,26 +698,26 @@ func (s *swapClientServer) GetLsatTokens(ctx context.Context,
idx++ idx++
} }
return &looprpc.TokensResponse{Tokens: rpcTokens}, nil return &clientrpc.TokensResponse{Tokens: rpcTokens}, nil
} }
// GetLiquidityParams gets our current liquidity manager's parameters. // GetLiquidityParams gets our current liquidity manager's parameters.
func (s *swapClientServer) GetLiquidityParams(_ context.Context, func (s *swapClientServer) GetLiquidityParams(_ context.Context,
_ *looprpc.GetLiquidityParamsRequest) (*looprpc.LiquidityParameters, _ *clientrpc.GetLiquidityParamsRequest) (*clientrpc.LiquidityParameters,
error) { error) {
cfg := s.liquidityMgr.GetParameters() cfg := s.liquidityMgr.GetParameters()
totalRules := len(cfg.ChannelRules) + len(cfg.PeerRules) totalRules := len(cfg.ChannelRules) + len(cfg.PeerRules)
rpcCfg := &looprpc.LiquidityParameters{ rpcCfg := &clientrpc.LiquidityParameters{
SweepConfTarget: cfg.SweepConfTarget, SweepConfTarget: cfg.SweepConfTarget,
FailureBackoffSec: uint64(cfg.FailureBackOff.Seconds()), FailureBackoffSec: uint64(cfg.FailureBackOff.Seconds()),
Autoloop: cfg.Autoloop, Autoloop: cfg.Autoloop,
AutoloopBudgetSat: uint64(cfg.AutoFeeBudget), AutoloopBudgetSat: uint64(cfg.AutoFeeBudget),
AutoMaxInFlight: uint64(cfg.MaxAutoInFlight), AutoMaxInFlight: uint64(cfg.MaxAutoInFlight),
Rules: make( Rules: make(
[]*looprpc.LiquidityRule, 0, totalRules, []*clientrpc.LiquidityRule, 0, totalRules,
), ),
MinSwapAmount: uint64(cfg.ClientRestrictions.Minimum), MinSwapAmount: uint64(cfg.ClientRestrictions.Minimum),
MaxSwapAmount: uint64(cfg.ClientRestrictions.Maximum), MaxSwapAmount: uint64(cfg.ClientRestrictions.Maximum),
@ -765,19 +765,19 @@ func (s *swapClientServer) GetLiquidityParams(_ context.Context,
} }
func newRPCRule(channelID uint64, peer []byte, func newRPCRule(channelID uint64, peer []byte,
rule *liquidity.SwapRule) *looprpc.LiquidityRule { rule *liquidity.SwapRule) *clientrpc.LiquidityRule {
rpcRule := &looprpc.LiquidityRule{ rpcRule := &clientrpc.LiquidityRule{
ChannelId: channelID, ChannelId: channelID,
Pubkey: peer, Pubkey: peer,
Type: looprpc.LiquidityRuleType_THRESHOLD, Type: clientrpc.LiquidityRuleType_THRESHOLD,
IncomingThreshold: uint32(rule.MinimumIncoming), IncomingThreshold: uint32(rule.MinimumIncoming),
OutgoingThreshold: uint32(rule.MinimumOutgoing), OutgoingThreshold: uint32(rule.MinimumOutgoing),
SwapType: looprpc.SwapType_LOOP_OUT, SwapType: clientrpc.SwapType_LOOP_OUT,
} }
if rule.Type == swap.TypeIn { if rule.Type == swap.TypeIn {
rpcRule.SwapType = looprpc.SwapType_LOOP_IN rpcRule.SwapType = clientrpc.SwapType_LOOP_IN
} }
return rpcRule return rpcRule
@ -786,7 +786,7 @@ func newRPCRule(channelID uint64, peer []byte,
// SetLiquidityParams attempts to set our current liquidity manager's // SetLiquidityParams attempts to set our current liquidity manager's
// parameters. // parameters.
func (s *swapClientServer) SetLiquidityParams(ctx context.Context, func (s *swapClientServer) SetLiquidityParams(ctx context.Context,
in *looprpc.SetLiquidityParamsRequest) (*looprpc.SetLiquidityParamsResponse, in *clientrpc.SetLiquidityParamsRequest) (*clientrpc.SetLiquidityParamsResponse,
error) { error) {
feeLimit, err := rpcToFee(in.Parameters) feeLimit, err := rpcToFee(in.Parameters)
@ -869,12 +869,12 @@ func (s *swapClientServer) SetLiquidityParams(ctx context.Context,
return nil, err return nil, err
} }
return &looprpc.SetLiquidityParamsResponse{}, nil return &clientrpc.SetLiquidityParamsResponse{}, nil
} }
// rpcToFee converts the values provided over rpc to a fee limit interface, // rpcToFee converts the values provided over rpc to a fee limit interface,
// failing if an inconsistent set of fields are set. // failing if an inconsistent set of fields are set.
func rpcToFee(req *looprpc.LiquidityParameters) (liquidity.FeeLimit, func rpcToFee(req *clientrpc.LiquidityParameters) (liquidity.FeeLimit,
error) { error) {
// Check which fee limit type we have values set for. If any fields // Check which fee limit type we have values set for. If any fields
@ -912,17 +912,17 @@ func rpcToFee(req *looprpc.LiquidityParameters) (liquidity.FeeLimit,
} }
// rpcToRule switches on rpc rule type to convert to our rule interface. // rpcToRule switches on rpc rule type to convert to our rule interface.
func rpcToRule(rule *looprpc.LiquidityRule) (*liquidity.SwapRule, error) { func rpcToRule(rule *clientrpc.LiquidityRule) (*liquidity.SwapRule, error) {
swapType := swap.TypeOut swapType := swap.TypeOut
if rule.SwapType == looprpc.SwapType_LOOP_IN { if rule.SwapType == clientrpc.SwapType_LOOP_IN {
swapType = swap.TypeIn swapType = swap.TypeIn
} }
switch rule.Type { switch rule.Type {
case looprpc.LiquidityRuleType_UNKNOWN: case clientrpc.LiquidityRuleType_UNKNOWN:
return nil, fmt.Errorf("rule type field must be set") return nil, fmt.Errorf("rule type field must be set")
case looprpc.LiquidityRuleType_THRESHOLD: case clientrpc.LiquidityRuleType_THRESHOLD:
return &liquidity.SwapRule{ return &liquidity.SwapRule{
ThresholdRule: liquidity.NewThresholdRule( ThresholdRule: liquidity.NewThresholdRule(
int(rule.IncomingThreshold), int(rule.IncomingThreshold),
@ -940,7 +940,7 @@ func rpcToRule(rule *looprpc.LiquidityRule) (*liquidity.SwapRule, error) {
// SuggestSwaps provides a list of suggested swaps based on lnd's current // SuggestSwaps provides a list of suggested swaps based on lnd's current
// channel balances and rules set by the liquidity manager. // channel balances and rules set by the liquidity manager.
func (s *swapClientServer) SuggestSwaps(ctx context.Context, func (s *swapClientServer) SuggestSwaps(ctx context.Context,
_ *looprpc.SuggestSwapsRequest) (*looprpc.SuggestSwapsResponse, error) { _ *clientrpc.SuggestSwapsRequest) (*clientrpc.SuggestSwapsResponse, error) {
suggestions, err := s.liquidityMgr.SuggestSwaps(ctx, false) suggestions, err := s.liquidityMgr.SuggestSwaps(ctx, false)
switch err { switch err {
@ -954,12 +954,12 @@ func (s *swapClientServer) SuggestSwaps(ctx context.Context,
} }
var ( var (
loopOut []*looprpc.LoopOutRequest loopOut []*clientrpc.LoopOutRequest
disqualified []*looprpc.Disqualified disqualified []*clientrpc.Disqualified
) )
for _, swap := range suggestions.OutSwaps { for _, swap := range suggestions.OutSwaps {
loopOut = append(loopOut, &looprpc.LoopOutRequest{ loopOut = append(loopOut, &clientrpc.LoopOutRequest{
Amt: int64(swap.Amount), Amt: int64(swap.Amount),
OutgoingChanSet: swap.OutgoingChanSet, OutgoingChanSet: swap.OutgoingChanSet,
MaxSwapFee: int64(swap.MaxSwapFee), MaxSwapFee: int64(swap.MaxSwapFee),
@ -977,7 +977,7 @@ func (s *swapClientServer) SuggestSwaps(ctx context.Context,
return nil, err return nil, err
} }
exclChan := &looprpc.Disqualified{ exclChan := &clientrpc.Disqualified{
Reason: autoloopReason, Reason: autoloopReason,
ChannelId: id.ToUint64(), ChannelId: id.ToUint64(),
} }
@ -991,7 +991,7 @@ func (s *swapClientServer) SuggestSwaps(ctx context.Context,
return nil, err return nil, err
} }
exclChan := &looprpc.Disqualified{ exclChan := &clientrpc.Disqualified{
Reason: autoloopReason, Reason: autoloopReason,
Pubkey: pubkey[:], Pubkey: pubkey[:],
} }
@ -999,55 +999,55 @@ func (s *swapClientServer) SuggestSwaps(ctx context.Context,
disqualified = append(disqualified, exclChan) disqualified = append(disqualified, exclChan)
} }
return &looprpc.SuggestSwapsResponse{ return &clientrpc.SuggestSwapsResponse{
LoopOut: loopOut, LoopOut: loopOut,
Disqualified: disqualified, Disqualified: disqualified,
}, nil }, nil
} }
func rpcAutoloopReason(reason liquidity.Reason) (looprpc.AutoReason, error) { func rpcAutoloopReason(reason liquidity.Reason) (clientrpc.AutoReason, error) {
switch reason { switch reason {
case liquidity.ReasonNone: case liquidity.ReasonNone:
return looprpc.AutoReason_AUTO_REASON_UNKNOWN, nil return clientrpc.AutoReason_AUTO_REASON_UNKNOWN, nil
case liquidity.ReasonBudgetNotStarted: case liquidity.ReasonBudgetNotStarted:
return looprpc.AutoReason_AUTO_REASON_BUDGET_NOT_STARTED, nil return clientrpc.AutoReason_AUTO_REASON_BUDGET_NOT_STARTED, nil
case liquidity.ReasonSweepFees: case liquidity.ReasonSweepFees:
return looprpc.AutoReason_AUTO_REASON_SWEEP_FEES, nil return clientrpc.AutoReason_AUTO_REASON_SWEEP_FEES, nil
case liquidity.ReasonBudgetElapsed: case liquidity.ReasonBudgetElapsed:
return looprpc.AutoReason_AUTO_REASON_BUDGET_ELAPSED, nil return clientrpc.AutoReason_AUTO_REASON_BUDGET_ELAPSED, nil
case liquidity.ReasonInFlight: case liquidity.ReasonInFlight:
return looprpc.AutoReason_AUTO_REASON_IN_FLIGHT, nil return clientrpc.AutoReason_AUTO_REASON_IN_FLIGHT, nil
case liquidity.ReasonSwapFee: case liquidity.ReasonSwapFee:
return looprpc.AutoReason_AUTO_REASON_SWAP_FEE, nil return clientrpc.AutoReason_AUTO_REASON_SWAP_FEE, nil
case liquidity.ReasonMinerFee: case liquidity.ReasonMinerFee:
return looprpc.AutoReason_AUTO_REASON_MINER_FEE, nil return clientrpc.AutoReason_AUTO_REASON_MINER_FEE, nil
case liquidity.ReasonPrepay: case liquidity.ReasonPrepay:
return looprpc.AutoReason_AUTO_REASON_PREPAY, nil return clientrpc.AutoReason_AUTO_REASON_PREPAY, nil
case liquidity.ReasonFailureBackoff: case liquidity.ReasonFailureBackoff:
return looprpc.AutoReason_AUTO_REASON_FAILURE_BACKOFF, nil return clientrpc.AutoReason_AUTO_REASON_FAILURE_BACKOFF, nil
case liquidity.ReasonLoopOut: case liquidity.ReasonLoopOut:
return looprpc.AutoReason_AUTO_REASON_LOOP_OUT, nil return clientrpc.AutoReason_AUTO_REASON_LOOP_OUT, nil
case liquidity.ReasonLoopIn: case liquidity.ReasonLoopIn:
return looprpc.AutoReason_AUTO_REASON_LOOP_IN, nil return clientrpc.AutoReason_AUTO_REASON_LOOP_IN, nil
case liquidity.ReasonLiquidityOk: case liquidity.ReasonLiquidityOk:
return looprpc.AutoReason_AUTO_REASON_LIQUIDITY_OK, nil return clientrpc.AutoReason_AUTO_REASON_LIQUIDITY_OK, nil
case liquidity.ReasonBudgetInsufficient: case liquidity.ReasonBudgetInsufficient:
return looprpc.AutoReason_AUTO_REASON_BUDGET_INSUFFICIENT, nil return clientrpc.AutoReason_AUTO_REASON_BUDGET_INSUFFICIENT, nil
case liquidity.ReasonFeePPMInsufficient: case liquidity.ReasonFeePPMInsufficient:
return looprpc.AutoReason_AUTO_REASON_SWAP_FEE, nil return clientrpc.AutoReason_AUTO_REASON_SWAP_FEE, nil
default: default:
return 0, fmt.Errorf("unknown autoloop reason: %v", reason) return 0, fmt.Errorf("unknown autoloop reason: %v", reason)
@ -1126,7 +1126,7 @@ func validateLoopInRequest(htlcConfTarget int32, external bool) (int32, error) {
// address and label of the loop out request. It also checks that the requested // address and label of the loop out request. It also checks that the requested
// loop amount is valid given the available balance. // loop amount is valid given the available balance.
func validateLoopOutRequest(ctx context.Context, lnd lndclient.LightningClient, func validateLoopOutRequest(ctx context.Context, lnd lndclient.LightningClient,
chainParams *chaincfg.Params, req *looprpc.LoopOutRequest, chainParams *chaincfg.Params, req *clientrpc.LoopOutRequest,
sweepAddr btcutil.Address, maxParts uint32) (int32, error) { sweepAddr btcutil.Address, maxParts uint32) (int32, error) {
// Check that the provided destination address has the correct format // Check that the provided destination address has the correct format

@ -3,7 +3,7 @@ package loopdb
import ( import (
"math" "math"
"github.com/lightninglabs/loop/swapserverrpc" looprpc "github.com/lightninglabs/loop/swapserverrpc"
) )
// ProtocolVersion represents the protocol version (declared on rpc level) that // ProtocolVersion represents the protocol version (declared on rpc level) that
@ -53,7 +53,7 @@ const (
// CurrentRPCProtocolVersion defines the version of the RPC protocol // CurrentRPCProtocolVersion defines the version of the RPC protocol
// that is currently supported by the loop client. // that is currently supported by the loop client.
CurrentRPCProtocolVersion = swapserverrpc.ProtocolVersion_PROBE CurrentRPCProtocolVersion = looprpc.ProtocolVersion_PROBE
// CurrentInternalProtocolVersion defines the RPC current protocol in // CurrentInternalProtocolVersion defines the RPC current protocol in
// the internal representation. // the internal representation.

@ -3,7 +3,7 @@ package loopdb
import ( import (
"testing" "testing"
"github.com/lightninglabs/loop/swapserverrpc" looprpc "github.com/lightninglabs/loop/swapserverrpc"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -25,16 +25,16 @@ func TestProtocolVersionSanity(t *testing.T) {
ProtocolVersionProbe, ProtocolVersionProbe,
} }
rpcVersions := [...]swapserverrpc.ProtocolVersion{ rpcVersions := [...]looprpc.ProtocolVersion{
swapserverrpc.ProtocolVersion_LEGACY, looprpc.ProtocolVersion_LEGACY,
swapserverrpc.ProtocolVersion_MULTI_LOOP_OUT, looprpc.ProtocolVersion_MULTI_LOOP_OUT,
swapserverrpc.ProtocolVersion_NATIVE_SEGWIT_LOOP_IN, looprpc.ProtocolVersion_NATIVE_SEGWIT_LOOP_IN,
swapserverrpc.ProtocolVersion_PREIMAGE_PUSH_LOOP_OUT, looprpc.ProtocolVersion_PREIMAGE_PUSH_LOOP_OUT,
swapserverrpc.ProtocolVersion_USER_EXPIRY_LOOP_OUT, looprpc.ProtocolVersion_USER_EXPIRY_LOOP_OUT,
swapserverrpc.ProtocolVersion_HTLC_V2, looprpc.ProtocolVersion_HTLC_V2,
swapserverrpc.ProtocolVersion_MULTI_LOOP_IN, looprpc.ProtocolVersion_MULTI_LOOP_IN,
swapserverrpc.ProtocolVersion_LOOP_OUT_CANCEL, looprpc.ProtocolVersion_LOOP_OUT_CANCEL,
swapserverrpc.ProtocolVersion_PROBE, looprpc.ProtocolVersion_PROBE,
} }
require.Equal(t, len(versions), len(rpcVersions)) require.Equal(t, len(versions), len(rpcVersions))

@ -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