@@ -1491,13 +1491,17 @@ struct KeyParser {
1491
1491
if (miniscript::IsTapscript (m_script_ctx) && end - begin == 32 ) {
1492
1492
XOnlyPubKey pubkey;
1493
1493
std::copy (begin, end, pubkey.begin ());
1494
- m_keys.push_back (InferPubkey (pubkey.GetEvenCorrespondingCPubKey (), ParseContext (), *m_in));
1495
- return key;
1494
+ if (auto pubkey_provider = InferPubkey (pubkey.GetEvenCorrespondingCPubKey (), ParseContext (), *m_in)) {
1495
+ m_keys.push_back (std::move (pubkey_provider));
1496
+ return key;
1497
+ }
1496
1498
} else if (!miniscript::IsTapscript (m_script_ctx)) {
1497
- CPubKey pubkey{ begin, end} ;
1499
+ CPubKey pubkey ( begin, end) ;
1498
1500
if (pubkey.IsValidNonHybrid ()) {
1499
- m_keys.push_back (InferPubkey (pubkey, ParseContext (), *m_in));
1500
- return key;
1501
+ if (auto pubkey_provider = InferPubkey (pubkey, ParseContext (), *m_in)) {
1502
+ m_keys.push_back (std::move (pubkey_provider));
1503
+ return key;
1504
+ }
1501
1505
}
1502
1506
}
1503
1507
return {};
@@ -1512,9 +1516,11 @@ struct KeyParser {
1512
1516
CKeyID keyid (hash);
1513
1517
CPubKey pubkey;
1514
1518
if (m_in->GetPubKey (keyid, pubkey)) {
1515
- Key key = m_keys.size ();
1516
- m_keys.push_back (InferPubkey (pubkey, ParseContext (), *m_in));
1517
- return key;
1519
+ if (auto pubkey_provider = InferPubkey (pubkey, ParseContext (), *m_in)) {
1520
+ Key key = m_keys.size ();
1521
+ m_keys.push_back (std::move (pubkey_provider));
1522
+ return key;
1523
+ }
1518
1524
}
1519
1525
return {};
1520
1526
}
@@ -1850,32 +1856,44 @@ std::unique_ptr<DescriptorImpl> InferScript(const CScript& script, ParseScriptCo
1850
1856
if (txntype == TxoutType::PUBKEY && (ctx == ParseScriptContext::TOP || ctx == ParseScriptContext::P2SH || ctx == ParseScriptContext::P2WSH)) {
1851
1857
CPubKey pubkey (data[0 ]);
1852
1858
if (pubkey.IsValidNonHybrid ()) {
1853
- return std::make_unique<PKDescriptor>(InferPubkey (pubkey, ctx, provider));
1859
+ if (auto pubkey_provider = InferPubkey (pubkey, ctx, provider)) {
1860
+ return std::make_unique<PKDescriptor>(std::move (pubkey_provider));
1861
+ }
1854
1862
}
1855
1863
}
1856
1864
if (txntype == TxoutType::PUBKEYHASH && (ctx == ParseScriptContext::TOP || ctx == ParseScriptContext::P2SH || ctx == ParseScriptContext::P2WSH)) {
1857
1865
uint160 hash (data[0 ]);
1858
1866
CKeyID keyid (hash);
1859
1867
CPubKey pubkey;
1860
1868
if (provider.GetPubKey (keyid, pubkey)) {
1861
- return std::make_unique<PKHDescriptor>(InferPubkey (pubkey, ctx, provider));
1869
+ if (auto pubkey_provider = InferPubkey (pubkey, ctx, provider)) {
1870
+ return std::make_unique<PKHDescriptor>(std::move (pubkey_provider));
1871
+ }
1862
1872
}
1863
1873
}
1864
1874
if (txntype == TxoutType::WITNESS_V0_KEYHASH && (ctx == ParseScriptContext::TOP || ctx == ParseScriptContext::P2SH)) {
1865
1875
uint160 hash (data[0 ]);
1866
1876
CKeyID keyid (hash);
1867
1877
CPubKey pubkey;
1868
1878
if (provider.GetPubKey (keyid, pubkey)) {
1869
- return std::make_unique<WPKHDescriptor>(InferPubkey (pubkey, ctx, provider));
1879
+ if (auto pubkey_provider = InferPubkey (pubkey, ctx, provider)) {
1880
+ return std::make_unique<WPKHDescriptor>(std::move (pubkey_provider));
1881
+ }
1870
1882
}
1871
1883
}
1872
1884
if (txntype == TxoutType::MULTISIG && (ctx == ParseScriptContext::TOP || ctx == ParseScriptContext::P2SH || ctx == ParseScriptContext::P2WSH)) {
1885
+ bool ok = true ;
1873
1886
std::vector<std::unique_ptr<PubkeyProvider>> providers;
1874
1887
for (size_t i = 1 ; i + 1 < data.size (); ++i) {
1875
1888
CPubKey pubkey (data[i]);
1876
- providers.push_back (InferPubkey (pubkey, ctx, provider));
1889
+ if (auto pubkey_provider = InferPubkey (pubkey, ctx, provider)) {
1890
+ providers.push_back (std::move (pubkey_provider));
1891
+ } else {
1892
+ ok = false ;
1893
+ break ;
1894
+ }
1877
1895
}
1878
- return std::make_unique<MultisigDescriptor>((int )data[0 ][0 ], std::move (providers));
1896
+ if (ok) return std::make_unique<MultisigDescriptor>((int )data[0 ][0 ], std::move (providers));
1879
1897
}
1880
1898
if (txntype == TxoutType::SCRIPTHASH && ctx == ParseScriptContext::TOP) {
1881
1899
uint160 hash (data[0 ]);
0 commit comments