From 9f1d73d6d30e3ff5e5e6854493244f69ff2d99d4 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Mon, 28 Jun 2021 12:05:54 +0200 Subject: [PATCH] wallet: allow zero output psbt funding To support the cpfp fee bump use case where no external outputs are required. --- wallet/psbt.go | 9 +++++++-- wallet/psbt_test.go | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/wallet/psbt.go b/wallet/psbt.go index 603e1fe..4088a90 100644 --- a/wallet/psbt.go +++ b/wallet/psbt.go @@ -45,12 +45,17 @@ func (w *Wallet) FundPsbt(packet *psbt.Packet, keyScope *waddrmgr.KeyScope, coinSelectionStrategy CoinSelectionStrategy) (int32, error) { // Make sure the packet is well formed. We only require there to be at - // least one output but not necessarily any inputs. - err := psbt.VerifyInputOutputLen(packet, false, true) + // least one input or output. + err := psbt.VerifyInputOutputLen(packet, false, false) if err != nil { return 0, err } + if len(packet.UnsignedTx.TxIn) == 0 && len(packet.UnsignedTx.TxOut) == 0 { + return 0, fmt.Errorf("PSBT packet must contain at least one " + + "input or output") + } + txOut := packet.UnsignedTx.TxOut txIn := packet.UnsignedTx.TxIn diff --git a/wallet/psbt_test.go b/wallet/psbt_test.go index 0df18da..216714c 100644 --- a/wallet/psbt_test.go +++ b/wallet/psbt_test.go @@ -89,7 +89,22 @@ func TestFundPsbt(t *testing.T) { UnsignedTx: &wire.MsgTx{}, }, feeRateSatPerKB: 0, - expectedErr: "must contain at least one output", + expectedErr: "PSBT packet must contain at least one input or output", + }, { + name: "single input, no outputs", + packet: &psbt.Packet{ + UnsignedTx: &wire.MsgTx{ + TxIn: []*wire.TxIn{{ + PreviousOutPoint: utxo1, + }}, + }, + Inputs: []psbt.PInput{{}}, + }, + feeRateSatPerKB: 20000, + validatePackage: true, + expectedInputs: []wire.OutPoint{utxo1}, + expectedFee: 2200, + expectedChange: 997800, }, { name: "no dust outputs", packet: &psbt.Packet{