diff --git a/cmd/lncli/walletrpc_active.go b/cmd/lncli/walletrpc_active.go index fe0bd2351..870464f61 100644 --- a/cmd/lncli/walletrpc_active.go +++ b/cmd/lncli/walletrpc_active.go @@ -43,6 +43,16 @@ var ( importPubKeyCommand, }, } + + // addressesCommand is a wallet subcommand that is responsible for + // address management operations. + addressesCommand = cli.Command{ + Name: "addresses", + Usage: "Interact with wallet addresses.", + Subcommands: []cli.Command{ + listAddressesCommand, + }, + } ) // walletCommands will return the set of commands to enable for walletrpc @@ -67,6 +77,7 @@ func walletCommands() []cli.Command { psbtCommand, accountsCommand, requiredReserveCommand, + addressesCommand, }, }, } @@ -1131,6 +1142,54 @@ func requiredReserve(ctx *cli.Context) error { return nil } +var listAddressesCommand = cli.Command{ + Name: "list", + Usage: "Retrieve information of existing on-chain wallet addresses.", + Description: ` + Retrieves information of existing on-chain wallet addresses along with + their type, internal/external and balance. + `, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "account_name", + Usage: "(optional) only addreses matching this account " + + "are returned", + }, + cli.BoolFlag{ + Name: "show_custom_accounts", + Usage: "(optional) set this to true to show lnd's " + + "custom accounts", + }, + }, + Action: actionDecorator(listAddresses), +} + +func listAddresses(ctx *cli.Context) error { + ctxc := getContext() + + // Display the command's help message if we do not have the expected + // number of arguments/flags. + if ctx.NArg() > 0 || ctx.NumFlags() > 2 { + return cli.ShowCommandHelp(ctx, "list") + } + + walletClient, cleanUp := getWalletClient(ctx) + defer cleanUp() + + req := &walletrpc.ListAddressesRequest{ + AccountName: ctx.String("account_name"), + ShowCustomAccounts: ctx.Bool("show_custom_accounts"), + } + resp, err := walletClient.ListAddresses(ctxc, req) + if err != nil { + return err + } + + printRespJSON(resp) + + return nil +} + var importAccountCommand = cli.Command{ Name: "import", Usage: "Import an on-chain account into the wallet through its " +