|
20 | 20 | #include <util/string.h>
|
21 | 21 | #include <util/translation.h>
|
22 | 22 |
|
| 23 | +#include <string_view> |
23 | 24 | #include <tuple>
|
24 | 25 |
|
25 | 26 | const std::string UNIX_EPOCH_TIME = "UNIX epoch time";
|
@@ -74,29 +75,29 @@ CAmount AmountFromValue(const UniValue& value, int decimals)
|
74 | 75 | return amount;
|
75 | 76 | }
|
76 | 77 |
|
77 |
| -uint256 ParseHashV(const UniValue& v, std::string strName) |
| 78 | +uint256 ParseHashV(const UniValue& v, std::string_view name) |
78 | 79 | {
|
79 | 80 | const std::string& strHex(v.get_str());
|
80 | 81 | if (64 != strHex.length())
|
81 |
| - throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s must be of length %d (not %d, for '%s')", strName, 64, strHex.length(), strHex)); |
| 82 | + throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s must be of length %d (not %d, for '%s')", name, 64, strHex.length(), strHex)); |
82 | 83 | if (!IsHex(strHex)) // Note: IsHex("") is false
|
83 |
| - throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be hexadecimal string (not '"+strHex+"')"); |
| 84 | + throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s must be hexadecimal string (not '%s')", name, strHex)); |
84 | 85 | return uint256S(strHex);
|
85 | 86 | }
|
86 |
| -uint256 ParseHashO(const UniValue& o, std::string strKey) |
| 87 | +uint256 ParseHashO(const UniValue& o, std::string_view strKey) |
87 | 88 | {
|
88 | 89 | return ParseHashV(o.find_value(strKey), strKey);
|
89 | 90 | }
|
90 |
| -std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strName) |
| 91 | +std::vector<unsigned char> ParseHexV(const UniValue& v, std::string_view name) |
91 | 92 | {
|
92 | 93 | std::string strHex;
|
93 | 94 | if (v.isStr())
|
94 | 95 | strHex = v.get_str();
|
95 | 96 | if (!IsHex(strHex))
|
96 |
| - throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be hexadecimal string (not '"+strHex+"')"); |
| 97 | + throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s must be hexadecimal string (not '%s')", name, strHex)); |
97 | 98 | return ParseHex(strHex);
|
98 | 99 | }
|
99 |
| -std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey) |
| 100 | +std::vector<unsigned char> ParseHexO(const UniValue& o, std::string_view strKey) |
100 | 101 | {
|
101 | 102 | return ParseHexV(o.find_value(strKey), strKey);
|
102 | 103 | }
|
|
0 commit comments