Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/util.cpp
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | if (fStrict) { | ||||
if (typesExpected.count(k) == 0) { | if (typesExpected.count(k) == 0) { | ||||
std::string err = strprintf("Unexpected key %s", k); | std::string err = strprintf("Unexpected key %s", k); | ||||
throw JSONRPCError(RPC_TYPE_ERROR, err); | throw JSONRPCError(RPC_TYPE_ERROR, err); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
Amount AmountFromValue(const UniValue &value) { | |||||
if (!value.isNum() && !value.isStr()) { | |||||
throw JSONRPCError(RPC_TYPE_ERROR, "Amount is not a number or string"); | |||||
} | |||||
int64_t n; | |||||
if (!ParseFixedPoint(value.getValStr(), 8, &n)) { | |||||
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount"); | |||||
} | |||||
Amount amt = n * SATOSHI; | |||||
if (!MoneyRange(amt)) { | |||||
throw JSONRPCError(RPC_TYPE_ERROR, "Amount out of range"); | |||||
} | |||||
return amt; | |||||
} | |||||
uint256 ParseHashV(const UniValue &v, std::string strName) { | uint256 ParseHashV(const UniValue &v, std::string strName) { | ||||
std::string strHex(v.get_str()); | std::string strHex(v.get_str()); | ||||
if (64 != strHex.length()) { | if (64 != strHex.length()) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_INVALID_PARAMETER, | RPC_INVALID_PARAMETER, | ||||
strprintf("%s must be of length %d (not %d, for '%s')", strName, 64, | strprintf("%s must be of length %d (not %d, for '%s')", strName, 64, | ||||
strHex.length(), strHex)); | strHex.length(), strHex)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 798 Lines • Show Last 20 Lines |