|
| 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 | + case ctx.NArg() > 0: |
| 43 | + amtStr = args[0] |
| 44 | + args = args.Tail() |
| 45 | + default: |
| 46 | + // Show command help if no arguments and flags were provided. |
| 47 | + return cli.ShowCommandHelp(ctx, "hyperloop") |
| 48 | + } |
| 49 | + |
| 50 | + amt, err := parseAmt(amtStr) |
| 51 | + if err != nil { |
| 52 | + return err |
| 53 | + } |
| 54 | + |
| 55 | + // First set up the swap client itself. |
| 56 | + client, cleanup, err := getClient(ctx) |
| 57 | + if err != nil { |
| 58 | + return err |
| 59 | + } |
| 60 | + defer cleanup() |
| 61 | + ctxb := context.Background() |
| 62 | + |
| 63 | + hyperloopRes, err := client.HyperLoopOut( |
| 64 | + ctxb, |
| 65 | + &looprpc.HyperLoopOutRequest{ |
| 66 | + Amt: uint64(amt), |
| 67 | + CustomSweepAddr: ctx.String("addr"), |
| 68 | + }, |
| 69 | + ) |
| 70 | + if err != nil { |
| 71 | + return err |
| 72 | + } |
| 73 | + |
| 74 | + printJSON(hyperloopRes) |
| 75 | + |
| 76 | + return nil |
| 77 | +} |
0 commit comments