Skip to content

Commit e2db611

Browse files
committed
loopcli: add hyperloop cmd
1 parent 1e9eec1 commit e2db611

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

cmd/loop/hyperloop.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package main
2+
3+
import (
4+
"context"
5+
6+
"github.com/lightninglabs/loop/looprpc"
7+
"github.com/urfave/cli"
8+
)
9+
10+
var hyperloopCommand = cli.Command{
11+
Name: "hyperloop",
12+
Usage: "perform a fee optimized off-chain to on-chain swap (hyperloop)",
13+
Description: `
14+
15+
`,
16+
ArgsUsage: "amt",
17+
Flags: []cli.Flag{
18+
cli.Uint64Flag{
19+
Name: "amt",
20+
Usage: "the amount in satoshis to loop out. To check " +
21+
"for the minimum and maximum amounts to loop " +
22+
"out please consult \"loop terms\"",
23+
},
24+
cli.StringFlag{
25+
Name: "addr",
26+
Usage: "the optional address that the looped out funds " +
27+
"should be sent to, if let blank the funds " +
28+
"will go to lnd's wallet",
29+
},
30+
},
31+
32+
Action: hyperloop,
33+
}
34+
35+
func hyperloop(ctx *cli.Context) error {
36+
args := ctx.Args()
37+
38+
var amtStr string
39+
switch {
40+
case ctx.IsSet("amt"):
41+
amtStr = ctx.String("amt")
42+
43+
case ctx.NArg() > 0:
44+
amtStr = args[0]
45+
46+
default:
47+
// Show command help if no arguments and flags were provided.
48+
return cli.ShowCommandHelp(ctx, "hyperloop")
49+
}
50+
51+
amt, err := parseAmt(amtStr)
52+
if err != nil {
53+
return err
54+
}
55+
56+
// First set up the swap client itself.
57+
client, cleanup, err := getClient(ctx)
58+
if err != nil {
59+
return err
60+
}
61+
defer cleanup()
62+
ctxb := context.Background()
63+
64+
hyperloopRes, err := client.HyperLoopOut(
65+
ctxb,
66+
&looprpc.HyperLoopOutRequest{
67+
Amt: uint64(amt),
68+
CustomSweepAddr: ctx.String("addr"),
69+
},
70+
)
71+
if err != nil {
72+
return err
73+
}
74+
75+
printJSON(hyperloopRes)
76+
77+
return nil
78+
}

cmd/loop/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func main() {
148148
listSwapsCommand, swapInfoCommand, getLiquidityParamsCommand,
149149
setLiquidityRuleCommand, suggestSwapCommand, setParamsCommand,
150150
getInfoCommand, abandonSwapCommand, reservationsCommands,
151-
instantOutCommand, listInstantOutsCommand,
151+
instantOutCommand, listInstantOutsCommand, hyperloopCommand,
152152
}
153153

154154
err := app.Run(os.Args)

0 commit comments

Comments
 (0)