Skip to content

Commit f62d095

Browse files
committed
loop: allow creation of loops with labels on cli
1 parent 8da0ea6 commit f62d095

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

cmd/loop/loopin.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/btcsuite/btcutil"
88
"github.com/lightninglabs/loop"
9+
"github.com/lightninglabs/loop/labels"
910
"github.com/lightninglabs/loop/looprpc"
1011
"github.com/lightningnetwork/lnd/routing/route"
1112
"github.com/urfave/cli"
@@ -24,6 +25,14 @@ var (
2425
"confirm within",
2526
}
2627

28+
labelFlag = cli.StringFlag{
29+
Name: "label",
30+
Usage: fmt.Sprintf("an optional label for this swap,"+
31+
"limited to %v characters. The label may not start "+
32+
"with our reserved prefix: %v.",
33+
labels.MaxLength, labels.Reserved),
34+
}
35+
2736
loopInCommand = cli.Command{
2837
Name: "in",
2938
Usage: "perform an on-chain to off-chain swap (loop in)",
@@ -51,6 +60,7 @@ var (
5160
},
5261
confTargetFlag,
5362
lastHopFlag,
63+
labelFlag,
5464
},
5565
Action: loopIn,
5666
}
@@ -93,6 +103,12 @@ func loopIn(ctx *cli.Context) error {
93103
return fmt.Errorf("external and conf_target both set")
94104
}
95105

106+
// Validate our label early so that we can fail before getting a quote.
107+
label := ctx.String(labelFlag.Name)
108+
if err := labels.Validate(label); err != nil {
109+
return err
110+
}
111+
96112
quote, err := client.GetLoopInQuote(
97113
context.Background(),
98114
&looprpc.QuoteRequest{
@@ -133,6 +149,7 @@ func loopIn(ctx *cli.Context) error {
133149
MaxSwapFee: int64(limits.maxSwapFee),
134150
ExternalHtlc: external,
135151
HtlcConfTarget: htlcConfTarget,
152+
Label: label,
136153
}
137154

138155
if ctx.IsSet(lastHopFlag.Name) {

cmd/loop/loopout.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/btcsuite/btcutil"
1111
"github.com/lightninglabs/loop"
12+
"github.com/lightninglabs/loop/labels"
1213
"github.com/lightninglabs/loop/looprpc"
1314
"github.com/urfave/cli"
1415
)
@@ -64,6 +65,7 @@ var loopOutCommand = cli.Command{
6465
"Not setting this flag therefore might " +
6566
"result in a lower swap fee.",
6667
},
68+
labelFlag,
6769
},
6870
Action: loopOut,
6971
}
@@ -104,6 +106,12 @@ func loopOut(ctx *cli.Context) error {
104106
}
105107
}
106108

109+
// Validate our label early so that we can fail before getting a quote.
110+
label := ctx.String(labelFlag.Name)
111+
if err := labels.Validate(label); err != nil {
112+
return err
113+
}
114+
107115
var destAddr string
108116
switch {
109117
case ctx.IsSet("addr"):
@@ -172,6 +180,7 @@ func loopOut(ctx *cli.Context) error {
172180
OutgoingChanSet: outgoingChanSet,
173181
SweepConfTarget: sweepConfTarget,
174182
SwapPublicationDeadline: uint64(swapDeadline.Unix()),
183+
Label: label,
175184
})
176185
if err != nil {
177186
return err

0 commit comments

Comments
 (0)