diff options
Diffstat (limited to 'src/rpc')
-rw-r--r-- | src/rpc/blockchain.cpp | 4 | ||||
-rw-r--r-- | src/rpc/client.cpp | 31 | ||||
-rw-r--r-- | src/rpc/client.h | 5 |
3 files changed, 24 insertions, 16 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 28a619fe54..9459801c2c 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -2106,6 +2106,10 @@ static RPCHelpMan scantxoutset() " combo(<pubkey>) P2PK, P2PKH, P2WPKH, and P2SH-P2WPKH outputs for the given pubkey\n" " pkh(<pubkey>) P2PKH outputs for the given pubkey\n" " sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for the given threshold and pubkeys\n" + " tr(<pubkey>) P2TR\n" + " tr(<pubkey>,{pk(<pubkey>)}) P2TR with single fallback pubkey in tapscript\n" + " rawtr(<pubkey>) P2TR with the specified key as output key rather than inner\n" + " wsh(and_v(v:pk(<pubkey>),after(2))) P2WSH miniscript with mandatory pubkey and a timelock\n" "\nIn the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one\n" "or more path elements separated by \"/\", and optionally ending in \"/*\" (unhardened), or \"/*'\" or \"/*h\" (hardened) to specify all\n" "unhardened or hardened child keys.\n" diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index eb91a151b5..9449b9d197 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -4,10 +4,13 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <rpc/client.h> +#include <tinyformat.h> #include <util/system.h> #include <set> #include <stdint.h> +#include <string> +#include <string_view> class CRPCConvertParam { @@ -229,15 +232,15 @@ public: CRPCConvertTable(); /** Return arg_value as UniValue, and first parse it if it is a non-string parameter */ - UniValue ArgToUniValue(const std::string& arg_value, const std::string& method, int param_idx) + UniValue ArgToUniValue(std::string_view arg_value, const std::string& method, int param_idx) { - return members.count(std::make_pair(method, param_idx)) > 0 ? ParseNonRFCJSONValue(arg_value) : arg_value; + return members.count({method, param_idx}) > 0 ? ParseNonRFCJSONValue(arg_value) : arg_value; } /** Return arg_value as UniValue, and first parse it if it is a non-string parameter */ - UniValue ArgToUniValue(const std::string& arg_value, const std::string& method, const std::string& param_name) + UniValue ArgToUniValue(std::string_view arg_value, const std::string& method, const std::string& param_name) { - return membersByName.count(std::make_pair(method, param_name)) > 0 ? ParseNonRFCJSONValue(arg_value) : arg_value; + return membersByName.count({method, param_name}) > 0 ? ParseNonRFCJSONValue(arg_value) : arg_value; } }; @@ -254,13 +257,11 @@ static CRPCConvertTable rpcCvtTable; /** Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, false, null) * as well as objects and arrays. */ -UniValue ParseNonRFCJSONValue(const std::string& strVal) +UniValue ParseNonRFCJSONValue(std::string_view raw) { - UniValue jVal; - if (!jVal.read(std::string("[")+strVal+std::string("]")) || - !jVal.isArray() || jVal.size()!=1) - throw std::runtime_error(std::string("Error parsing JSON: ") + strVal); - return jVal[0]; + UniValue parsed; + if (!parsed.read(raw)) throw std::runtime_error(tfm::format("Error parsing JSON: %s", raw)); + return parsed; } UniValue RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams) @@ -268,8 +269,8 @@ UniValue RPCConvertValues(const std::string &strMethod, const std::vector<std::s UniValue params(UniValue::VARR); for (unsigned int idx = 0; idx < strParams.size(); idx++) { - const std::string& strVal = strParams[idx]; - params.push_back(rpcCvtTable.ArgToUniValue(strVal, strMethod, idx)); + std::string_view value{strParams[idx]}; + params.push_back(rpcCvtTable.ArgToUniValue(value, strMethod, idx)); } return params; @@ -280,15 +281,15 @@ UniValue RPCConvertNamedValues(const std::string &strMethod, const std::vector<s UniValue params(UniValue::VOBJ); UniValue positional_args{UniValue::VARR}; - for (const std::string &s: strParams) { + for (std::string_view s: strParams) { size_t pos = s.find('='); if (pos == std::string::npos) { positional_args.push_back(rpcCvtTable.ArgToUniValue(s, strMethod, positional_args.size())); continue; } - std::string name = s.substr(0, pos); - std::string value = s.substr(pos+1); + std::string name{s.substr(0, pos)}; + std::string_view value{s.substr(pos+1)}; // Intentionally overwrite earlier named values with later ones as a // convenience for scripts and command line users that want to merge diff --git a/src/rpc/client.h b/src/rpc/client.h index b9fee5bbb3..3c5c4fc4d6 100644 --- a/src/rpc/client.h +++ b/src/rpc/client.h @@ -6,6 +6,9 @@ #ifndef BITCOIN_RPC_CLIENT_H #define BITCOIN_RPC_CLIENT_H +#include <string> +#include <string_view> + #include <univalue.h> /** Convert positional arguments to command-specific RPC representation */ @@ -17,6 +20,6 @@ UniValue RPCConvertNamedValues(const std::string& strMethod, const std::vector<s /** Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, false, null) * as well as objects and arrays. */ -UniValue ParseNonRFCJSONValue(const std::string& strVal); +UniValue ParseNonRFCJSONValue(std::string_view raw); #endif // BITCOIN_RPC_CLIENT_H |