@@ -335,10 +335,12 @@ class BIP32PubkeyProvider final : public PubkeyProvider
335
335
/* * Base class for all Descriptor implementations. */
336
336
class DescriptorImpl : public Descriptor
337
337
{
338
- // ! Public key arguments for this descriptor (size 1 for PK, PKH, WPKH; any size of Multisig).
338
+ // ! Public key arguments for this descriptor (size 1 for PK, PKH, WPKH; any size for Multisig).
339
339
const std::vector<std::unique_ptr<PubkeyProvider>> m_pubkey_args;
340
340
// ! The sub-descriptor argument (nullptr for everything but SH and WSH).
341
- const std::unique_ptr<DescriptorImpl> m_script_arg;
341
+ // ! In doc/descriptors.m this is referred to as SCRIPT expressions sh(SCRIPT)
342
+ // ! and wsh(SCRIPT), and distinct from KEY expressions and ADDR expressions.
343
+ const std::unique_ptr<DescriptorImpl> m_subdescriptor_arg;
342
344
// ! The string name of the descriptor function.
343
345
const std::string m_name;
344
346
@@ -349,23 +351,23 @@ class DescriptorImpl : public Descriptor
349
351
/* * A helper function to construct the scripts for this descriptor.
350
352
*
351
353
* This function is invoked once for every CScript produced by evaluating
352
- * m_script_arg , or just once in case m_script_arg is nullptr.
354
+ * m_subdescriptor_arg , or just once in case m_subdescriptor_arg is nullptr.
353
355
354
356
* @param pubkeys The evaluations of the m_pubkey_args field.
355
- * @param script The evaluation of m_script_arg (or nullptr when m_script_arg is nullptr).
357
+ * @param script The evaluation of m_subdescriptor_arg (or nullptr when m_subdescriptor_arg is nullptr).
356
358
* @param out A FlatSigningProvider to put scripts or public keys in that are necessary to the solver.
357
359
* The script arguments to this function are automatically added, as is the origin info of the provided pubkeys.
358
360
* @return A vector with scriptPubKeys for this descriptor.
359
361
*/
360
362
virtual std::vector<CScript> MakeScripts (const std::vector<CPubKey>& pubkeys, const CScript* script, FlatSigningProvider& out) const = 0;
361
363
362
364
public:
363
- DescriptorImpl (std::vector<std::unique_ptr<PubkeyProvider>> pubkeys, std::unique_ptr<DescriptorImpl> script, const std::string& name) : m_pubkey_args(std::move(pubkeys)), m_script_arg (std::move(script)), m_name(name) {}
365
+ DescriptorImpl (std::vector<std::unique_ptr<PubkeyProvider>> pubkeys, std::unique_ptr<DescriptorImpl> script, const std::string& name) : m_pubkey_args(std::move(pubkeys)), m_subdescriptor_arg (std::move(script)), m_name(name) {}
364
366
365
367
bool IsSolvable () const override
366
368
{
367
- if (m_script_arg ) {
368
- if (!m_script_arg ->IsSolvable ()) return false ;
369
+ if (m_subdescriptor_arg ) {
370
+ if (!m_subdescriptor_arg ->IsSolvable ()) return false ;
369
371
}
370
372
return true ;
371
373
}
@@ -375,8 +377,8 @@ class DescriptorImpl : public Descriptor
375
377
for (const auto & pubkey : m_pubkey_args) {
376
378
if (pubkey->IsRange ()) return true ;
377
379
}
378
- if (m_script_arg ) {
379
- if (m_script_arg ->IsRange ()) return true ;
380
+ if (m_subdescriptor_arg ) {
381
+ if (m_subdescriptor_arg ->IsRange ()) return true ;
380
382
}
381
383
return false ;
382
384
}
@@ -396,10 +398,10 @@ class DescriptorImpl : public Descriptor
396
398
}
397
399
ret += std::move (tmp);
398
400
}
399
- if (m_script_arg ) {
401
+ if (m_subdescriptor_arg ) {
400
402
if (pos++) ret += " ," ;
401
403
std::string tmp;
402
- if (!m_script_arg ->ToStringHelper (arg, tmp, priv)) return false ;
404
+ if (!m_subdescriptor_arg ->ToStringHelper (arg, tmp, priv)) return false ;
403
405
ret += std::move (tmp);
404
406
}
405
407
out = std::move (ret) + " )" ;
@@ -428,6 +430,8 @@ class DescriptorImpl : public Descriptor
428
430
// Construct temporary data in `entries` and `subscripts`, to avoid producing output in case of failure.
429
431
for (const auto & p : m_pubkey_args) {
430
432
entries.emplace_back ();
433
+ // If we have a cache, we don't need GetPubKey to compute the public key.
434
+ // Pass in nullptr to signify only origin info is desired.
431
435
if (!p->GetPubKey (pos, arg, cache_read ? nullptr : &entries.back ().first , entries.back ().second )) return false ;
432
436
if (cache_read) {
433
437
// Cached expanded public key exists, use it.
@@ -444,9 +448,9 @@ class DescriptorImpl : public Descriptor
444
448
}
445
449
}
446
450
std::vector<CScript> subscripts;
447
- if (m_script_arg ) {
451
+ if (m_subdescriptor_arg ) {
448
452
FlatSigningProvider subprovider;
449
- if (!m_script_arg ->ExpandHelper (pos, arg, cache_read, subscripts, subprovider, cache_write)) return false ;
453
+ if (!m_subdescriptor_arg ->ExpandHelper (pos, arg, cache_read, subscripts, subprovider, cache_write)) return false ;
450
454
out = Merge (out, subprovider);
451
455
}
452
456
@@ -456,7 +460,7 @@ class DescriptorImpl : public Descriptor
456
460
pubkeys.push_back (entry.first );
457
461
out.origins .emplace (entry.first .GetID (), std::make_pair<CPubKey, KeyOriginInfo>(CPubKey (entry.first ), std::move (entry.second )));
458
462
}
459
- if (m_script_arg ) {
463
+ if (m_subdescriptor_arg ) {
460
464
for (const auto & subscript : subscripts) {
461
465
out.scripts .emplace (CScriptID (subscript), subscript);
462
466
std::vector<CScript> addscripts = MakeScripts (pubkeys, &subscript, out);
0 commit comments