11package main
22
33import (
4- "context"
54 "encoding/hex"
65 "fmt"
76 "os"
@@ -75,9 +74,9 @@ spend that amount.`,
7574 Action : createAccount ,
7675}
7776
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 )
8180 if err != nil {
8281 return err
8382 }
@@ -88,11 +87,11 @@ func createAccount(ctx *cli.Context) error {
8887 initialBalance uint64
8988 expirationDate int64
9089 )
91- args := ctx .Args ()
90+ args := cli .Args ()
9291
9392 switch {
94- case ctx .IsSet ("balance" ):
95- initialBalance = ctx .Uint64 ("balance" )
93+ case cli .IsSet ("balance" ):
94+ initialBalance = cli .Uint64 ("balance" )
9695 case args .Present ():
9796 initialBalance , err = strconv .ParseUint (args .First (), 10 , 64 )
9897 if err != nil {
@@ -102,8 +101,8 @@ func createAccount(ctx *cli.Context) error {
102101 }
103102
104103 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" )
107106 case args .Present ():
108107 expirationDate , err = strconv .ParseInt (args .First (), 10 , 64 )
109108 if err != nil {
@@ -117,9 +116,9 @@ func createAccount(ctx *cli.Context) error {
117116 req := & litrpc.CreateAccountRequest {
118117 AccountBalance : initialBalance ,
119118 ExpirationDate : expirationDate ,
120- Label : ctx .String (labelName ),
119+ Label : cli .String (labelName ),
121120 }
122- resp , err := client .CreateAccount (ctxb , req )
121+ resp , err := client .CreateAccount (ctx , req )
123122 if err != nil {
124123 return err
125124 }
@@ -128,8 +127,8 @@ func createAccount(ctx *cli.Context) error {
128127
129128 // User requested to store the newly baked account macaroon to a file
130129 // 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" ))
133132 err := os .WriteFile (fileName , resp .Macaroon , 0644 )
134133 if err != nil {
135134 return fmt .Errorf ("error writing account macaroon " +
@@ -176,16 +175,16 @@ var updateAccountCommand = cli.Command{
176175 Action : updateAccount ,
177176}
178177
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 )
182181 if err != nil {
183182 return err
184183 }
185184 defer cleanup ()
186185 client := litrpc .NewAccountsClient (clientConn )
187186
188- id , label , args , err := parseIDOrLabel (ctx )
187+ id , label , args , err := parseIDOrLabel (cli )
189188 if err != nil {
190189 return err
191190 }
@@ -195,8 +194,8 @@ func updateAccount(ctx *cli.Context) error {
195194 expirationDate int64
196195 )
197196 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" )
200199 case args .Present ():
201200 newBalance , err = strconv .ParseInt (args .First (), 10 , 64 )
202201 if err != nil {
@@ -206,8 +205,8 @@ func updateAccount(ctx *cli.Context) error {
206205 }
207206
208207 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" )
211210 case args .Present ():
212211 expirationDate , err = strconv .ParseInt (args .First (), 10 , 64 )
213212 if err != nil {
@@ -224,7 +223,7 @@ func updateAccount(ctx *cli.Context) error {
224223 AccountBalance : newBalance ,
225224 ExpirationDate : expirationDate ,
226225 }
227- resp , err := client .UpdateAccount (ctxb , req )
226+ resp , err := client .UpdateAccount (ctx , req )
228227 if err != nil {
229228 return err
230229 }
@@ -242,17 +241,17 @@ var listAccountsCommand = cli.Command{
242241 Action : listAccounts ,
243242}
244243
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 )
248247 if err != nil {
249248 return err
250249 }
251250 defer cleanup ()
252251 client := litrpc .NewAccountsClient (clientConn )
253252
254253 req := & litrpc.ListAccountsRequest {}
255- resp , err := client .ListAccounts (ctxb , req )
254+ resp , err := client .ListAccounts (ctx , req )
256255 if err != nil {
257256 return err
258257 }
@@ -281,16 +280,16 @@ var accountInfoCommand = cli.Command{
281280 Action : accountInfo ,
282281}
283282
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 )
287286 if err != nil {
288287 return err
289288 }
290289 defer cleanup ()
291290 client := litrpc .NewAccountsClient (clientConn )
292291
293- id , label , _ , err := parseIDOrLabel (ctx )
292+ id , label , _ , err := parseIDOrLabel (cli )
294293 if err != nil {
295294 return err
296295 }
@@ -299,7 +298,7 @@ func accountInfo(ctx *cli.Context) error {
299298 Id : id ,
300299 Label : label ,
301300 }
302- resp , err := client .AccountInfo (ctxb , req )
301+ resp , err := client .AccountInfo (ctx , req )
303302 if err != nil {
304303 return err
305304 }
@@ -327,16 +326,16 @@ var removeAccountCommand = cli.Command{
327326 Action : removeAccount ,
328327}
329328
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 )
333332 if err != nil {
334333 return err
335334 }
336335 defer cleanup ()
337336 client := litrpc .NewAccountsClient (clientConn )
338337
339- id , label , _ , err := parseIDOrLabel (ctx )
338+ id , label , _ , err := parseIDOrLabel (cli )
340339 if err != nil {
341340 return err
342341 }
@@ -345,7 +344,7 @@ func removeAccount(ctx *cli.Context) error {
345344 Id : id ,
346345 Label : label ,
347346 }
348- _ , err = client .RemoveAccount (ctxb , req )
347+ _ , err = client .RemoveAccount (ctx , req )
349348 return err
350349}
351350
0 commit comments