@@ -2,13 +2,26 @@ package main
2
2
3
3
import (
4
4
"context"
5
+ "errors"
6
+ "fmt"
5
7
6
8
"github.com/lightninglabs/loop/looprpc"
7
9
"github.com/urfave/cli"
8
10
)
9
11
10
- var reservationsCommands = cli.Command {
12
+ var (
13
+ reservationAmountFlag = cli.Uint64Flag {
14
+ Name : "amt" ,
15
+ Usage : "the amount in satoshis for the reservation" ,
16
+ }
17
+ reservationExpiryFlag = cli.UintFlag {
18
+ Name : "expiry" ,
19
+ Usage : "the relative block height at which the reservation" +
20
+ " expires" ,
21
+ }
22
+ )
11
23
24
+ var reservationsCommands = cli.Command {
12
25
Name : "reservations" ,
13
26
ShortName : "r" ,
14
27
Usage : "manage reservations" ,
@@ -20,6 +33,7 @@ var reservationsCommands = cli.Command{
20
33
` ,
21
34
Subcommands : []cli.Command {
22
35
listReservationsCommand ,
36
+ newReservationCommand ,
23
37
},
24
38
}
25
39
34
48
` ,
35
49
Action : listReservations ,
36
50
}
51
+
52
+ newReservationCommand = cli.Command {
53
+ Name : "new" ,
54
+ ShortName : "n" ,
55
+ Usage : "create a new reservation" ,
56
+ Description : `
57
+ Create a new reservation with the given value and expiry.
58
+ ` ,
59
+ Action : newReservation ,
60
+ Flags : []cli.Flag {
61
+ reservationAmountFlag ,
62
+ reservationExpiryFlag ,
63
+ },
64
+ }
37
65
)
38
66
67
+ func newReservation (ctx * cli.Context ) error {
68
+ client , cleanup , err := getClient (ctx )
69
+ if err != nil {
70
+ return err
71
+ }
72
+ defer cleanup ()
73
+
74
+ ctxt , cancel := context .WithTimeout (
75
+ context .Background (), defaultRpcTimeout ,
76
+ )
77
+ defer cancel ()
78
+
79
+ if ! ctx .IsSet (reservationAmountFlag .Name ) {
80
+ return errors .New ("amt flag missing" )
81
+ }
82
+
83
+ if ! ctx .IsSet (reservationExpiryFlag .Name ) {
84
+ return errors .New ("expiry flag missing" )
85
+ }
86
+
87
+ quoteReq , err := client .ReservationQuote (
88
+ ctxt , & looprpc.ReservationQuoteRequest {
89
+ Amt : ctx .Uint64 (reservationAmountFlag .Name ),
90
+ Expiry : uint32 (ctx .Uint (reservationExpiryFlag .Name )),
91
+ },
92
+ )
93
+ if err != nil {
94
+ return err
95
+ }
96
+
97
+ fmt .Printf (satAmtFmt , "Reservation Cost: " , quoteReq .PrepayAmt )
98
+
99
+ fmt .Printf ("CONTINUE RESERVATION? (y/n): " )
100
+
101
+ var answer string
102
+ fmt .Scanln (& answer )
103
+ if answer == "n" {
104
+ return nil
105
+ }
106
+
107
+ reservationRes , err := client .ReservationRequest (
108
+ ctxt , & looprpc.ReservationRequestRequest {
109
+ Amt : ctx .Uint64 (reservationAmountFlag .Name ),
110
+ Expiry : uint32 (ctx .Uint (reservationExpiryFlag .Name )),
111
+ MaxPrepayAmt : quoteReq .PrepayAmt ,
112
+ },
113
+ )
114
+ if err != nil {
115
+ return err
116
+ }
117
+
118
+ printRespJSON (reservationRes )
119
+ return nil
120
+ }
121
+
39
122
func listReservations (ctx * cli.Context ) error {
40
123
client , cleanup , err := getClient (ctx )
41
124
if err != nil {
0 commit comments