@@ -11,6 +11,7 @@ import (
1111 "github.com/btcsuite/btcd/chaincfg/chainhash"
1212 "github.com/lightninglabs/loop/labels"
1313 "github.com/lightninglabs/loop/looprpc"
14+ "github.com/lightninglabs/loop/staticaddr/deposit"
1415 "github.com/lightninglabs/loop/swapserverrpc"
1516 "github.com/lightningnetwork/lnd/routing/route"
1617 "github.com/urfave/cli"
@@ -24,6 +25,8 @@ var staticAddressCommands = cli.Command{
2425 Subcommands : []cli.Command {
2526 newStaticAddressCommand ,
2627 listUnspentCommand ,
28+ listDepositsCommand ,
29+ listStaticAddressSwapsCommand ,
2730 withdrawalCommand ,
2831 summaryCommand ,
2932 },
@@ -206,6 +209,36 @@ func withdraw(ctx *cli.Context) error {
206209 return nil
207210}
208211
212+ var listDepositsCommand = cli.Command {
213+ Name : "listdeposits" ,
214+ Usage : "Display a summary of static address related information." ,
215+ Description : `
216+ ` ,
217+ Flags : []cli.Flag {
218+ cli.StringFlag {
219+ Name : "filter" ,
220+ Usage : "specify a filter to only display deposits in " +
221+ "the specified state. Leaving out the filter " +
222+ "returns all deposits.\n The state can be one " +
223+ "of the following: \n " +
224+ "deposited\n withdrawing\n withdrawn\n " +
225+ "looping_in\n looped_in\n " +
226+ "publish_expired_deposit\n " +
227+ "sweep_htlc_timeout\n htlc_timeout_swept\n " +
228+ "wait_for_expiry_sweep\n expired\n failed\n ." ,
229+ },
230+ },
231+ Action : listDeposits ,
232+ }
233+
234+ var listStaticAddressSwapsCommand = cli.Command {
235+ Name : "listswaps" ,
236+ Usage : "Display a summary of static address related information." ,
237+ Description : `
238+ ` ,
239+ Action : listStaticAddressSwaps ,
240+ }
241+
209242var summaryCommand = cli.Command {
210243 Name : "summary" ,
211244 ShortName : "s" ,
@@ -231,10 +264,10 @@ var summaryCommand = cli.Command{
231264 Action : summary ,
232265}
233266
234- func summary (ctx * cli.Context ) error {
267+ func listDeposits (ctx * cli.Context ) error {
235268 ctxb := context .Background ()
236269 if ctx .NArg () > 0 {
237- return cli .ShowCommandHelp (ctx , "summary " )
270+ return cli .ShowCommandHelp (ctx , "listdeposits " )
238271 }
239272
240273 client , cleanup , err := getClient (ctx )
@@ -285,8 +318,8 @@ func summary(ctx *cli.Context) error {
285318 filterState = looprpc .DepositState_UNKNOWN_STATE
286319 }
287320
288- resp , err := client .GetStaticAddressSummary (
289- ctxb , & looprpc.StaticAddressSummaryRequest {
321+ resp , err := client .ListStaticAddressDeposits (
322+ ctxb , & looprpc.ListStaticAddressDepositsRequest {
290323 StateFilter : filterState ,
291324 },
292325 )
@@ -299,6 +332,54 @@ func summary(ctx *cli.Context) error {
299332 return nil
300333}
301334
335+ func listStaticAddressSwaps (ctx * cli.Context ) error {
336+ ctxb := context .Background ()
337+ if ctx .NArg () > 0 {
338+ return cli .ShowCommandHelp (ctx , "listswaps" )
339+ }
340+
341+ client , cleanup , err := getClient (ctx )
342+ if err != nil {
343+ return err
344+ }
345+ defer cleanup ()
346+
347+ resp , err := client .ListStaticAddressSwaps (
348+ ctxb , & looprpc.ListStaticAddressSwapsRequest {},
349+ )
350+ if err != nil {
351+ return err
352+ }
353+
354+ printRespJSON (resp )
355+
356+ return nil
357+ }
358+
359+ func summary (ctx * cli.Context ) error {
360+ ctxb := context .Background ()
361+ if ctx .NArg () > 0 {
362+ return cli .ShowCommandHelp (ctx , "summary" )
363+ }
364+
365+ client , cleanup , err := getClient (ctx )
366+ if err != nil {
367+ return err
368+ }
369+ defer cleanup ()
370+
371+ resp , err := client .GetStaticAddressSummary (
372+ ctxb , & looprpc.StaticAddressSummaryRequest {},
373+ )
374+ if err != nil {
375+ return err
376+ }
377+
378+ printRespJSON (resp )
379+
380+ return nil
381+ }
382+
302383func utxosToOutpoints (utxos []string ) ([]* looprpc.OutPoint , error ) {
303384 outpoints := make ([]* looprpc.OutPoint , 0 , len (utxos ))
304385 if len (utxos ) == 0 {
@@ -382,23 +463,31 @@ func staticAddressLoopIn(ctx *cli.Context) error {
382463 }
383464
384465 // Get the amount we need to quote for.
385- summaryResp , err := client .GetStaticAddressSummary (
386- ctxb , & looprpc.StaticAddressSummaryRequest {
466+ depositList , err := client .ListStaticAddressDeposits (
467+ ctxb , & looprpc.ListStaticAddressDepositsRequest {
387468 StateFilter : looprpc .DepositState_DEPOSITED ,
388469 },
389470 )
390471 if err != nil {
391472 return err
392473 }
393474
475+ if len (depositList .FilteredDeposits ) == 0 {
476+ errString := fmt .Sprintf ("no confirmed deposits available, " +
477+ "deposits need at least %v confirmations" ,
478+ deposit .DefaultConfTarget )
479+
480+ return errors .New (errString )
481+ }
482+
394483 var depositOutpoints []string
395484 switch {
396485 case isAllSelected == isUtxoSelected :
397486 return errors .New ("must select either all or some utxos" )
398487
399488 case isAllSelected :
400489 depositOutpoints = depositsToOutpoints (
401- summaryResp .FilteredDeposits ,
490+ depositList .FilteredDeposits ,
402491 )
403492
404493 case isUtxoSelected :
@@ -428,7 +517,7 @@ func staticAddressLoopIn(ctx *cli.Context) error {
428517 // populate the quote request with the sum of selected deposits and
429518 // prompt the user for acceptance.
430519 quoteReq .Amt , err = sumDeposits (
431- depositOutpoints , summaryResp .FilteredDeposits ,
520+ depositOutpoints , depositList .FilteredDeposits ,
432521 )
433522 if err != nil {
434523 return err
0 commit comments