From b3cbab44826cd1a95a4081ab1642ffc4faeb5733 Mon Sep 17 00:00:00 2001 From: Torakushi Date: Thu, 2 Feb 2023 13:40:02 +0100 Subject: [PATCH] lncli: possibility to define an address type for changes in FundPsbt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With this commit, we can define an address type for default/imported accounts in FundPsbt using '—change_type' flag. The value for this flag can only be 'p2tr' at the moment. If not specified, we will use P2WKH addresses for change outputs. Custom accounts don’t support this flag as they have a unique scope. --- cmd/lncli/walletrpc_active.go | 37 +++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/cmd/lncli/walletrpc_active.go b/cmd/lncli/walletrpc_active.go index 16c99cb09..abccb2b2c 100644 --- a/cmd/lncli/walletrpc_active.go +++ b/cmd/lncli/walletrpc_active.go @@ -582,7 +582,7 @@ var fundPsbtCommand = cli.Command{ Name: "fund", Usage: "Fund a Partially Signed Bitcoin Transaction (PSBT).", ArgsUsage: "[--template_psbt=T | [--outputs=O [--inputs=I]]] " + - "[--conf_target=C | --sat_per_vbyte=S]", + "[--conf_target=C | --sat_per_vbyte=S] [--change_type=A]", Description: ` The fund command creates a fully populated PSBT that contains enough inputs to fund the outputs specified in either the PSBT or the @@ -606,7 +606,14 @@ var fundPsbtCommand = cli.Command{ The optional 'inputs' flag decodes a JSON list of UTXO outpoints as returned by the listunspent command for example: - --inputs='[":",":",...]' + --inputs='[":",":",...] + + The optional '--change-type' flag permits to choose the address type + for the change for default accounts and single imported public keys. + The custom address type can only be p2tr at the moment (p2wkh will be + used by default). No custom address type should be provided for custom + accounts as we will always generate the change address using the coin + selection key scope. `, Flags: []cli.Flag{ cli.StringFlag{ @@ -642,6 +649,17 @@ var fundPsbtCommand = cli.Command{ Usage: "(optional) the name of the account to use to " + "create/fund the PSBT", }, + cli.StringFlag{ + Name: "change_type", + Usage: "(optional) the type of the change address to " + + "use to create/fund the PSBT. If no address " + + "type is provided, p2wpkh will be used for " + + "default accounts and single imported public " + + "keys. No custom address type should be " + + "provided for custom accounts as we will " + + "always use the coin selection key scope to " + + "generate the change address", + }, }, Action: actionDecorator(fundPsbt), } @@ -747,6 +765,21 @@ func fundPsbt(ctx *cli.Context) error { } } + if ctx.IsSet("change_type") { + switch addressType := ctx.String("change_type"); addressType { + case "p2tr": + //nolint:lll + req.ChangeType = walletrpc.ChangeAddressType_CHANGE_ADDRESS_TYPE_P2TR + + default: + return fmt.Errorf("invalid type for the "+ + "change type: %s. At the moment, the "+ + "only address type supported is p2tr "+ + "(default to p2wkh)", + addressType) + } + } + walletClient, cleanUp := getWalletClient(ctx) defer cleanUp()