In 4ba2d10: This function is only used within ParseKeyPath and after this change, it seems more like a wrapper for ParseKeyPathElem. Can consider making this a lambda and moving it inside ParseKeyPath.
diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp
index 6a5aafb0bd..b2013d7340 100644
--- a/src/script/descriptor.cpp
+++ b/src/script/descriptor.cpp
@@ -1751,18 +1751,6 @@ enum class ParseScriptContext {
MUSIG, //!< Inside musig() (implies P2TR, cannot have nested musig())
};
-std::optional<uint32_t> ParseKeyPathNum(std::span<const char> elem, bool& apostrophe, std::string& error, bool& has_hardened)
-{
- bool hardened = false;
- const auto index{ParseKeyPathElement(elem, hardened, error)};
- if (!index.has_value()) return std::nullopt;
- if (hardened) {
- has_hardened = true;
- apostrophe = elem.back() == '\'';
- }
- return *index | (hardened ? BIP32_HARDENED : BIP32_UNHARDENED);
-}
-
/**
* Parse a key path, being passed a split list of elements (the first element is ignored because it is always the key).
*
@@ -1776,6 +1764,17 @@ std::optional<uint32_t> ParseKeyPathNum(std::span<const char> elem, bool& apostr
**/
[[nodiscard]] bool ParseKeyPath(const std::vector<std::span<const char>>& split, std::vector<KeyPath>& out, bool& apostrophe, std::string& error, bool allow_multipath, bool& has_hardened)
{
+ auto parserWrapper = [&](std::span<const char> elem) -> std::optional<uint32_t> {
+ bool hardened = false;
+ const auto index{ParseKeyPathElement(elem, hardened, error)};
+ if (!index.has_value()) return std::nullopt;
+ if (hardened) {
+ has_hardened = true;
+ apostrophe = elem.back() == '\'';
+ }
+ return *index | (hardened ? BIP32_HARDENED : BIP32_UNHARDENED);
+ };
+
KeyPath path;
struct MultipathSubstitutes {
size_t placeholder_index;
@@ -1808,7 +1807,7 @@ std::optional<uint32_t> ParseKeyPathNum(std::span<const char> elem, bool& apostr
substitutes.emplace();
std::unordered_set<uint32_t> seen_substitutes;
for (const auto& num : nums) {
- const auto& op_num = ParseKeyPathNum(num, apostrophe, error, has_hardened);
+ const auto& op_num = parserWrapper(num);
if (!op_num) return false;
auto [_, inserted] = seen_substitutes.insert(*op_num);
if (!inserted) {
@@ -1821,7 +1820,7 @@ std::optional<uint32_t> ParseKeyPathNum(std::span<const char> elem, bool& apostr
path.emplace_back(); // Placeholder for multipath segment
substitutes->placeholder_index = path.size() - 1;
} else {
- const auto& op_num = ParseKeyPathNum(elem, apostrophe, error, has_hardened);
+ const auto& op_num = parserWrapper(elem);
if (!op_num) return false;
path.emplace_back(*op_num);
}