From 925229f9dfaad697b252a1bb6c97622b9fa725a3 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Mon, 28 Jun 2021 12:22:08 +0200 Subject: [PATCH] walletrpc+lncli: allow zero output psbt funding To support the cpfp fee bump use case where no external outputs are required. --- cmd/lncli/walletrpc_active.go | 26 ++++++++++------------ docs/release-notes/release-notes-0.14.0.md | 6 +++++ lnrpc/walletrpc/walletkit_server.go | 3 --- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/cmd/lncli/walletrpc_active.go b/cmd/lncli/walletrpc_active.go index 7710b3a3a..fa6104d35 100644 --- a/cmd/lncli/walletrpc_active.go +++ b/cmd/lncli/walletrpc_active.go @@ -659,26 +659,24 @@ func fundPsbt(ctx *cli.Context) error { Psbt: psbtBytes, } - // The user manually specified outputs and optional inputs in JSON + // The user manually specified outputs and/or inputs in JSON // format. - case len(ctx.String("outputs")) > 0: + case len(ctx.String("outputs")) > 0 || len(ctx.String("inputs")) > 0: var ( tpl = &walletrpc.TxTemplate{} amountToAddr map[string]uint64 ) - // Parse the address to amount map as JSON now. At least one - // entry must be present. - jsonMap := []byte(ctx.String("outputs")) - if err := json.Unmarshal(jsonMap, &amountToAddr); err != nil { - return fmt.Errorf("error parsing outputs JSON: %v", - err) + if len(ctx.String("outputs")) > 0 { + // Parse the address to amount map as JSON now. At least one + // entry must be present. + jsonMap := []byte(ctx.String("outputs")) + if err := json.Unmarshal(jsonMap, &amountToAddr); err != nil { + return fmt.Errorf("error parsing outputs JSON: %v", + err) + } + tpl.Outputs = amountToAddr } - if len(amountToAddr) == 0 { - return fmt.Errorf("at least one output must be " + - "specified") - } - tpl.Outputs = amountToAddr // Inputs are optional. if len(ctx.String("inputs")) > 0 { @@ -707,7 +705,7 @@ func fundPsbt(ctx *cli.Context) error { default: return fmt.Errorf("must specify either template_psbt or " + - "outputs flag") + "inputs/outputs flag") } // Parse fee flags. diff --git a/docs/release-notes/release-notes-0.14.0.md b/docs/release-notes/release-notes-0.14.0.md index 80bb14238..968513a16 100644 --- a/docs/release-notes/release-notes-0.14.0.md +++ b/docs/release-notes/release-notes-0.14.0.md @@ -25,6 +25,12 @@ for more information. * [Stub code for interacting with `lnrpc` from a WASM context through JSON messages was added](https://github.com/lightningnetwork/lnd/pull/5601). +## Wallet + +* It is now possible to fund a psbt [without specifying any + outputs](https://github.com/lightningnetwork/lnd/pull/5442). This option is + useful for CPFP bumping of unconfirmed outputs or general utxo consolidation. + ## Security ### Admin macaroon permissions diff --git a/lnrpc/walletrpc/walletkit_server.go b/lnrpc/walletrpc/walletkit_server.go index 28f502f6b..93b698351 100644 --- a/lnrpc/walletrpc/walletkit_server.go +++ b/lnrpc/walletrpc/walletkit_server.go @@ -996,9 +996,6 @@ func (w *WalletKit) FundPsbt(_ context.Context, // PSBT and copy the RPC information over. case req.GetRaw() != nil: tpl := req.GetRaw() - if len(tpl.Outputs) == 0 { - return nil, fmt.Errorf("no outputs specified") - } txOut := make([]*wire.TxOut, 0, len(tpl.Outputs)) for addrStr, amt := range tpl.Outputs {