Skip to content

Commit 6972475

Browse files
committed
multi: update autoloop labels to support both swap types
1 parent 24aa429 commit 6972475

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

labels/labels.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"errors"
55
"fmt"
66
"strings"
7+
8+
"github.com/lightninglabs/loop/swap"
79
)
810

911
const (
@@ -17,6 +19,10 @@ const (
1719
// autoOut is the label used for loop out swaps that are automatically
1820
// dispatched.
1921
autoOut = "autoloop-out"
22+
23+
// autoIn is the label used for loop in swaps that are automatically
24+
// dispatched.
25+
autoIn = "autoloop-in"
2026
)
2127

2228
var (
@@ -28,10 +34,14 @@ var (
2834
ErrReservedPrefix = errors.New("label contains reserved prefix")
2935
)
3036

31-
// AutoOutLabel returns a label with the reserved prefix that identifies
32-
// automatically dispatched loop outs.
33-
func AutoOutLabel() string {
34-
return fmt.Sprintf("%v: %v", Reserved, autoOut)
37+
// AutoloopLabel returns a label with the reserved prefix that identifies
38+
// automatically dispatched swaps depending on the type of swap being executed.
39+
func AutoloopLabel(swapType swap.Type) string {
40+
if swapType == swap.TypeOut {
41+
return fmt.Sprintf("%v: %v", Reserved, autoOut)
42+
}
43+
44+
return fmt.Sprintf("%v: %v", Reserved, autoIn)
3545
}
3646

3747
// Validate checks that a label is of appropriate length and is not in our list

liquidity/autoloop_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/lightninglabs/loop"
99
"github.com/lightninglabs/loop/labels"
1010
"github.com/lightninglabs/loop/loopdb"
11+
"github.com/lightninglabs/loop/swap"
1112
"github.com/lightninglabs/loop/test"
1213
"github.com/lightningnetwork/lnd/lntypes"
1314
"github.com/lightningnetwork/lnd/lnwire"
@@ -145,7 +146,7 @@ func TestAutoLoopEnabled(t *testing.T) {
145146
MaxMinerFee: params.MaximumMinerFee,
146147
SweepConfTarget: params.SweepConfTarget,
147148
OutgoingChanSet: loopdb.ChannelSet{chanID1.ToUint64()},
148-
Label: labels.AutoOutLabel(),
149+
Label: labels.AutoloopLabel(swap.TypeOut),
149150
Initiator: autoloopSwapInitiator,
150151
}
151152

@@ -161,7 +162,7 @@ func TestAutoLoopEnabled(t *testing.T) {
161162
MaxMinerFee: params.MaximumMinerFee,
162163
SweepConfTarget: params.SweepConfTarget,
163164
OutgoingChanSet: loopdb.ChannelSet{chanID2.ToUint64()},
164-
Label: labels.AutoOutLabel(),
165+
Label: labels.AutoloopLabel(swap.TypeOut),
165166
Initiator: autoloopSwapInitiator,
166167
}
167168

liquidity/liquidity.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import (
4646
"github.com/lightninglabs/loop"
4747
"github.com/lightninglabs/loop/labels"
4848
"github.com/lightninglabs/loop/loopdb"
49+
"github.com/lightninglabs/loop/swap"
4950
"github.com/lightningnetwork/lnd/clock"
5051
"github.com/lightningnetwork/lnd/funding"
5152
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
@@ -816,7 +817,7 @@ func (m *Manager) makeLoopOutRequest(ctx context.Context,
816817
}
817818

818819
if autoloop {
819-
request.Label = labels.AutoOutLabel()
820+
request.Label = labels.AutoloopLabel(swap.TypeOut)
820821

821822
addr, err := m.cfg.Lnd.WalletKit.NextAddr(ctx)
822823
if err != nil {
@@ -882,7 +883,7 @@ func (m *Manager) checkExistingAutoLoops(ctx context.Context,
882883
var summary existingAutoLoopSummary
883884

884885
for _, out := range loopOuts {
885-
if out.Contract.Label != labels.AutoOutLabel() {
886+
if out.Contract.Label != labels.AutoloopLabel(swap.TypeOut) {
886887
continue
887888
}
888889

liquidity/liquidity_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/lightninglabs/loop"
1111
"github.com/lightninglabs/loop/labels"
1212
"github.com/lightninglabs/loop/loopdb"
13+
"github.com/lightninglabs/loop/swap"
1314
"github.com/lightninglabs/loop/test"
1415
"github.com/lightningnetwork/lnd/clock"
1516
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
@@ -99,7 +100,7 @@ var (
99100
// and restricted to a channel that we do not use in our tests.
100101
autoOutContract = &loopdb.LoopOutContract{
101102
SwapContract: loopdb.SwapContract{
102-
Label: labels.AutoOutLabel(),
103+
Label: labels.AutoloopLabel(swap.TypeOut),
103104
InitiationTime: testBudgetStart,
104105
},
105106
OutgoingChanSet: loopdb.ChannelSet{999},

0 commit comments

Comments
 (0)