mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
Consolidate redundant implementations of ParseHashStr
This change: * adds a length check to ParseHashStr, appropriate given its use to populate a 256-bit number from a hex str. * allows the caller to handle the failure, which allows for the more appropriate JSONRPCError on failure in prioritisetransaction rpc
This commit is contained in:
@@ -193,14 +193,13 @@ bool DecodePSBT(PartiallySignedTransaction& psbt, const std::string& base64_tx,
|
||||
return true;
|
||||
}
|
||||
|
||||
uint256 ParseHashStr(const std::string& strHex, const std::string& strName)
|
||||
bool ParseHashStr(const std::string& strHex, uint256& result)
|
||||
{
|
||||
if (!IsHex(strHex)) // Note: IsHex("") is false
|
||||
throw std::runtime_error(strName + " must be hexadecimal string (not '" + strHex + "')");
|
||||
if ((strHex.size() != 64) || !IsHex(strHex))
|
||||
return false;
|
||||
|
||||
uint256 result;
|
||||
result.SetHex(strHex);
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> ParseHexUV(const UniValue& v, const std::string& strName)
|
||||
|
||||
Reference in New Issue
Block a user