Move Parse{Hash|Hex} to be usable by all RPC code
This commit is contained in:
@@ -113,6 +113,34 @@ std::string HexBits(unsigned int nBits)
|
||||
return HexStr(BEGIN(uBits.cBits), END(uBits.cBits));
|
||||
}
|
||||
|
||||
uint256 ParseHashV(const Value& v, string strName)
|
||||
{
|
||||
string strHex;
|
||||
if (v.type() == str_type)
|
||||
strHex = v.get_str();
|
||||
if (!IsHex(strHex)) // Note: IsHex("") is false
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be hexadecimal string (not '"+strHex+"')");
|
||||
uint256 result;
|
||||
result.SetHex(strHex);
|
||||
return result;
|
||||
}
|
||||
uint256 ParseHashO(const Object& o, string strKey)
|
||||
{
|
||||
return ParseHashV(find_value(o, strKey), strKey);
|
||||
}
|
||||
vector<unsigned char> ParseHexV(const Value& v, string strName)
|
||||
{
|
||||
string strHex;
|
||||
if (v.type() == str_type)
|
||||
strHex = v.get_str();
|
||||
if (!IsHex(strHex))
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be hexadecimal string (not '"+strHex+"')");
|
||||
return ParseHex(strHex);
|
||||
}
|
||||
vector<unsigned char> ParseHexO(const Object& o, string strKey)
|
||||
{
|
||||
return ParseHexV(find_value(o, strKey), strKey);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user