Skip to content

Commit

Permalink
loopcli: add hyperloop cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
sputn1ck committed Aug 19, 2024
1 parent f6bbbd8 commit 45cc003
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
77 changes: 77 additions & 0 deletions cmd/loop/hyperloop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package main

import (
"context"

"github.com/lightninglabs/loop/looprpc"
"github.com/urfave/cli"
)

var hyperloopCommand = cli.Command{
Name: "hyperloop",
Usage: "perform a fee optimized off-chain to on-chain swap (hyperloop)",
Description: `
`,
ArgsUsage: "amt",
Flags: []cli.Flag{
cli.Uint64Flag{
Name: "amt",
Usage: "the amount in satoshis to loop out. To check " +
"for the minimum and maximum amounts to loop " +
"out please consult \"loop terms\"",
},
cli.StringFlag{
Name: "addr",
Usage: "the optional address that the looped out funds " +
"should be sent to, if let blank the funds " +
"will go to lnd's wallet",
},
},

Action: hyperloop,
}

func hyperloop(ctx *cli.Context) error {
args := ctx.Args()

var amtStr string
switch {
case ctx.IsSet("amt"):
amtStr = ctx.String("amt")
case ctx.NArg() > 0:
amtStr = args[0]
args = args.Tail()
default:
// Show command help if no arguments and flags were provided.
return cli.ShowCommandHelp(ctx, "hyperloop")
}

amt, err := parseAmt(amtStr)
if err != nil {
return err
}

// First set up the swap client itself.
client, cleanup, err := getClient(ctx)
if err != nil {
return err
}
defer cleanup()
ctxb := context.Background()

hyperloopRes, err := client.HyperLoopOut(
ctxb,
&looprpc.HyperLoopOutRequest{
Amt: uint64(amt),
CustomSweepAddr: ctx.String("addr"),
},
)
if err != nil {
return err
}

printJSON(hyperloopRes)

return nil
}
2 changes: 1 addition & 1 deletion cmd/loop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func main() {
listSwapsCommand, swapInfoCommand, getLiquidityParamsCommand,
setLiquidityRuleCommand, suggestSwapCommand, setParamsCommand,
getInfoCommand, abandonSwapCommand, reservationsCommands,
instantOutCommand, listInstantOutsCommand,
instantOutCommand, listInstantOutsCommand, hyperloopCommand,
}

err := app.Run(os.Args)
Expand Down

0 comments on commit 45cc003

Please sign in to comment.