From e9bc1c14784070f3f4133e7091c6d4f865612178 Mon Sep 17 00:00:00 2001 From: Slyghtning Date: Wed, 25 Oct 2023 15:46:48 +0200 Subject: [PATCH] loop: list unspent static address outputs --- cmd/loop/staticaddr.go | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/cmd/loop/staticaddr.go b/cmd/loop/staticaddr.go index 394e5b1..c9626ba 100644 --- a/cmd/loop/staticaddr.go +++ b/cmd/loop/staticaddr.go @@ -15,6 +15,7 @@ var staticAddressCommands = cli.Command{ Category: "StaticAddress", Subcommands: []cli.Command{ newStaticAddressCommand, + listUnspentCommand, }, } @@ -57,6 +58,53 @@ func newStaticAddress(ctx *cli.Context) error { return nil } +var listUnspentCommand = cli.Command{ + Name: "listunspent", + ShortName: "l", + Usage: "List unspent static address outputs.", + Description: ` + List all unspent static address outputs. + `, + Flags: []cli.Flag{ + cli.IntFlag{ + Name: "min_confs", + Usage: "The minimum amount of confirmations an " + + "output should have to be listed.", + }, + cli.IntFlag{ + Name: "max_confs", + Usage: "The maximum number of confirmations an " + + "output could have to be listed.", + }, + }, + Action: listUnspent, +} + +func listUnspent(ctx *cli.Context) error { + ctxb := context.Background() + if ctx.NArg() > 0 { + return cli.ShowCommandHelp(ctx, "listunspent") + } + + client, cleanup, err := getAddressClient(ctx) + if err != nil { + return err + } + defer cleanup() + + resp, err := client.ListUnspent(ctxb, &looprpc.ListUnspentRequest{ + MinConfs: int32(ctx.Int("min_confs")), + MaxConfs: int32(ctx.Int("max_confs")), + }) + if err != nil { + return err + } + + printRespJSON(resp) + + return nil +} + func getAddressClient(ctx *cli.Context) (looprpc.StaticAddressClientClient, func(), error) {