Browse Source

multi: update autoloop labels to support both swap types

pull/331/head
carla 8 months ago
parent
commit
69724757ce
No known key found for this signature in database GPG Key ID: 4CA7FE54A6213C91
4 changed files with 22 additions and 9 deletions
  1. +14
    -4
      labels/labels.go
  2. +3
    -2
      liquidity/autoloop_test.go
  3. +3
    -2
      liquidity/liquidity.go
  4. +2
    -1
      liquidity/liquidity_test.go

+ 14
- 4
labels/labels.go View File

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

+ 3
- 2
liquidity/autoloop_test.go View File

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

+ 3
- 2
liquidity/liquidity.go View File

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

+ 2
- 1
liquidity/liquidity_test.go View File

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

Loading…
Cancel
Save