Skip to content

Commit

Permalink
staticaddr: cmd listdeposits and listswaps
Browse files Browse the repository at this point in the history
  • Loading branch information
hieblmi committed Sep 2, 2024
1 parent 2b3b179 commit 18770ee
Show file tree
Hide file tree
Showing 11 changed files with 1,515 additions and 556 deletions.
4 changes: 2 additions & 2 deletions cmd/loop/quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ func quoteIn(ctx *cli.Context) error {
func depositAmount(ctx context.Context, client looprpc.SwapClientClient,
depositOutpoints []string) (btcutil.Amount, error) {

addressSummary, err := client.GetStaticAddressSummary(
ctx, &looprpc.StaticAddressSummaryRequest{
addressSummary, err := client.ListStaticAddressDeposits(
ctx, &looprpc.ListStaticAddressDepositsRequest{
Outpoints: depositOutpoints,
},
)
Expand Down
92 changes: 86 additions & 6 deletions cmd/loop/staticaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var staticAddressCommands = cli.Command{
Subcommands: []cli.Command{
newStaticAddressCommand,
listUnspentCommand,
listDepositsCommand,
listStaticAddressSwapsCommand,
withdrawalCommand,
summaryCommand,
},
Expand Down Expand Up @@ -206,6 +208,36 @@ func withdraw(ctx *cli.Context) error {
return nil
}

var listDepositsCommand = cli.Command{
Name: "listdeposits",
Usage: "Display a summary of static address related information.",
Description: `
`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "filter",
Usage: "specify a filter to only display deposits in " +
"the specified state. Leaving out the filter " +
"returns all deposits.\nThe state can be one " +
"of the following: \n" +
"deposited\nwithdrawing\nwithdrawn\n" +
"loopingin\nloopedin\n" +
"publish_expired_deposit\n" +
"sweep_htlc_timeout\nhtlc_timeout_swept\n" +
"wait_for_expiry_sweep\nexpired\nfailed\n.",
},
},
Action: listDeposits,
}

var listStaticAddressSwapsCommand = cli.Command{
Name: "listswaps",
Usage: "Display a summary of static address related information.",
Description: `
`,
Action: listStaticAddressSwaps,
}

var summaryCommand = cli.Command{
Name: "summary",
ShortName: "s",
Expand All @@ -231,10 +263,10 @@ var summaryCommand = cli.Command{
Action: summary,
}

func summary(ctx *cli.Context) error {
func listDeposits(ctx *cli.Context) error {
ctxb := context.Background()
if ctx.NArg() > 0 {
return cli.ShowCommandHelp(ctx, "summary")
return cli.ShowCommandHelp(ctx, "listdeposits")
}

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

resp, err := client.GetStaticAddressSummary(
ctxb, &looprpc.StaticAddressSummaryRequest{
resp, err := client.ListStaticAddressDeposits(
ctxb, &looprpc.ListStaticAddressDepositsRequest{
StateFilter: filterState,
},
)
Expand All @@ -299,6 +331,54 @@ func summary(ctx *cli.Context) error {
return nil
}

func listStaticAddressSwaps(ctx *cli.Context) error {
ctxb := context.Background()
if ctx.NArg() > 0 {
return cli.ShowCommandHelp(ctx, "listswaps")
}

client, cleanup, err := getClient(ctx)
if err != nil {
return err
}
defer cleanup()

resp, err := client.ListStaticAddressSwaps(
ctxb, &looprpc.ListStaticAddressSwapsRequest{},
)
if err != nil {
return err
}

printRespJSON(resp)

return nil
}

func summary(ctx *cli.Context) error {
ctxb := context.Background()
if ctx.NArg() > 0 {
return cli.ShowCommandHelp(ctx, "summary")
}

client, cleanup, err := getClient(ctx)
if err != nil {
return err
}
defer cleanup()

resp, err := client.GetStaticAddressSummary(
ctxb, &looprpc.StaticAddressSummaryRequest{},
)
if err != nil {
return err
}

printRespJSON(resp)

return nil
}

func utxosToOutpoints(utxos []string) ([]*looprpc.OutPoint, error) {
outpoints := make([]*looprpc.OutPoint, 0, len(utxos))
if len(utxos) == 0 {
Expand Down Expand Up @@ -382,8 +462,8 @@ func staticAddressLoopIn(ctx *cli.Context) error {
}

// Get the amount we need to quote for.
summaryResp, err := client.GetStaticAddressSummary(
ctxb, &looprpc.StaticAddressSummaryRequest{
summaryResp, err := client.ListStaticAddressDeposits(
ctxb, &looprpc.ListStaticAddressDepositsRequest{
StateFilter: looprpc.DepositState_DEPOSITED,
},
)
Expand Down
14 changes: 14 additions & 0 deletions loopd/perms/perms.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ var RequiredPermissions = map[string][]bakery.Op{
Entity: "loop",
Action: "in",
}},
"/looprpc.SwapClient/ListStaticAddressDeposits": {{
Entity: "swap",
Action: "read",
}, {
Entity: "loop",
Action: "in",
}},
"/looprpc.SwapClient/ListStaticAddressSwaps": {{
Entity: "swap",
Action: "read",
}, {
Entity: "loop",
Action: "in",
}},
"/looprpc.SwapClient/GetStaticAddressSummary": {{
Entity: "swap",
Action: "read",
Expand Down
Loading

0 comments on commit 18770ee

Please sign in to comment.