Skip to content

Commit b351145

Browse files
committed
staticaddr: cmd listdeposits and listswaps
1 parent a597e12 commit b351145

File tree

11 files changed

+1515
-556
lines changed

11 files changed

+1515
-556
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: 86 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ var staticAddressCommands = cli.Command{
2424
Subcommands: []cli.Command{
2525
newStaticAddressCommand,
2626
listUnspentCommand,
27+
listDepositsCommand,
28+
listStaticAddressSwapsCommand,
2729
withdrawalCommand,
2830
summaryCommand,
2931
},
@@ -206,6 +208,36 @@ func withdraw(ctx *cli.Context) error {
206208
return nil
207209
}
208210

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

234-
func summary(ctx *cli.Context) error {
266+
func listDeposits(ctx *cli.Context) error {
235267
ctxb := context.Background()
236268
if ctx.NArg() > 0 {
237-
return cli.ShowCommandHelp(ctx, "summary")
269+
return cli.ShowCommandHelp(ctx, "listdeposits")
238270
}
239271

240272
client, cleanup, err := getClient(ctx)
@@ -285,8 +317,8 @@ func summary(ctx *cli.Context) error {
285317
filterState = looprpc.DepositState_UNKNOWN_STATE
286318
}
287319

288-
resp, err := client.GetStaticAddressSummary(
289-
ctxb, &looprpc.StaticAddressSummaryRequest{
320+
resp, err := client.ListStaticAddressDeposits(
321+
ctxb, &looprpc.ListStaticAddressDepositsRequest{
290322
StateFilter: filterState,
291323
},
292324
)
@@ -299,6 +331,54 @@ func summary(ctx *cli.Context) error {
299331
return nil
300332
}
301333

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

384464
// Get the amount we need to quote for.
385-
summaryResp, err := client.GetStaticAddressSummary(
386-
ctxb, &looprpc.StaticAddressSummaryRequest{
465+
summaryResp, err := client.ListStaticAddressDeposits(
466+
ctxb, &looprpc.ListStaticAddressDepositsRequest{
387467
StateFilter: looprpc.DepositState_DEPOSITED,
388468
},
389469
)

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)