mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
rpc: refactor: use string_view in Arg/MaybeArg
Modernizes interface by not forcing users to deal with raw pointers, without adding copying overhead. Generalizes the logic of whether we return by value or by optional/pointer. In cases where functions take a `const std::string&` and it would be too much work to update them, a string copy is made (which was already happening anyway).
This commit is contained in:
@@ -181,7 +181,7 @@ static UniValue generateBlocks(ChainstateManager& chainman, Mining& miner, const
|
||||
return blockHashes;
|
||||
}
|
||||
|
||||
static bool getScriptFromDescriptor(const std::string& descriptor, CScript& script, std::string& error)
|
||||
static bool getScriptFromDescriptor(std::string_view descriptor, CScript& script, std::string& error)
|
||||
{
|
||||
FlatSigningProvider key_provider;
|
||||
const auto descs = Parse(descriptor, key_provider, error, /* require_checksum = */ false);
|
||||
@@ -241,7 +241,7 @@ static RPCHelpMan generatetodescriptor()
|
||||
|
||||
CScript coinbase_output_script;
|
||||
std::string error;
|
||||
if (!getScriptFromDescriptor(self.Arg<std::string>("descriptor"), coinbase_output_script, error)) {
|
||||
if (!getScriptFromDescriptor(self.Arg<std::string_view>("descriptor"), coinbase_output_script, error)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, error);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user