mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Switch away from exceptions in refactored tx code
After refactoring general-purpose PSBT and transaction code out of RPC code, for use in the GUI, it's no longer appropriate to throw exceptions. Instead we now return bools for success, and take an output parameter for an error object. We still use JSONRPCError() for the error objects, since only RPC callers actually care about the error codes.
This commit is contained in:
@@ -141,6 +141,32 @@ unsigned int ParseConfirmTarget(const UniValue& value)
|
||||
return (unsigned int)target;
|
||||
}
|
||||
|
||||
RPCErrorCode RPCErrorFromTransactionError(TransactionError terr)
|
||||
{
|
||||
switch (terr) {
|
||||
case TransactionError::MEMPOOL_REJECTED:
|
||||
return RPC_TRANSACTION_REJECTED;
|
||||
case TransactionError::ALREADY_IN_CHAIN:
|
||||
return RPC_TRANSACTION_ALREADY_IN_CHAIN;
|
||||
case TransactionError::P2P_DISABLED:
|
||||
return RPC_CLIENT_P2P_DISABLED;
|
||||
case TransactionError::INVALID_PSBT:
|
||||
case TransactionError::SIGHASH_MISMATCH:
|
||||
return RPC_DESERIALIZATION_ERROR;
|
||||
default: break;
|
||||
}
|
||||
return RPC_TRANSACTION_ERROR;
|
||||
}
|
||||
|
||||
UniValue JSONRPCTransactionError(TransactionError terr, const std::string& err_string)
|
||||
{
|
||||
if (err_string.length() > 0) {
|
||||
return JSONRPCError(RPCErrorFromTransactionError(terr), err_string);
|
||||
} else {
|
||||
return JSONRPCError(RPCErrorFromTransactionError(terr), TransactionErrorString(terr));
|
||||
}
|
||||
}
|
||||
|
||||
struct Section {
|
||||
Section(const std::string& left, const std::string& right)
|
||||
: m_left{left}, m_right{right} {}
|
||||
|
||||
Reference in New Issue
Block a user