mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 15:19:07 +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:
@@ -2735,13 +2735,12 @@ bool CheckChecksum(std::span<const char>& sp, bool require_checksum, std::string
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<Descriptor>> Parse(const std::string& descriptor, FlatSigningProvider& out, std::string& error, bool require_checksum)
|
||||
std::vector<std::unique_ptr<Descriptor>> Parse(std::span<const char> descriptor, FlatSigningProvider& out, std::string& error, bool require_checksum)
|
||||
{
|
||||
std::span<const char> sp{descriptor};
|
||||
if (!CheckChecksum(sp, require_checksum, error)) return {};
|
||||
if (!CheckChecksum(descriptor, require_checksum, error)) return {};
|
||||
uint32_t key_exp_index = 0;
|
||||
auto ret = ParseScript(key_exp_index, sp, ParseScriptContext::TOP, out, error);
|
||||
if (sp.size() == 0 && !ret.empty()) {
|
||||
auto ret = ParseScript(key_exp_index, descriptor, ParseScriptContext::TOP, out, error);
|
||||
if (descriptor.empty() && !ret.empty()) {
|
||||
std::vector<std::unique_ptr<Descriptor>> descs;
|
||||
descs.reserve(ret.size());
|
||||
for (auto& r : ret) {
|
||||
|
||||
@@ -175,7 +175,7 @@ struct Descriptor {
|
||||
* If a parse error occurs, or the checksum is missing/invalid, or anything
|
||||
* else is wrong, an empty vector is returned.
|
||||
*/
|
||||
std::vector<std::unique_ptr<Descriptor>> Parse(const std::string& descriptor, FlatSigningProvider& out, std::string& error, bool require_checksum = false);
|
||||
std::vector<std::unique_ptr<Descriptor>> Parse(std::span<const char> descriptor, FlatSigningProvider& out, std::string& error, bool require_checksum = false);
|
||||
|
||||
/** Get the checksum for a `descriptor`.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user