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:
Ben Woosley
2018-09-24 10:59:17 -04:00
parent 990fc0de1a
commit 9c5af58d51
6 changed files with 87 additions and 22 deletions

View File

@@ -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)