walletrpc: return an error when finalizing an already complete PSBT

Return an error to the client if attempting to finalize a PSBS with no missing signatures.
This commit is contained in:
Liviu 2022-01-30 21:37:32 -08:00
parent 9e0f7e73db
commit e11c41ba8f

View File

@ -1254,8 +1254,7 @@ func (w *WalletKit) FinalizePsbt(_ context.Context,
account = req.Account
}
// Parse the funded PSBT. No additional checks are required at this
// level as the wallet will perform all of them.
// Parse the funded PSBT.
packet, err := psbt.NewFromRawBytes(
bytes.NewReader(req.FundedPsbt), false,
)
@ -1263,6 +1262,12 @@ func (w *WalletKit) FinalizePsbt(_ context.Context,
return nil, fmt.Errorf("error parsing PSBT: %v", err)
}
// The only check done at this level is to validate that the PSBT is
// not complete. The wallet performs all other checks.
if packet.IsComplete() {
return nil, fmt.Errorf("PSBT is already fully signed")
}
// Let the wallet do the heavy lifting. This will sign all inputs that
// we have the UTXO for. If some inputs can't be signed and don't have
// witness data attached, this will fail.