diff --git a/doc/release-notes-28113.md b/doc/release-notes-28113.md new file mode 100644 index 0000000000..c1a3a07b17 --- /dev/null +++ b/doc/release-notes-28113.md @@ -0,0 +1,7 @@ +RPC Wallet +---------- + +- The `signrawtransactionwithkey`, `signrawtransactionwithwallet`, + `walletprocesspsbt` and `descriptorprocesspsbt` calls now return more + specific RPC_INVALID_PARAMETER instead of RPC_PARSE_ERROR if their + sighashtype argument is malformed or not a string. diff --git a/src/core_io.h b/src/core_io.h index 997f3bfd5b..a8c62da3f3 100644 --- a/src/core_io.h +++ b/src/core_io.h @@ -6,6 +6,7 @@ #define BITCOIN_CORE_IO_H #include +#include #include #include @@ -46,7 +47,7 @@ bool DecodeHexBlockHeader(CBlockHeader&, const std::string& hex_header); */ bool ParseHashStr(const std::string& strHex, uint256& result); std::vector ParseHexUV(const UniValue& v, const std::string& strName); -int ParseSighashString(const UniValue& sighash); +[[nodiscard]] util::Result SighashFromStr(const std::string& sighash); // core_write.cpp UniValue ValueFromAmount(const CAmount amount); diff --git a/src/core_read.cpp b/src/core_read.cpp index 84cd559b7f..c40f04a824 100644 --- a/src/core_read.cpp +++ b/src/core_read.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -252,26 +253,21 @@ std::vector ParseHexUV(const UniValue& v, const std::string& strN return ParseHex(strHex); } -int ParseSighashString(const UniValue& sighash) +util::Result SighashFromStr(const std::string& sighash) { - int hash_type = SIGHASH_DEFAULT; - if (!sighash.isNull()) { - static std::map map_sighash_values = { - {std::string("DEFAULT"), int(SIGHASH_DEFAULT)}, - {std::string("ALL"), int(SIGHASH_ALL)}, - {std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)}, - {std::string("NONE"), int(SIGHASH_NONE)}, - {std::string("NONE|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY)}, - {std::string("SINGLE"), int(SIGHASH_SINGLE)}, - {std::string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY)}, - }; - const std::string& strHashType = sighash.get_str(); - const auto& it = map_sighash_values.find(strHashType); - if (it != map_sighash_values.end()) { - hash_type = it->second; - } else { - throw std::runtime_error(strHashType + " is not a valid sighash parameter."); - } + static std::map map_sighash_values = { + {std::string("DEFAULT"), int(SIGHASH_DEFAULT)}, + {std::string("ALL"), int(SIGHASH_ALL)}, + {std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)}, + {std::string("NONE"), int(SIGHASH_NONE)}, + {std::string("NONE|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY)}, + {std::string("SINGLE"), int(SIGHASH_SINGLE)}, + {std::string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY)}, + }; + const auto& it = map_sighash_values.find(sighash); + if (it != map_sighash_values.end()) { + return it->second; + } else { + return util::Error{Untranslated(sighash + " is not a valid sighash parameter.")}; } - return hash_type; } diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 19e14f88df..377181dd81 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -3,8 +3,10 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include +#include