Skip to content

Commit b88116e

Browse files
committed
staticaddr: cmd listdeposits and listswaps
1 parent 2a89748 commit b88116e

File tree

11 files changed

+1531
-563
lines changed

11 files changed

+1531
-563
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/swapserverrpc"
1516
"github.com/lightningnetwork/lnd/routing/route"
1617
"github.com/urfave/cli"
@@ -23,6 +24,8 @@ var staticAddressCommands = cli.Command{
2324
Subcommands: []cli.Command{
2425
newStaticAddressCommand,
2526
listUnspentCommand,
27+
listDepositsCommand,
28+
listStaticAddressSwapsCommand,
2629
withdrawalCommand,
2730
summaryCommand,
2831
},
@@ -208,6 +211,36 @@ func withdraw(ctx *cli.Context) error {
208211
return nil
209212
}
210213

214+
var listDepositsCommand = cli.Command{
215+
Name: "listdeposits",
216+
Usage: "Display a summary of static address related information.",
217+
Description: `
218+
`,
219+
Flags: []cli.Flag{
220+
cli.StringFlag{
221+
Name: "filter",
222+
Usage: "specify a filter to only display deposits in " +
223+
"the specified state. Leaving out the filter " +
224+
"returns all deposits.\nThe state can be one " +
225+
"of the following: \n" +
226+
"deposited\nwithdrawing\nwithdrawn\n" +
227+
"looping_in\nlooped_in\n" +
228+
"publish_expired_deposit\n" +
229+
"sweep_htlc_timeout\nhtlc_timeout_swept\n" +
230+
"wait_for_expiry_sweep\nexpired\nfailed\n.",
231+
},
232+
},
233+
Action: listDeposits,
234+
}
235+
236+
var listStaticAddressSwapsCommand = cli.Command{
237+
Name: "listswaps",
238+
Usage: "Display a summary of static address related information.",
239+
Description: `
240+
`,
241+
Action: listStaticAddressSwaps,
242+
}
243+
211244
var summaryCommand = cli.Command{
212245
Name: "summary",
213246
ShortName: "s",
@@ -233,10 +266,10 @@ var summaryCommand = cli.Command{
233266
Action: summary,
234267
}
235268

236-
func summary(ctx *cli.Context) error {
269+
func listDeposits(ctx *cli.Context) error {
237270
ctxb := context.Background()
238271
if ctx.NArg() > 0 {
239-
return cli.ShowCommandHelp(ctx, "summary")
272+
return cli.ShowCommandHelp(ctx, "listdeposits")
240273
}
241274

242275
client, cleanup, err := getClient(ctx)
@@ -287,8 +320,8 @@ func summary(ctx *cli.Context) error {
287320
filterState = looprpc.DepositState_UNKNOWN_STATE
288321
}
289322

290-
resp, err := client.GetStaticAddressSummary(
291-
ctxb, &looprpc.StaticAddressSummaryRequest{
323+
resp, err := client.ListStaticAddressDeposits(
324+
ctxb, &looprpc.ListStaticAddressDepositsRequest{
292325
StateFilter: filterState,
293326
},
294327
)
@@ -301,6 +334,54 @@ func summary(ctx *cli.Context) error {
301334
return nil
302335
}
303336

337+
func listStaticAddressSwaps(ctx *cli.Context) error {
338+
ctxb := context.Background()
339+
if ctx.NArg() > 0 {
340+
return cli.ShowCommandHelp(ctx, "listswaps")
341+
}
342+
343+
client, cleanup, err := getClient(ctx)
344+
if err != nil {
345+
return err
346+
}
347+
defer cleanup()
348+
349+
resp, err := client.ListStaticAddressSwaps(
350+
ctxb, &looprpc.ListStaticAddressSwapsRequest{},
351+
)
352+
if err != nil {
353+
return err
354+
}
355+
356+
printRespJSON(resp)
357+
358+
return nil
359+
}
360+
361+
func summary(ctx *cli.Context) error {
362+
ctxb := context.Background()
363+
if ctx.NArg() > 0 {
364+
return cli.ShowCommandHelp(ctx, "summary")
365+
}
366+
367+
client, cleanup, err := getClient(ctx)
368+
if err != nil {
369+
return err
370+
}
371+
defer cleanup()
372+
373+
resp, err := client.GetStaticAddressSummary(
374+
ctxb, &looprpc.StaticAddressSummaryRequest{},
375+
)
376+
if err != nil {
377+
return err
378+
}
379+
380+
printRespJSON(resp)
381+
382+
return nil
383+
}
384+
304385
func utxosToOutpoints(utxos []string) ([]*looprpc.OutPoint, error) {
305386
outpoints := make([]*looprpc.OutPoint, 0, len(utxos))
306387
if len(utxos) == 0 {
@@ -384,23 +465,31 @@ func staticAddressLoopIn(ctx *cli.Context) error {
384465
}
385466

386467
// Get the amount we need to quote for.
387-
summaryResp, err := client.GetStaticAddressSummary(
388-
ctxb, &looprpc.StaticAddressSummaryRequest{
468+
depositList, err := client.ListStaticAddressDeposits(
469+
ctxb, &looprpc.ListStaticAddressDepositsRequest{
389470
StateFilter: looprpc.DepositState_DEPOSITED,
390471
},
391472
)
392473
if err != nil {
393474
return err
394475
}
395476

477+
if len(depositList.FilteredDeposits) == 0 {
478+
errString := fmt.Sprintf("no confirmed deposits available, "+
479+
"deposits need at least %v confirmations",
480+
deposit.DefaultConfTarget)
481+
482+
return errors.New(errString)
483+
}
484+
396485
var depositOutpoints []string
397486
switch {
398487
case isAllSelected == isUtxoSelected:
399488
return errors.New("must select either all or some utxos")
400489

401490
case isAllSelected:
402491
depositOutpoints = depositsToOutpoints(
403-
summaryResp.FilteredDeposits,
492+
depositList.FilteredDeposits,
404493
)
405494

406495
case isUtxoSelected:
@@ -430,7 +519,7 @@ func staticAddressLoopIn(ctx *cli.Context) error {
430519
// populate the quote request with the sum of selected deposits and
431520
// prompt the user for acceptance.
432521
quoteReq.Amt, err = sumDeposits(
433-
depositOutpoints, summaryResp.FilteredDeposits,
522+
depositOutpoints, depositList.FilteredDeposits,
434523
)
435524
if err != nil {
436525
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)