Skip to content

Commit 3eed6fc

Browse files
committed
Add multi_a descriptor inference
1 parent 79728c4 commit 3eed6fc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/script/descriptor.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,13 +1287,33 @@ std::unique_ptr<PubkeyProvider> InferXOnlyPubkey(const XOnlyPubKey& xkey, ParseS
12871287
return key_provider;
12881288
}
12891289

1290+
std::unique_ptr<DescriptorImpl> InferMultiA(const CScript& script, ParseScriptContext ctx, const SigningProvider& provider)
1291+
{
1292+
auto match = MatchMultiA(script);
1293+
if (!match) return {};
1294+
std::vector<std::unique_ptr<PubkeyProvider>> keys;
1295+
keys.reserve(match->second.size());
1296+
for (const auto keyspan : match->second) {
1297+
if (keyspan.size() != 32) return {};
1298+
auto key = InferXOnlyPubkey(XOnlyPubKey{keyspan}, ctx, provider);
1299+
if (!key) return {};
1300+
keys.push_back(std::move(key));
1301+
}
1302+
return std::make_unique<MultiADescriptor>(match->first, std::move(keys));
1303+
}
1304+
12901305
std::unique_ptr<DescriptorImpl> InferScript(const CScript& script, ParseScriptContext ctx, const SigningProvider& provider)
12911306
{
12921307
if (ctx == ParseScriptContext::P2TR && script.size() == 34 && script[0] == 32 && script[33] == OP_CHECKSIG) {
12931308
XOnlyPubKey key{Span{script}.subspan(1, 32)};
12941309
return std::make_unique<PKDescriptor>(InferXOnlyPubkey(key, ctx, provider));
12951310
}
12961311

1312+
if (ctx == ParseScriptContext::P2TR) {
1313+
auto ret = InferMultiA(script, ctx, provider);
1314+
if (ret) return ret;
1315+
}
1316+
12971317
std::vector<std::vector<unsigned char>> data;
12981318
TxoutType txntype = Solver(script, data);
12991319

0 commit comments

Comments
 (0)