Skip to content

Commit d4cbb87

Browse files
committed
staticaddr: cmd listdeposits and listswaps
1 parent 01098b3 commit d4cbb87

File tree

11 files changed

+1588
-511
lines changed

11 files changed

+1588
-511
lines changed

cmd/loop/quote.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ func quoteIn(ctx *cli.Context) error {
139139
func depositAmount(ctx context.Context, client looprpc.SwapClientClient,
140140
depositOutpoints []string) (btcutil.Amount, error) {
141141

142-
addressSummary, err := client.GetStaticAddressSummary(
143-
ctx, &looprpc.StaticAddressSummaryRequest{
142+
addressSummary, err := client.ListStaticAddressDeposits(
143+
ctx, &looprpc.ListStaticAddressDepositsRequest{
144144
Outpoints: depositOutpoints,
145145
},
146146
)

cmd/loop/staticaddr.go

Lines changed: 97 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
},
@@ -217,6 +220,36 @@ func withdraw(ctx *cli.Context) error {
217220
return nil
218221
}
219222

223+
var listDepositsCommand = cli.Command{
224+
Name: "listdeposits",
225+
Usage: "Display a summary of static address related information.",
226+
Description: `
227+
`,
228+
Flags: []cli.Flag{
229+
cli.StringFlag{
230+
Name: "filter",
231+
Usage: "specify a filter to only display deposits in " +
232+
"the specified state. Leaving out the filter " +
233+
"returns all deposits.\nThe state can be one " +
234+
"of the following: \n" +
235+
"deposited\nwithdrawing\nwithdrawn\n" +
236+
"looping_in\nlooped_in\n" +
237+
"publish_expired_deposit\n" +
238+
"sweep_htlc_timeout\nhtlc_timeout_swept\n" +
239+
"wait_for_expiry_sweep\nexpired\nfailed\n.",
240+
},
241+
},
242+
Action: listDeposits,
243+
}
244+
245+
var listStaticAddressSwapsCommand = cli.Command{
246+
Name: "listswaps",
247+
Usage: "Display a summary of static address related information.",
248+
Description: `
249+
`,
250+
Action: listStaticAddressSwaps,
251+
}
252+
220253
var summaryCommand = cli.Command{
221254
Name: "summary",
222255
ShortName: "s",
@@ -242,10 +275,10 @@ var summaryCommand = cli.Command{
242275
Action: summary,
243276
}
244277

245-
func summary(ctx *cli.Context) error {
278+
func listDeposits(ctx *cli.Context) error {
246279
ctxb := context.Background()
247280
if ctx.NArg() > 0 {
248-
return cli.ShowCommandHelp(ctx, "summary")
281+
return cli.ShowCommandHelp(ctx, "listdeposits")
249282
}
250283

251284
client, cleanup, err := getClient(ctx)
@@ -293,8 +326,8 @@ func summary(ctx *cli.Context) error {
293326
filterState = looprpc.DepositState_UNKNOWN_STATE
294327
}
295328

296-
resp, err := client.GetStaticAddressSummary(
297-
ctxb, &looprpc.StaticAddressSummaryRequest{
329+
resp, err := client.ListStaticAddressDeposits(
330+
ctxb, &looprpc.ListStaticAddressDepositsRequest{
298331
StateFilter: filterState,
299332
},
300333
)
@@ -307,6 +340,54 @@ func summary(ctx *cli.Context) error {
307340
return nil
308341
}
309342

343+
func listStaticAddressSwaps(ctx *cli.Context) error {
344+
ctxb := context.Background()
345+
if ctx.NArg() > 0 {
346+
return cli.ShowCommandHelp(ctx, "listswaps")
347+
}
348+
349+
client, cleanup, err := getClient(ctx)
350+
if err != nil {
351+
return err
352+
}
353+
defer cleanup()
354+
355+
resp, err := client.ListStaticAddressSwaps(
356+
ctxb, &looprpc.ListStaticAddressSwapsRequest{},
357+
)
358+
if err != nil {
359+
return err
360+
}
361+
362+
printRespJSON(resp)
363+
364+
return nil
365+
}
366+
367+
func summary(ctx *cli.Context) error {
368+
ctxb := context.Background()
369+
if ctx.NArg() > 0 {
370+
return cli.ShowCommandHelp(ctx, "summary")
371+
}
372+
373+
client, cleanup, err := getClient(ctx)
374+
if err != nil {
375+
return err
376+
}
377+
defer cleanup()
378+
379+
resp, err := client.GetStaticAddressSummary(
380+
ctxb, &looprpc.StaticAddressSummaryRequest{},
381+
)
382+
if err != nil {
383+
return err
384+
}
385+
386+
printRespJSON(resp)
387+
388+
return nil
389+
}
390+
310391
func utxosToOutpoints(utxos []string) ([]*looprpc.OutPoint, error) {
311392
outpoints := make([]*looprpc.OutPoint, 0, len(utxos))
312393
if len(utxos) == 0 {
@@ -391,23 +472,31 @@ func staticAddressLoopIn(ctx *cli.Context) error {
391472
}
392473

393474
// Get the amount we need to quote for.
394-
summaryResp, err := client.GetStaticAddressSummary(
395-
ctxb, &looprpc.StaticAddressSummaryRequest{
475+
depositList, err := client.ListStaticAddressDeposits(
476+
ctxb, &looprpc.ListStaticAddressDepositsRequest{
396477
StateFilter: looprpc.DepositState_DEPOSITED,
397478
},
398479
)
399480
if err != nil {
400481
return err
401482
}
402483

484+
if len(depositList.FilteredDeposits) == 0 {
485+
errString := fmt.Sprintf("no confirmed deposits available, "+
486+
"deposits need at least %v confirmations",
487+
deposit.DefaultConfTarget)
488+
489+
return errors.New(errString)
490+
}
491+
403492
var depositOutpoints []string
404493
switch {
405494
case isAllSelected == isUtxoSelected:
406495
return errors.New("must select either all or some utxos")
407496

408497
case isAllSelected:
409498
depositOutpoints = depositsToOutpoints(
410-
summaryResp.FilteredDeposits,
499+
depositList.FilteredDeposits,
411500
)
412501

413502
case isUtxoSelected:
@@ -437,7 +526,7 @@ func staticAddressLoopIn(ctx *cli.Context) error {
437526
// populate the quote request with the sum of selected deposits and
438527
// prompt the user for acceptance.
439528
quoteReq.Amt, err = sumDeposits(
440-
depositOutpoints, summaryResp.FilteredDeposits,
529+
depositOutpoints, depositList.FilteredDeposits,
441530
)
442531
if err != nil {
443532
return err

loopd/perms/perms.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ var RequiredPermissions = map[string][]bakery.Op{
9494
Entity: "loop",
9595
Action: "in",
9696
}},
97+
"/looprpc.SwapClient/ListStaticAddressDeposits": {{
98+
Entity: "swap",
99+
Action: "read",
100+
}, {
101+
Entity: "loop",
102+
Action: "in",
103+
}},
104+
"/looprpc.SwapClient/ListStaticAddressSwaps": {{
105+
Entity: "swap",
106+
Action: "read",
107+
}, {
108+
Entity: "loop",
109+
Action: "in",
110+
}},
97111
"/looprpc.SwapClient/GetStaticAddressSummary": {{
98112
Entity: "swap",
99113
Action: "read",

0 commit comments

Comments
 (0)