From 30acccbb6f71948a7f383ddc3eace80f9d230070 Mon Sep 17 00:00:00 2001 From: sputn1ck Date: Fri, 25 Aug 2023 01:42:43 +0200 Subject: [PATCH] loop: add reservation cli commands --- cmd/loop/main.go | 2 +- cmd/loop/reservations.go | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 cmd/loop/reservations.go diff --git a/cmd/loop/main.go b/cmd/loop/main.go index 42ffba3..3ac4cea 100644 --- a/cmd/loop/main.go +++ b/cmd/loop/main.go @@ -147,7 +147,7 @@ func main() { monitorCommand, quoteCommand, listAuthCommand, listSwapsCommand, swapInfoCommand, getLiquidityParamsCommand, setLiquidityRuleCommand, suggestSwapCommand, setParamsCommand, - getInfoCommand, abandonSwapCommand, + getInfoCommand, abandonSwapCommand, reservationsCommands, } err := app.Run(os.Args) diff --git a/cmd/loop/reservations.go b/cmd/loop/reservations.go new file mode 100644 index 0000000..9f5c123 --- /dev/null +++ b/cmd/loop/reservations.go @@ -0,0 +1,55 @@ +package main + +import ( + "context" + + "github.com/lightninglabs/loop/looprpc" + "github.com/urfave/cli" +) + +var reservationsCommands = cli.Command{ + + Name: "reservations", + ShortName: "r", + Usage: "manage reservations", + Description: ` + With loopd running, you can use this command to manage your + reservations. Reservations are 2-of-2 multisig utxos that + the loop server can open to clients. The reservations are used + to enable instant swaps. + `, + Subcommands: []cli.Command{ + listReservationsCommand, + }, +} + +var ( + listReservationsCommand = cli.Command{ + Name: "list", + ShortName: "l", + Usage: "list all reservations", + ArgsUsage: "", + Description: ` + List all reservations. + `, + Action: listReservations, + } +) + +func listReservations(ctx *cli.Context) error { + client, cleanup, err := getClient(ctx) + if err != nil { + return err + } + defer cleanup() + + resp, err := client.ListReservations( + context.Background(), &looprpc.ListReservationsRequest{}, + ) + if err != nil { + return err + } + + printRespJSON(resp) + return nil +}