mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-14 19:02:43 +02:00
Account for key cache indices in subexpressions
This has no effect for now, as the only fragments with sub-script expressions (sh, wsh) only allow one, and don't have key expressions in them. A future Taproot descriptor will however violate both, and we want the keys in different sub-scripts to be assigned non-overlapping cache indices.
This commit is contained in:
parent
4441c6f3c0
commit
6ba5dda0c9
@ -939,7 +939,7 @@ std::unique_ptr<PubkeyProvider> ParsePubkey(uint32_t key_exp_index, const Span<c
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Parse a script in a particular context. */
|
/** Parse a script in a particular context. */
|
||||||
std::unique_ptr<DescriptorImpl> ParseScript(uint32_t key_exp_index, Span<const char>& sp, ParseScriptContext ctx, FlatSigningProvider& out, std::string& error)
|
std::unique_ptr<DescriptorImpl> ParseScript(uint32_t& key_exp_index, Span<const char>& sp, ParseScriptContext ctx, FlatSigningProvider& out, std::string& error)
|
||||||
{
|
{
|
||||||
using namespace spanparsing;
|
using namespace spanparsing;
|
||||||
|
|
||||||
@ -948,16 +948,19 @@ std::unique_ptr<DescriptorImpl> ParseScript(uint32_t key_exp_index, Span<const c
|
|||||||
if (Func("pk", expr)) {
|
if (Func("pk", expr)) {
|
||||||
auto pubkey = ParsePubkey(key_exp_index, expr, ctx != ParseScriptContext::P2WSH, out, error);
|
auto pubkey = ParsePubkey(key_exp_index, expr, ctx != ParseScriptContext::P2WSH, out, error);
|
||||||
if (!pubkey) return nullptr;
|
if (!pubkey) return nullptr;
|
||||||
|
++key_exp_index;
|
||||||
return std::make_unique<PKDescriptor>(std::move(pubkey));
|
return std::make_unique<PKDescriptor>(std::move(pubkey));
|
||||||
}
|
}
|
||||||
if (Func("pkh", expr)) {
|
if (Func("pkh", expr)) {
|
||||||
auto pubkey = ParsePubkey(key_exp_index, expr, ctx != ParseScriptContext::P2WSH, out, error);
|
auto pubkey = ParsePubkey(key_exp_index, expr, ctx != ParseScriptContext::P2WSH, out, error);
|
||||||
if (!pubkey) return nullptr;
|
if (!pubkey) return nullptr;
|
||||||
|
++key_exp_index;
|
||||||
return std::make_unique<PKHDescriptor>(std::move(pubkey));
|
return std::make_unique<PKHDescriptor>(std::move(pubkey));
|
||||||
}
|
}
|
||||||
if (ctx == ParseScriptContext::TOP && Func("combo", expr)) {
|
if (ctx == ParseScriptContext::TOP && Func("combo", expr)) {
|
||||||
auto pubkey = ParsePubkey(key_exp_index, expr, true, out, error);
|
auto pubkey = ParsePubkey(key_exp_index, expr, true, out, error);
|
||||||
if (!pubkey) return nullptr;
|
if (!pubkey) return nullptr;
|
||||||
|
++key_exp_index;
|
||||||
return std::make_unique<ComboDescriptor>(std::move(pubkey));
|
return std::make_unique<ComboDescriptor>(std::move(pubkey));
|
||||||
} else if (ctx != ParseScriptContext::TOP && Func("combo", expr)) {
|
} else if (ctx != ParseScriptContext::TOP && Func("combo", expr)) {
|
||||||
error = "Cannot have combo in non-top level";
|
error = "Cannot have combo in non-top level";
|
||||||
@ -1011,6 +1014,7 @@ std::unique_ptr<DescriptorImpl> ParseScript(uint32_t key_exp_index, Span<const c
|
|||||||
if (ctx != ParseScriptContext::P2WSH && Func("wpkh", expr)) {
|
if (ctx != ParseScriptContext::P2WSH && Func("wpkh", expr)) {
|
||||||
auto pubkey = ParsePubkey(key_exp_index, expr, false, out, error);
|
auto pubkey = ParsePubkey(key_exp_index, expr, false, out, error);
|
||||||
if (!pubkey) return nullptr;
|
if (!pubkey) return nullptr;
|
||||||
|
key_exp_index++;
|
||||||
return std::make_unique<WPKHDescriptor>(std::move(pubkey));
|
return std::make_unique<WPKHDescriptor>(std::move(pubkey));
|
||||||
} else if (ctx == ParseScriptContext::P2WSH && Func("wpkh", expr)) {
|
} else if (ctx == ParseScriptContext::P2WSH && Func("wpkh", expr)) {
|
||||||
error = "Cannot have wpkh within wsh";
|
error = "Cannot have wpkh within wsh";
|
||||||
@ -1177,7 +1181,8 @@ std::unique_ptr<Descriptor> Parse(const std::string& descriptor, FlatSigningProv
|
|||||||
{
|
{
|
||||||
Span<const char> sp{descriptor};
|
Span<const char> sp{descriptor};
|
||||||
if (!CheckChecksum(sp, require_checksum, error)) return nullptr;
|
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<Descriptor>(std::move(ret));
|
if (sp.size() == 0 && ret) return std::unique_ptr<Descriptor>(std::move(ret));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user