multi: update autoloop labels to support both swap types

pull/331/head
carla 3 years ago
parent 24aa429aa0
commit 69724757ce
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

@ -4,6 +4,8 @@ import (
"errors" "errors"
"fmt" "fmt"
"strings" "strings"
"github.com/lightninglabs/loop/swap"
) )
const ( const (
@ -17,6 +19,10 @@ const (
// autoOut is the label used for loop out swaps that are automatically // autoOut is the label used for loop out swaps that are automatically
// dispatched. // dispatched.
autoOut = "autoloop-out" autoOut = "autoloop-out"
// autoIn is the label used for loop in swaps that are automatically
// dispatched.
autoIn = "autoloop-in"
) )
var ( var (
@ -28,10 +34,14 @@ var (
ErrReservedPrefix = errors.New("label contains reserved prefix") ErrReservedPrefix = errors.New("label contains reserved prefix")
) )
// AutoOutLabel returns a label with the reserved prefix that identifies // AutoloopLabel returns a label with the reserved prefix that identifies
// automatically dispatched loop outs. // automatically dispatched swaps depending on the type of swap being executed.
func AutoOutLabel() string { func AutoloopLabel(swapType swap.Type) string {
return fmt.Sprintf("%v: %v", Reserved, autoOut) if swapType == swap.TypeOut {
return fmt.Sprintf("%v: %v", Reserved, autoOut)
}
return fmt.Sprintf("%v: %v", Reserved, autoIn)
} }
// Validate checks that a label is of appropriate length and is not in our list // Validate checks that a label is of appropriate length and is not in our list

@ -8,6 +8,7 @@ import (
"github.com/lightninglabs/loop" "github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/labels" "github.com/lightninglabs/loop/labels"
"github.com/lightninglabs/loop/loopdb" "github.com/lightninglabs/loop/loopdb"
"github.com/lightninglabs/loop/swap"
"github.com/lightninglabs/loop/test" "github.com/lightninglabs/loop/test"
"github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
@ -145,7 +146,7 @@ func TestAutoLoopEnabled(t *testing.T) {
MaxMinerFee: params.MaximumMinerFee, MaxMinerFee: params.MaximumMinerFee,
SweepConfTarget: params.SweepConfTarget, SweepConfTarget: params.SweepConfTarget,
OutgoingChanSet: loopdb.ChannelSet{chanID1.ToUint64()}, OutgoingChanSet: loopdb.ChannelSet{chanID1.ToUint64()},
Label: labels.AutoOutLabel(), Label: labels.AutoloopLabel(swap.TypeOut),
Initiator: autoloopSwapInitiator, Initiator: autoloopSwapInitiator,
} }
@ -161,7 +162,7 @@ func TestAutoLoopEnabled(t *testing.T) {
MaxMinerFee: params.MaximumMinerFee, MaxMinerFee: params.MaximumMinerFee,
SweepConfTarget: params.SweepConfTarget, SweepConfTarget: params.SweepConfTarget,
OutgoingChanSet: loopdb.ChannelSet{chanID2.ToUint64()}, OutgoingChanSet: loopdb.ChannelSet{chanID2.ToUint64()},
Label: labels.AutoOutLabel(), Label: labels.AutoloopLabel(swap.TypeOut),
Initiator: autoloopSwapInitiator, Initiator: autoloopSwapInitiator,
} }

@ -46,6 +46,7 @@ import (
"github.com/lightninglabs/loop" "github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/labels" "github.com/lightninglabs/loop/labels"
"github.com/lightninglabs/loop/loopdb" "github.com/lightninglabs/loop/loopdb"
"github.com/lightninglabs/loop/swap"
"github.com/lightningnetwork/lnd/clock" "github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/funding" "github.com/lightningnetwork/lnd/funding"
"github.com/lightningnetwork/lnd/lnwallet/chainfee" "github.com/lightningnetwork/lnd/lnwallet/chainfee"
@ -816,7 +817,7 @@ func (m *Manager) makeLoopOutRequest(ctx context.Context,
} }
if autoloop { if autoloop {
request.Label = labels.AutoOutLabel() request.Label = labels.AutoloopLabel(swap.TypeOut)
addr, err := m.cfg.Lnd.WalletKit.NextAddr(ctx) addr, err := m.cfg.Lnd.WalletKit.NextAddr(ctx)
if err != nil { if err != nil {
@ -882,7 +883,7 @@ func (m *Manager) checkExistingAutoLoops(ctx context.Context,
var summary existingAutoLoopSummary var summary existingAutoLoopSummary
for _, out := range loopOuts { for _, out := range loopOuts {
if out.Contract.Label != labels.AutoOutLabel() { if out.Contract.Label != labels.AutoloopLabel(swap.TypeOut) {
continue continue
} }

@ -10,6 +10,7 @@ import (
"github.com/lightninglabs/loop" "github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/labels" "github.com/lightninglabs/loop/labels"
"github.com/lightninglabs/loop/loopdb" "github.com/lightninglabs/loop/loopdb"
"github.com/lightninglabs/loop/swap"
"github.com/lightninglabs/loop/test" "github.com/lightninglabs/loop/test"
"github.com/lightningnetwork/lnd/clock" "github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/lnwallet/chainfee" "github.com/lightningnetwork/lnd/lnwallet/chainfee"
@ -99,7 +100,7 @@ var (
// and restricted to a channel that we do not use in our tests. // and restricted to a channel that we do not use in our tests.
autoOutContract = &loopdb.LoopOutContract{ autoOutContract = &loopdb.LoopOutContract{
SwapContract: loopdb.SwapContract{ SwapContract: loopdb.SwapContract{
Label: labels.AutoOutLabel(), Label: labels.AutoloopLabel(swap.TypeOut),
InitiationTime: testBudgetStart, InitiationTime: testBudgetStart,
}, },
OutgoingChanSet: loopdb.ChannelSet{999}, OutgoingChanSet: loopdb.ChannelSet{999},

Loading…
Cancel
Save