aboutsummaryrefslogtreecommitdiff
path: root/src/util/error.cpp
diff options
context:
space:
mode:
authorRyan Ofsky <ryan@ofsky.org>2023-12-13 11:43:16 -0500
committerRyan Ofsky <ryan@ofsky.org>2024-05-16 10:16:08 -0500
commit02e62c6c9af4beabaeea58fb1ea3ad0dc5094678 (patch)
tree3ddfb29afa69039b8d2444d3d2cd2e069e823aee /src/util/error.cpp
parent0d44c44ae33434f366229c612d6edeedf7658963 (diff)
downloadbitcoin-02e62c6c9af4beabaeea58fb1ea3ad0dc5094678.tar.xz
common: Add PSBTError enum
Add separate PSBTError enum instead of reusing TransactionError enum for PSBT operations, and drop unused error codes. The error codes returned by PSBT operations and transaction broadcast functions mostly do not overlap, so using an unified enum makes it harder to call any of these functions and know which errors actually need to be handled. Define PSBTError in the common library because PSBT functionality is implemented in the common library and used by both the node (for rawtransaction RPCs) and the wallet.
Diffstat (limited to 'src/util/error.cpp')
-rw-r--r--src/util/error.cpp33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/util/error.cpp b/src/util/error.cpp
index 309877d067..9d506ee25c 100644
--- a/src/util/error.cpp
+++ b/src/util/error.cpp
@@ -4,12 +4,33 @@
#include <util/error.h>
+#include <common/types.h>
#include <tinyformat.h>
#include <util/translation.h>
#include <cassert>
#include <string>
+using common::PSBTError;
+
+bilingual_str PSBTErrorString(PSBTError err)
+{
+ switch (err) {
+ case PSBTError::MISSING_INPUTS:
+ return Untranslated("Inputs missing or spent");
+ case PSBTError::SIGHASH_MISMATCH:
+ return Untranslated("Specified sighash value does not match value stored in PSBT");
+ case PSBTError::EXTERNAL_SIGNER_NOT_FOUND:
+ return Untranslated("External signer not found");
+ case PSBTError::EXTERNAL_SIGNER_FAILED:
+ return Untranslated("External signer failed to sign");
+ case PSBTError::UNSUPPORTED:
+ return Untranslated("Signer does not support PSBT");
+ // no default case, so the compiler can warn about missing cases
+ }
+ assert(false);
+}
+
bilingual_str TransactionErrorString(const TransactionError err)
{
switch (err) {
@@ -19,26 +40,14 @@ bilingual_str TransactionErrorString(const TransactionError err)
return Untranslated("Inputs missing or spent");
case TransactionError::ALREADY_IN_CHAIN:
return Untranslated("Transaction already in block chain");
- case TransactionError::P2P_DISABLED:
- return Untranslated("Peer-to-peer functionality missing or disabled");
case TransactionError::MEMPOOL_REJECTED:
return Untranslated("Transaction rejected by mempool");
case TransactionError::MEMPOOL_ERROR:
return Untranslated("Mempool internal error");
- case TransactionError::INVALID_PSBT:
- return Untranslated("PSBT is not well-formed");
- case TransactionError::PSBT_MISMATCH:
- return Untranslated("PSBTs not compatible (different transactions)");
- case TransactionError::SIGHASH_MISMATCH:
- return Untranslated("Specified sighash value does not match value stored in PSBT");
case TransactionError::MAX_FEE_EXCEEDED:
return Untranslated("Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)");
case TransactionError::MAX_BURN_EXCEEDED:
return Untranslated("Unspendable output exceeds maximum configured by user (maxburnamount)");
- case TransactionError::EXTERNAL_SIGNER_NOT_FOUND:
- return Untranslated("External signer not found");
- case TransactionError::EXTERNAL_SIGNER_FAILED:
- return Untranslated("External signer failed to sign");
case TransactionError::INVALID_PACKAGE:
return Untranslated("Transaction rejected due to invalid package");
// no default case, so the compiler can warn about missing cases