@@ -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/staticaddr/loopin"
1516 "github.com/lightninglabs/loop/swapserverrpc"
1617 "github.com/lightningnetwork/lnd/routing/route"
@@ -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 },
@@ -216,6 +219,36 @@ func withdraw(ctx *cli.Context) error {
216219 return nil
217220}
218221
222+ var listDepositsCommand = cli.Command {
223+ Name : "listdeposits" ,
224+ Usage : "Display a summary of static address related information." ,
225+ Description : `
226+ ` ,
227+ Flags : []cli.Flag {
228+ cli.StringFlag {
229+ Name : "filter" ,
230+ Usage : "specify a filter to only display deposits in " +
231+ "the specified state. Leaving out the filter " +
232+ "returns all deposits.\n The state can be one " +
233+ "of the following: \n " +
234+ "deposited\n withdrawing\n withdrawn\n " +
235+ "looping_in\n looped_in\n " +
236+ "publish_expired_deposit\n " +
237+ "sweep_htlc_timeout\n htlc_timeout_swept\n " +
238+ "wait_for_expiry_sweep\n expired\n failed\n ." ,
239+ },
240+ },
241+ Action : listDeposits ,
242+ }
243+
244+ var listStaticAddressSwapsCommand = cli.Command {
245+ Name : "listswaps" ,
246+ Usage : "Display a summary of static address related information." ,
247+ Description : `
248+ ` ,
249+ Action : listStaticAddressSwaps ,
250+ }
251+
219252var summaryCommand = cli.Command {
220253 Name : "summary" ,
221254 ShortName : "s" ,
@@ -241,10 +274,10 @@ var summaryCommand = cli.Command{
241274 Action : summary ,
242275}
243276
244- func summary (ctx * cli.Context ) error {
277+ func listDeposits (ctx * cli.Context ) error {
245278 ctxb := context .Background ()
246279 if ctx .NArg () > 0 {
247- return cli .ShowCommandHelp (ctx , "summary " )
280+ return cli .ShowCommandHelp (ctx , "listdeposits " )
248281 }
249282
250283 client , cleanup , err := getClient (ctx )
@@ -295,8 +328,8 @@ func summary(ctx *cli.Context) error {
295328 filterState = looprpc .DepositState_UNKNOWN_STATE
296329 }
297330
298- resp , err := client .GetStaticAddressSummary (
299- ctxb , & looprpc.StaticAddressSummaryRequest {
331+ resp , err := client .ListStaticAddressDeposits (
332+ ctxb , & looprpc.ListStaticAddressDepositsRequest {
300333 StateFilter : filterState ,
301334 },
302335 )
@@ -309,6 +342,54 @@ func summary(ctx *cli.Context) error {
309342 return nil
310343}
311344
345+ func listStaticAddressSwaps (ctx * cli.Context ) error {
346+ ctxb := context .Background ()
347+ if ctx .NArg () > 0 {
348+ return cli .ShowCommandHelp (ctx , "listswaps" )
349+ }
350+
351+ client , cleanup , err := getClient (ctx )
352+ if err != nil {
353+ return err
354+ }
355+ defer cleanup ()
356+
357+ resp , err := client .ListStaticAddressSwaps (
358+ ctxb , & looprpc.ListStaticAddressSwapsRequest {},
359+ )
360+ if err != nil {
361+ return err
362+ }
363+
364+ printRespJSON (resp )
365+
366+ return nil
367+ }
368+
369+ func summary (ctx * cli.Context ) error {
370+ ctxb := context .Background ()
371+ if ctx .NArg () > 0 {
372+ return cli .ShowCommandHelp (ctx , "summary" )
373+ }
374+
375+ client , cleanup , err := getClient (ctx )
376+ if err != nil {
377+ return err
378+ }
379+ defer cleanup ()
380+
381+ resp , err := client .GetStaticAddressSummary (
382+ ctxb , & looprpc.StaticAddressSummaryRequest {},
383+ )
384+ if err != nil {
385+ return err
386+ }
387+
388+ printRespJSON (resp )
389+
390+ return nil
391+ }
392+
312393func utxosToOutpoints (utxos []string ) ([]* looprpc.OutPoint , error ) {
313394 outpoints := make ([]* looprpc.OutPoint , 0 , len (utxos ))
314395 if len (utxos ) == 0 {
@@ -393,23 +474,31 @@ func staticAddressLoopIn(ctx *cli.Context) error {
393474 }
394475
395476 // Get the amount we need to quote for.
396- summaryResp , err := client .GetStaticAddressSummary (
397- ctxb , & looprpc.StaticAddressSummaryRequest {
477+ depositList , err := client .ListStaticAddressDeposits (
478+ ctxb , & looprpc.ListStaticAddressDepositsRequest {
398479 StateFilter : looprpc .DepositState_DEPOSITED ,
399480 },
400481 )
401482 if err != nil {
402483 return err
403484 }
404485
486+ if len (depositList .FilteredDeposits ) == 0 {
487+ errString := fmt .Sprintf ("no confirmed deposits available, " +
488+ "deposits need at least %v confirmations" ,
489+ deposit .DefaultConfTarget )
490+
491+ return errors .New (errString )
492+ }
493+
405494 var depositOutpoints []string
406495 switch {
407496 case isAllSelected == isUtxoSelected :
408497 return errors .New ("must select either all or some utxos" )
409498
410499 case isAllSelected :
411500 depositOutpoints = depositsToOutpoints (
412- summaryResp .FilteredDeposits ,
501+ depositList .FilteredDeposits ,
413502 )
414503
415504 case isUtxoSelected :
@@ -439,7 +528,7 @@ func staticAddressLoopIn(ctx *cli.Context) error {
439528 // populate the quote request with the sum of selected deposits and
440529 // prompt the user for acceptance.
441530 quoteReq .Amt , err = sumDeposits (
442- depositOutpoints , summaryResp .FilteredDeposits ,
531+ depositOutpoints , depositList .FilteredDeposits ,
443532 )
444533 if err != nil {
445534 return err
0 commit comments