From e58b680923b10f0690de9dcd34f17fbb8d6de5eb Mon Sep 17 00:00:00 2001 From: Ava Chow Date: Wed, 8 Jan 2025 14:37:38 -0500 Subject: [PATCH] psbt: Return PSBTError from SignPSBTInput SignPSBTInput will need to report the specific things that caused an error to callers, so change it to return a PSBTError. Additionally some callers will now check the return value and report an error to the user. Currently, this should not change any behavior as the things that SignPBSTInput will error on are all first checked by its callers. --- src/common/messages.cpp | 4 ++++ src/common/types.h | 2 ++ src/node/psbt.cpp | 4 ++-- src/psbt.cpp | 19 +++++++++++-------- src/psbt.h | 5 ++++- src/rpc/rawtransaction.cpp | 3 ++- src/wallet/scriptpubkeyman.cpp | 5 ++++- 7 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/common/messages.cpp b/src/common/messages.cpp index 5fe3e9e4d86..fc0b4a8861f 100644 --- a/src/common/messages.cpp +++ b/src/common/messages.cpp @@ -116,6 +116,10 @@ bilingual_str PSBTErrorString(PSBTError err) return Untranslated("External signer failed to sign"); case PSBTError::UNSUPPORTED: return Untranslated("Signer does not support PSBT"); + case PSBTError::INCOMPLETE: + return Untranslated("Input needs additional signatures or other data"); + case PSBTError::OK: + return Untranslated("No errors"); // no default case, so the compiler can warn about missing cases } assert(false); diff --git a/src/common/types.h b/src/common/types.h index 0d9cb67ce94..fb9ee4bf31b 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -20,6 +20,8 @@ enum class PSBTError { EXTERNAL_SIGNER_NOT_FOUND, EXTERNAL_SIGNER_FAILED, UNSUPPORTED, + INCOMPLETE, + OK, }; } // namespace common diff --git a/src/node/psbt.cpp b/src/node/psbt.cpp index 51e252bffca..079c7e2d4e2 100644 --- a/src/node/psbt.cpp +++ b/src/node/psbt.cpp @@ -64,7 +64,7 @@ PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx) // Figure out what is missing SignatureData outdata; - bool complete = SignPSBTInput(DUMMY_SIGNING_PROVIDER, psbtx, i, &txdata, 1, &outdata); + bool complete = SignPSBTInput(DUMMY_SIGNING_PROVIDER, psbtx, i, &txdata, 1, &outdata) == PSBTError::OK; // Things are missing if (!complete) { @@ -124,7 +124,7 @@ PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx) PSBTInput& input = psbtx.inputs[i]; Coin newcoin; - if (!SignPSBTInput(DUMMY_SIGNING_PROVIDER, psbtx, i, nullptr, 1) || !psbtx.GetInputUTXO(newcoin.out, i)) { + if (SignPSBTInput(DUMMY_SIGNING_PROVIDER, psbtx, i, nullptr, 1) != PSBTError::OK || !psbtx.GetInputUTXO(newcoin.out, i)) { success = false; break; } else { diff --git a/src/psbt.cpp b/src/psbt.cpp index 9369cfc334d..c89066c1497 100644 --- a/src/psbt.cpp +++ b/src/psbt.cpp @@ -4,12 +4,15 @@ #include +#include #include #include #include