1
1
package main
2
2
3
3
import (
4
- "context"
5
4
"encoding/hex"
6
5
"fmt"
7
6
"os"
@@ -75,9 +74,9 @@ spend that amount.`,
75
74
Action : createAccount ,
76
75
}
77
76
78
- func createAccount (ctx * cli.Context ) error {
79
- ctxb := context . Background ()
80
- clientConn , cleanup , err := connectClient (ctx , false )
77
+ func createAccount (cli * cli.Context ) error {
78
+ ctx := getContext ()
79
+ clientConn , cleanup , err := connectClient (cli , false )
81
80
if err != nil {
82
81
return err
83
82
}
@@ -88,11 +87,11 @@ func createAccount(ctx *cli.Context) error {
88
87
initialBalance uint64
89
88
expirationDate int64
90
89
)
91
- args := ctx .Args ()
90
+ args := cli .Args ()
92
91
93
92
switch {
94
- case ctx .IsSet ("balance" ):
95
- initialBalance = ctx .Uint64 ("balance" )
93
+ case cli .IsSet ("balance" ):
94
+ initialBalance = cli .Uint64 ("balance" )
96
95
case args .Present ():
97
96
initialBalance , err = strconv .ParseUint (args .First (), 10 , 64 )
98
97
if err != nil {
@@ -102,8 +101,8 @@ func createAccount(ctx *cli.Context) error {
102
101
}
103
102
104
103
switch {
105
- case ctx .IsSet ("expiration_date" ):
106
- expirationDate = ctx .Int64 ("expiration_date" )
104
+ case cli .IsSet ("expiration_date" ):
105
+ expirationDate = cli .Int64 ("expiration_date" )
107
106
case args .Present ():
108
107
expirationDate , err = strconv .ParseInt (args .First (), 10 , 64 )
109
108
if err != nil {
@@ -117,9 +116,9 @@ func createAccount(ctx *cli.Context) error {
117
116
req := & litrpc.CreateAccountRequest {
118
117
AccountBalance : initialBalance ,
119
118
ExpirationDate : expirationDate ,
120
- Label : ctx .String (labelName ),
119
+ Label : cli .String (labelName ),
121
120
}
122
- resp , err := client .CreateAccount (ctxb , req )
121
+ resp , err := client .CreateAccount (ctx , req )
123
122
if err != nil {
124
123
return err
125
124
}
@@ -128,8 +127,8 @@ func createAccount(ctx *cli.Context) error {
128
127
129
128
// User requested to store the newly baked account macaroon to a file
130
129
// in addition to printing it to the console.
131
- if ctx .IsSet ("save_to" ) {
132
- fileName := lncfg .CleanAndExpandPath (ctx .String ("save_to" ))
130
+ if cli .IsSet ("save_to" ) {
131
+ fileName := lncfg .CleanAndExpandPath (cli .String ("save_to" ))
133
132
err := os .WriteFile (fileName , resp .Macaroon , 0644 )
134
133
if err != nil {
135
134
return fmt .Errorf ("error writing account macaroon " +
@@ -176,16 +175,16 @@ var updateAccountCommand = cli.Command{
176
175
Action : updateAccount ,
177
176
}
178
177
179
- func updateAccount (ctx * cli.Context ) error {
180
- ctxb := context . Background ()
181
- clientConn , cleanup , err := connectClient (ctx , false )
178
+ func updateAccount (cli * cli.Context ) error {
179
+ ctx := getContext ()
180
+ clientConn , cleanup , err := connectClient (cli , false )
182
181
if err != nil {
183
182
return err
184
183
}
185
184
defer cleanup ()
186
185
client := litrpc .NewAccountsClient (clientConn )
187
186
188
- id , label , args , err := parseIDOrLabel (ctx )
187
+ id , label , args , err := parseIDOrLabel (cli )
189
188
if err != nil {
190
189
return err
191
190
}
@@ -195,8 +194,8 @@ func updateAccount(ctx *cli.Context) error {
195
194
expirationDate int64
196
195
)
197
196
switch {
198
- case ctx .IsSet ("new_balance" ):
199
- newBalance = ctx .Int64 ("new_balance" )
197
+ case cli .IsSet ("new_balance" ):
198
+ newBalance = cli .Int64 ("new_balance" )
200
199
case args .Present ():
201
200
newBalance , err = strconv .ParseInt (args .First (), 10 , 64 )
202
201
if err != nil {
@@ -206,8 +205,8 @@ func updateAccount(ctx *cli.Context) error {
206
205
}
207
206
208
207
switch {
209
- case ctx .IsSet ("new_expiration_date" ):
210
- expirationDate = ctx .Int64 ("new_expiration_date" )
208
+ case cli .IsSet ("new_expiration_date" ):
209
+ expirationDate = cli .Int64 ("new_expiration_date" )
211
210
case args .Present ():
212
211
expirationDate , err = strconv .ParseInt (args .First (), 10 , 64 )
213
212
if err != nil {
@@ -224,7 +223,7 @@ func updateAccount(ctx *cli.Context) error {
224
223
AccountBalance : newBalance ,
225
224
ExpirationDate : expirationDate ,
226
225
}
227
- resp , err := client .UpdateAccount (ctxb , req )
226
+ resp , err := client .UpdateAccount (ctx , req )
228
227
if err != nil {
229
228
return err
230
229
}
@@ -242,17 +241,17 @@ var listAccountsCommand = cli.Command{
242
241
Action : listAccounts ,
243
242
}
244
243
245
- func listAccounts (ctx * cli.Context ) error {
246
- ctxb := context . Background ()
247
- clientConn , cleanup , err := connectClient (ctx , false )
244
+ func listAccounts (cli * cli.Context ) error {
245
+ ctx := getContext ()
246
+ clientConn , cleanup , err := connectClient (cli , false )
248
247
if err != nil {
249
248
return err
250
249
}
251
250
defer cleanup ()
252
251
client := litrpc .NewAccountsClient (clientConn )
253
252
254
253
req := & litrpc.ListAccountsRequest {}
255
- resp , err := client .ListAccounts (ctxb , req )
254
+ resp , err := client .ListAccounts (ctx , req )
256
255
if err != nil {
257
256
return err
258
257
}
@@ -281,16 +280,16 @@ var accountInfoCommand = cli.Command{
281
280
Action : accountInfo ,
282
281
}
283
282
284
- func accountInfo (ctx * cli.Context ) error {
285
- ctxb := context . Background ()
286
- clientConn , cleanup , err := connectClient (ctx , false )
283
+ func accountInfo (cli * cli.Context ) error {
284
+ ctx := getContext ()
285
+ clientConn , cleanup , err := connectClient (cli , false )
287
286
if err != nil {
288
287
return err
289
288
}
290
289
defer cleanup ()
291
290
client := litrpc .NewAccountsClient (clientConn )
292
291
293
- id , label , _ , err := parseIDOrLabel (ctx )
292
+ id , label , _ , err := parseIDOrLabel (cli )
294
293
if err != nil {
295
294
return err
296
295
}
@@ -299,7 +298,7 @@ func accountInfo(ctx *cli.Context) error {
299
298
Id : id ,
300
299
Label : label ,
301
300
}
302
- resp , err := client .AccountInfo (ctxb , req )
301
+ resp , err := client .AccountInfo (ctx , req )
303
302
if err != nil {
304
303
return err
305
304
}
@@ -327,16 +326,16 @@ var removeAccountCommand = cli.Command{
327
326
Action : removeAccount ,
328
327
}
329
328
330
- func removeAccount (ctx * cli.Context ) error {
331
- ctxb := context . Background ()
332
- clientConn , cleanup , err := connectClient (ctx , false )
329
+ func removeAccount (cli * cli.Context ) error {
330
+ ctx := getContext ()
331
+ clientConn , cleanup , err := connectClient (cli , false )
333
332
if err != nil {
334
333
return err
335
334
}
336
335
defer cleanup ()
337
336
client := litrpc .NewAccountsClient (clientConn )
338
337
339
- id , label , _ , err := parseIDOrLabel (ctx )
338
+ id , label , _ , err := parseIDOrLabel (cli )
340
339
if err != nil {
341
340
return err
342
341
}
@@ -345,7 +344,7 @@ func removeAccount(ctx *cli.Context) error {
345
344
Id : id ,
346
345
Label : label ,
347
346
}
348
- _ , err = client .RemoveAccount (ctxb , req )
347
+ _ , err = client .RemoveAccount (ctx , req )
349
348
return err
350
349
}
351
350
0 commit comments