lnwallet: fix bug in SignPsbt with np2wkh addresses
Fixes #6626. If either of the two fields FinalScriptSig or FinalScriptWitness is set on an input of a PSBT then that results in most of the fields of that input not to be serialized in the packet anymore, since the input is considered to be complete. But because a signer isn't supposed to set any of the Final* fields, this was wrong from the beginning. Only the finalizer will set those fields.
This commit is contained in:
2 files changed
+13
-27
No files matched your search
@@ -205,10 +205,9 @@ func (i testInputType) decorateInput(t *testing.T, privKey *btcec.PrivateKey,
|
||||
}
|
||||
}
|
||||
|
||||
func (i testInputType) beforeFinalize(t *testing.T, packet *psbt.Packet) {
|
||||
func (i testInputType) finalize(t *testing.T, packet *psbt.Packet) {
|
||||
in := &packet.Inputs[0]
|
||||
sigBytes := in.PartialSigs[0].Signature
|
||||
pubKeyBytes := in.PartialSigs[0].PubKey
|
||||
|
||||
var witnessStack wire.TxWitness
|
||||
switch i {
|
||||
@@ -227,9 +226,12 @@ func (i testInputType) beforeFinalize(t *testing.T, packet *psbt.Packet) {
|
||||
witnessStack[2] = in.WitnessScript
|
||||
|
||||
default:
|
||||
witnessStack = make([][]byte, 2)
|
||||
witnessStack[0] = sigBytes
|
||||
witnessStack[1] = pubKeyBytes
|
||||
// The PSBT finalizer knows what to do if we're not using a
|
||||
// custom script.
|
||||
err := psbt.MaybeFinalizeAll(packet)
|
||||
require.NoError(t, err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
var err error
|
||||
@@ -321,7 +323,7 @@ func TestSignPsbt(t *testing.T) {
|
||||
|
||||
// If the witness stack needs to be assembled, give the caller
|
||||
// the option to do that now.
|
||||
tc.inputType.beforeFinalize(t, packet)
|
||||
tc.inputType.finalize(t, packet)
|
||||
|
||||
finalTx, err := psbt.Extract(packet)
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in new issue
Block a user