mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
multi: update autoloop labels to support both swap types
This commit is contained in:
parent
24aa429aa0
commit
69724757ce
4 changed files with 22 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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…
Add table
Add a link
Reference in a new issue