loop: allow creation of loops with labels on cli

pull/263/head
carla 4 years ago
parent 8da0ea6048
commit f62d09528d
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

@ -6,6 +6,7 @@ import (
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/lightninglabs/loop" "github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/labels"
"github.com/lightninglabs/loop/looprpc" "github.com/lightninglabs/loop/looprpc"
"github.com/lightningnetwork/lnd/routing/route" "github.com/lightningnetwork/lnd/routing/route"
"github.com/urfave/cli" "github.com/urfave/cli"
@ -24,6 +25,14 @@ var (
"confirm within", "confirm within",
} }
labelFlag = cli.StringFlag{
Name: "label",
Usage: fmt.Sprintf("an optional label for this swap,"+
"limited to %v characters. The label may not start "+
"with our reserved prefix: %v.",
labels.MaxLength, labels.Reserved),
}
loopInCommand = cli.Command{ loopInCommand = cli.Command{
Name: "in", Name: "in",
Usage: "perform an on-chain to off-chain swap (loop in)", Usage: "perform an on-chain to off-chain swap (loop in)",
@ -51,6 +60,7 @@ var (
}, },
confTargetFlag, confTargetFlag,
lastHopFlag, lastHopFlag,
labelFlag,
}, },
Action: loopIn, Action: loopIn,
} }
@ -93,6 +103,12 @@ func loopIn(ctx *cli.Context) error {
return fmt.Errorf("external and conf_target both set") return fmt.Errorf("external and conf_target both set")
} }
// Validate our label early so that we can fail before getting a quote.
label := ctx.String(labelFlag.Name)
if err := labels.Validate(label); err != nil {
return err
}
quote, err := client.GetLoopInQuote( quote, err := client.GetLoopInQuote(
context.Background(), context.Background(),
&looprpc.QuoteRequest{ &looprpc.QuoteRequest{
@ -133,6 +149,7 @@ func loopIn(ctx *cli.Context) error {
MaxSwapFee: int64(limits.maxSwapFee), MaxSwapFee: int64(limits.maxSwapFee),
ExternalHtlc: external, ExternalHtlc: external,
HtlcConfTarget: htlcConfTarget, HtlcConfTarget: htlcConfTarget,
Label: label,
} }
if ctx.IsSet(lastHopFlag.Name) { if ctx.IsSet(lastHopFlag.Name) {

@ -9,6 +9,7 @@ import (
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/lightninglabs/loop" "github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/labels"
"github.com/lightninglabs/loop/looprpc" "github.com/lightninglabs/loop/looprpc"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -64,6 +65,7 @@ var loopOutCommand = cli.Command{
"Not setting this flag therefore might " + "Not setting this flag therefore might " +
"result in a lower swap fee.", "result in a lower swap fee.",
}, },
labelFlag,
}, },
Action: loopOut, Action: loopOut,
} }
@ -104,6 +106,12 @@ func loopOut(ctx *cli.Context) error {
} }
} }
// Validate our label early so that we can fail before getting a quote.
label := ctx.String(labelFlag.Name)
if err := labels.Validate(label); err != nil {
return err
}
var destAddr string var destAddr string
switch { switch {
case ctx.IsSet("addr"): case ctx.IsSet("addr"):
@ -172,6 +180,7 @@ func loopOut(ctx *cli.Context) error {
OutgoingChanSet: outgoingChanSet, OutgoingChanSet: outgoingChanSet,
SweepConfTarget: sweepConfTarget, SweepConfTarget: sweepConfTarget,
SwapPublicationDeadline: uint64(swapDeadline.Unix()), SwapPublicationDeadline: uint64(swapDeadline.Unix()),
Label: label,
}) })
if err != nil { if err != nil {
return err return err

Loading…
Cancel
Save