mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
cmd: add new reservation clis
This commit is contained in:
parent
b48fd9aa7c
commit
56be61c31d
2 changed files with 84 additions and 1 deletions
|
|
@ -41,6 +41,8 @@ var (
|
|||
|
||||
defaultSwapWaitTime = 30 * time.Minute
|
||||
|
||||
defaultRpcTimeout = 30 * time.Second
|
||||
|
||||
// maxMsgRecvSize is the largest message our client will receive. We
|
||||
// set this to 200MiB atm.
|
||||
maxMsgRecvSize = grpc.MaxCallRecvMsgSize(1 * 1024 * 1024 * 200)
|
||||
|
|
|
|||
|
|
@ -2,13 +2,26 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/lightninglabs/loop/looprpc"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
var reservationsCommands = &cli.Command{
|
||||
var (
|
||||
reservationAmountFlag = &cli.Uint64Flag{
|
||||
Name: "amt",
|
||||
Usage: "the amount in satoshis for the reservation",
|
||||
}
|
||||
reservationExpiryFlag = &cli.UintFlag{
|
||||
Name: "expiry",
|
||||
Usage: "the relative block height at which the reservation" +
|
||||
" expires",
|
||||
}
|
||||
)
|
||||
|
||||
var reservationsCommands = &cli.Command{
|
||||
Name: "reservations",
|
||||
Aliases: []string{"r"},
|
||||
Usage: "manage reservations",
|
||||
|
|
@ -20,6 +33,7 @@ var reservationsCommands = &cli.Command{
|
|||
`,
|
||||
Commands: []*cli.Command{
|
||||
listReservationsCommand,
|
||||
newReservationCommand,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -34,8 +48,75 @@ var (
|
|||
`,
|
||||
Action: listReservations,
|
||||
}
|
||||
|
||||
newReservationCommand = &cli.Command{
|
||||
Name: "new",
|
||||
Aliases: []string{"n"},
|
||||
Usage: "create a new reservation",
|
||||
Description: `
|
||||
Create a new reservation with the given value and expiry.
|
||||
`,
|
||||
Action: newReservation,
|
||||
Flags: []cli.Flag{
|
||||
reservationAmountFlag,
|
||||
reservationExpiryFlag,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func newReservation(ctx context.Context, cmd *cli.Command) error {
|
||||
client, cleanup, err := getClient(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cleanup()
|
||||
|
||||
rpcCtx, cancel := context.WithTimeout(ctx, defaultRpcTimeout)
|
||||
defer cancel()
|
||||
|
||||
if !cmd.IsSet(reservationAmountFlag.Name) {
|
||||
return errors.New("amt flag missing")
|
||||
}
|
||||
|
||||
if !cmd.IsSet(reservationExpiryFlag.Name) {
|
||||
return errors.New("expiry flag missing")
|
||||
}
|
||||
|
||||
quoteReq, err := client.ReservationQuote(
|
||||
rpcCtx, &looprpc.ReservationQuoteRequest{
|
||||
Amt: cmd.Uint64(reservationAmountFlag.Name),
|
||||
Expiry: uint32(cmd.Uint(reservationExpiryFlag.Name)),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf(satAmtFmt, "Reservation Cost: ", quoteReq.PrepayAmt)
|
||||
|
||||
fmt.Printf("CONTINUE RESERVATION? (y/n): ")
|
||||
|
||||
var answer string
|
||||
fmt.Scanln(&answer)
|
||||
if answer == "n" {
|
||||
return nil
|
||||
}
|
||||
|
||||
reservationRes, err := client.ReservationRequest(
|
||||
rpcCtx, &looprpc.ReservationRequestRequest{
|
||||
Amt: cmd.Uint64(reservationAmountFlag.Name),
|
||||
Expiry: uint32(cmd.Uint(reservationExpiryFlag.Name)),
|
||||
MaxPrepayAmt: quoteReq.PrepayAmt,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printRespJSON(reservationRes)
|
||||
return nil
|
||||
}
|
||||
|
||||
func listReservations(ctx context.Context, cmd *cli.Command) error {
|
||||
client, cleanup, err := getClient(cmd)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue