diff --git a/labels/labels.go b/labels/labels.go index 3129249..e17f907 100644 --- a/labels/labels.go +++ b/labels/labels.go @@ -4,6 +4,8 @@ import ( "errors" "fmt" "strings" + + "github.com/lightninglabs/loop/swap" ) const ( @@ -17,6 +19,10 @@ const ( // autoOut is the label used for loop out swaps that are automatically // dispatched. autoOut = "autoloop-out" + + // autoIn is the label used for loop in swaps that are automatically + // dispatched. + autoIn = "autoloop-in" ) var ( @@ -28,10 +34,14 @@ var ( ErrReservedPrefix = errors.New("label contains reserved prefix") ) -// AutoOutLabel returns a label with the reserved prefix that identifies -// automatically dispatched loop outs. -func AutoOutLabel() string { - return fmt.Sprintf("%v: %v", Reserved, autoOut) +// AutoloopLabel returns a label with the reserved prefix that identifies +// automatically dispatched swaps depending on the type of swap being executed. +func AutoloopLabel(swapType swap.Type) string { + 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 diff --git a/liquidity/autoloop_test.go b/liquidity/autoloop_test.go index 0cd3274..4295542 100644 --- a/liquidity/autoloop_test.go +++ b/liquidity/autoloop_test.go @@ -8,6 +8,7 @@ import ( "github.com/lightninglabs/loop" "github.com/lightninglabs/loop/labels" "github.com/lightninglabs/loop/loopdb" + "github.com/lightninglabs/loop/swap" "github.com/lightninglabs/loop/test" "github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lnwire" @@ -145,7 +146,7 @@ func TestAutoLoopEnabled(t *testing.T) { MaxMinerFee: params.MaximumMinerFee, SweepConfTarget: params.SweepConfTarget, OutgoingChanSet: loopdb.ChannelSet{chanID1.ToUint64()}, - Label: labels.AutoOutLabel(), + Label: labels.AutoloopLabel(swap.TypeOut), Initiator: autoloopSwapInitiator, } @@ -161,7 +162,7 @@ func TestAutoLoopEnabled(t *testing.T) { MaxMinerFee: params.MaximumMinerFee, SweepConfTarget: params.SweepConfTarget, OutgoingChanSet: loopdb.ChannelSet{chanID2.ToUint64()}, - Label: labels.AutoOutLabel(), + Label: labels.AutoloopLabel(swap.TypeOut), Initiator: autoloopSwapInitiator, } diff --git a/liquidity/liquidity.go b/liquidity/liquidity.go index 183dc9a..3c717fe 100644 --- a/liquidity/liquidity.go +++ b/liquidity/liquidity.go @@ -46,6 +46,7 @@ import ( "github.com/lightninglabs/loop" "github.com/lightninglabs/loop/labels" "github.com/lightninglabs/loop/loopdb" + "github.com/lightninglabs/loop/swap" "github.com/lightningnetwork/lnd/clock" "github.com/lightningnetwork/lnd/funding" "github.com/lightningnetwork/lnd/lnwallet/chainfee" @@ -816,7 +817,7 @@ func (m *Manager) makeLoopOutRequest(ctx context.Context, } if autoloop { - request.Label = labels.AutoOutLabel() + request.Label = labels.AutoloopLabel(swap.TypeOut) addr, err := m.cfg.Lnd.WalletKit.NextAddr(ctx) if err != nil { @@ -882,7 +883,7 @@ func (m *Manager) checkExistingAutoLoops(ctx context.Context, var summary existingAutoLoopSummary for _, out := range loopOuts { - if out.Contract.Label != labels.AutoOutLabel() { + if out.Contract.Label != labels.AutoloopLabel(swap.TypeOut) { continue } diff --git a/liquidity/liquidity_test.go b/liquidity/liquidity_test.go index 5f46c3f..93b1cc6 100644 --- a/liquidity/liquidity_test.go +++ b/liquidity/liquidity_test.go @@ -10,6 +10,7 @@ import ( "github.com/lightninglabs/loop" "github.com/lightninglabs/loop/labels" "github.com/lightninglabs/loop/loopdb" + "github.com/lightninglabs/loop/swap" "github.com/lightninglabs/loop/test" "github.com/lightningnetwork/lnd/clock" "github.com/lightningnetwork/lnd/lnwallet/chainfee" @@ -99,7 +100,7 @@ var ( // and restricted to a channel that we do not use in our tests. autoOutContract = &loopdb.LoopOutContract{ SwapContract: loopdb.SwapContract{ - Label: labels.AutoOutLabel(), + Label: labels.AutoloopLabel(swap.TypeOut), InitiationTime: testBudgetStart, }, OutgoingChanSet: loopdb.ChannelSet{999},