mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-17 13:07:54 +02: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:
parent
c6c3d42a7d
commit
bd0dbe8763
10 changed files with 159 additions and 24 deletions
|
|
@ -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} {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue