Merge pull request #753 from joostjager/zero-output-psbt
wallet: allow zero output psbt funding
This commit is contained in:
commit
8e18674563
2 changed files with 23 additions and 3 deletions
|
@ -45,12 +45,17 @@ func (w *Wallet) FundPsbt(packet *psbt.Packet, keyScope *waddrmgr.KeyScope,
|
||||||
coinSelectionStrategy CoinSelectionStrategy) (int32, error) {
|
coinSelectionStrategy CoinSelectionStrategy) (int32, error) {
|
||||||
|
|
||||||
// Make sure the packet is well formed. We only require there to be at
|
// Make sure the packet is well formed. We only require there to be at
|
||||||
// least one output but not necessarily any inputs.
|
// least one input or output.
|
||||||
err := psbt.VerifyInputOutputLen(packet, false, true)
|
err := psbt.VerifyInputOutputLen(packet, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
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
|
txOut := packet.UnsignedTx.TxOut
|
||||||
txIn := packet.UnsignedTx.TxIn
|
txIn := packet.UnsignedTx.TxIn
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,22 @@ func TestFundPsbt(t *testing.T) {
|
||||||
UnsignedTx: &wire.MsgTx{},
|
UnsignedTx: &wire.MsgTx{},
|
||||||
},
|
},
|
||||||
feeRateSatPerKB: 0,
|
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",
|
name: "no dust outputs",
|
||||||
packet: &psbt.Packet{
|
packet: &psbt.Packet{
|
||||||
|
|
Loading…
Reference in a new issue