diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index 5fbc740608..a1ef23ea1a 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -939,7 +939,7 @@ std::unique_ptr ParsePubkey(uint32_t key_exp_index, const Span ParseScript(uint32_t key_exp_index, Span& sp, ParseScriptContext ctx, FlatSigningProvider& out, std::string& error) +std::unique_ptr ParseScript(uint32_t& key_exp_index, Span& sp, ParseScriptContext ctx, FlatSigningProvider& out, std::string& error) { using namespace spanparsing; @@ -948,16 +948,19 @@ std::unique_ptr ParseScript(uint32_t key_exp_index, Span(std::move(pubkey)); } if (Func("pkh", expr)) { auto pubkey = ParsePubkey(key_exp_index, expr, ctx != ParseScriptContext::P2WSH, out, error); if (!pubkey) return nullptr; + ++key_exp_index; return std::make_unique(std::move(pubkey)); } if (ctx == ParseScriptContext::TOP && Func("combo", expr)) { auto pubkey = ParsePubkey(key_exp_index, expr, true, out, error); if (!pubkey) return nullptr; + ++key_exp_index; return std::make_unique(std::move(pubkey)); } else if (ctx != ParseScriptContext::TOP && Func("combo", expr)) { error = "Cannot have combo in non-top level"; @@ -1011,6 +1014,7 @@ std::unique_ptr ParseScript(uint32_t key_exp_index, Span(std::move(pubkey)); } else if (ctx == ParseScriptContext::P2WSH && Func("wpkh", expr)) { error = "Cannot have wpkh within wsh"; @@ -1177,7 +1181,8 @@ std::unique_ptr Parse(const std::string& descriptor, FlatSigningProv { Span sp{descriptor}; if (!CheckChecksum(sp, require_checksum, error)) return nullptr; - auto ret = ParseScript(0, sp, ParseScriptContext::TOP, out, error); + uint32_t key_exp_index = 0; + auto ret = ParseScript(key_exp_index, sp, ParseScriptContext::TOP, out, error); if (sp.size() == 0 && ret) return std::unique_ptr(std::move(ret)); return nullptr; }