loopd: alias client rpc import with clientrpc

Packages importing loopd can't import 2x looprpc packages (in the
form of swapserverrpc and looprpc). To get around this, we alias
each import with a different name, starting with the client in this
commit.
pull/446/head
carla 2 years ago
parent 3b911cfd4f
commit 996b5e43ab
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

@ -17,7 +17,7 @@ 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" "github.com/lightninglabs/loop/swapserverrpc"
"github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lntypes"
@ -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,
@ -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

Loading…
Cancel
Save