Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/server.cpp
Show First 20 Lines • Show All 181 Lines • ▼ Show 20 Lines | Amount AmountFromValue(const UniValue &value) { | ||||
if (!MoneyRange(amt)) { | if (!MoneyRange(amt)) { | ||||
throw JSONRPCError(RPC_TYPE_ERROR, "Amount out of range"); | throw JSONRPCError(RPC_TYPE_ERROR, "Amount out of range"); | ||||
} | } | ||||
return amt; | return amt; | ||||
} | } | ||||
uint256 ParseHashV(const UniValue &v, std::string strName) { | uint256 ParseHashV(const UniValue &v, std::string strName) { | ||||
std::string strHex; | std::string strHex(v.get_str()); | ||||
if (v.isStr()) { | if (64 != strHex.length()) { | ||||
strHex = v.get_str(); | throw JSONRPCError( | ||||
RPC_INVALID_PARAMETER, | |||||
strprintf("%s must be of length %d (not %d, for '%s')", strName, 64, | |||||
strHex.length(), strHex)); | |||||
} | } | ||||
// Note: IsHex("") is false | // Note: IsHex("") is false | ||||
if (!IsHex(strHex)) { | if (!IsHex(strHex)) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
strName + " must be hexadecimal string (not '" + | strName + " must be hexadecimal string (not '" + | ||||
strHex + "')"); | strHex + "')"); | ||||
} | } | ||||
return uint256S(strHex); | |||||
if (strHex.length() != 64) { | |||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | |||||
strprintf("%s must be of length %d (not %d)", | |||||
strName, 64, strHex.length())); | |||||
} | |||||
uint256 result; | |||||
result.SetHex(strHex); | |||||
return result; | |||||
} | } | ||||
uint256 ParseHashO(const UniValue &o, std::string strKey) { | uint256 ParseHashO(const UniValue &o, std::string strKey) { | ||||
return ParseHashV(find_value(o, strKey), strKey); | return ParseHashV(find_value(o, strKey), strKey); | ||||
} | } | ||||
std::vector<uint8_t> ParseHexV(const UniValue &v, std::string strName) { | std::vector<uint8_t> ParseHexV(const UniValue &v, std::string strName) { | ||||
std::string strHex; | std::string strHex; | ||||
if (v.isStr()) { | if (v.isStr()) { | ||||
strHex = v.get_str(); | strHex = v.get_str(); | ||||
▲ Show 20 Lines • Show All 426 Lines • Show Last 20 Lines |