44
55#include < psbt.h>
66
7+ #include < common/types.h>
78#include < node/types.h>
89#include < policy/policy.h>
910#include < script/signingprovider.h>
1011#include < util/check.h>
1112#include < util/strencodings.h>
1213
14+ using common::PSBTError;
15+
1316PartiallySignedTransaction::PartiallySignedTransaction (const CMutableTransaction& tx) : tx(tx)
1417{
1518 inputs.resize (tx.vin .size ());
@@ -372,13 +375,13 @@ PrecomputedTransactionData PrecomputePSBTData(const PartiallySignedTransaction&
372375 return txdata;
373376}
374377
375- bool SignPSBTInput (const SigningProvider& provider, PartiallySignedTransaction& psbt, int index, const PrecomputedTransactionData* txdata, int sighash, SignatureData* out_sigdata, bool finalize)
378+ PSBTError SignPSBTInput (const SigningProvider& provider, PartiallySignedTransaction& psbt, int index, const PrecomputedTransactionData* txdata, int sighash, SignatureData* out_sigdata, bool finalize)
376379{
377380 PSBTInput& input = psbt.inputs .at (index);
378381 const CMutableTransaction& tx = *psbt.tx ;
379382
380383 if (PSBTInputSignedAndVerified (psbt, index, txdata)) {
381- return true ;
384+ return PSBTError::OK ;
382385 }
383386
384387 // Fill SignatureData with input info
@@ -393,10 +396,10 @@ bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction&
393396 // If we're taking our information from a non-witness UTXO, verify that it matches the prevout.
394397 COutPoint prevout = tx.vin [index].prevout ;
395398 if (prevout.n >= input.non_witness_utxo ->vout .size ()) {
396- return false ;
399+ return PSBTError::MISSING_INPUTS ;
397400 }
398401 if (input.non_witness_utxo ->GetHash () != prevout.hash ) {
399- return false ;
402+ return PSBTError::MISSING_INPUTS ;
400403 }
401404 utxo = input.non_witness_utxo ->vout [prevout.n ];
402405 } else if (!input.witness_utxo .IsNull ()) {
@@ -407,7 +410,7 @@ bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction&
407410 // a witness signature in this situation.
408411 require_witness_sig = true ;
409412 } else {
410- return false ;
413+ return PSBTError::MISSING_INPUTS ;
411414 }
412415
413416 sigdata.witness = false ;
@@ -419,7 +422,7 @@ bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction&
419422 sig_complete = ProduceSignature (provider, creator, utxo.scriptPubKey , sigdata);
420423 }
421424 // Verify that a witness signature was produced in case one was required.
422- if (require_witness_sig && !sigdata.witness ) return false ;
425+ if (require_witness_sig && !sigdata.witness ) return PSBTError::INCOMPLETE ;
423426
424427 // If we are not finalizing, set sigdata.complete to false to not set the scriptWitness
425428 if (!finalize && sigdata.complete ) sigdata.complete = false ;
@@ -442,7 +445,7 @@ bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction&
442445 out_sigdata->missing_witness_script = sigdata.missing_witness_script ;
443446 }
444447
445- return sig_complete;
448+ return sig_complete ? PSBTError::OK : PSBTError::INCOMPLETE ;
446449}
447450
448451void RemoveUnnecessaryTransactions (PartiallySignedTransaction& psbtx, const int & sighash_type)
@@ -486,7 +489,7 @@ bool FinalizePSBT(PartiallySignedTransaction& psbtx)
486489 bool complete = true ;
487490 const PrecomputedTransactionData txdata = PrecomputePSBTData (psbtx);
488491 for (unsigned int i = 0 ; i < psbtx.tx ->vin .size (); ++i) {
489- complete &= SignPSBTInput (DUMMY_SIGNING_PROVIDER, psbtx, i, &txdata, SIGHASH_ALL, nullptr , true );
492+ complete &= ( SignPSBTInput (DUMMY_SIGNING_PROVIDER, psbtx, i, &txdata, SIGHASH_ALL, nullptr , true ) == PSBTError::OK );
490493 }
491494
492495 return complete;
0 commit comments