@@ -339,14 +339,15 @@ class DescriptorImpl : public Descriptor
339
339
{
340
340
// ! Public key arguments for this descriptor (size 1 for PK, PKH, WPKH; any size for Multisig).
341
341
const std::vector<std::unique_ptr<PubkeyProvider>> m_pubkey_args;
342
+ // ! The string name of the descriptor function.
343
+ const std::string m_name;
344
+
345
+ protected:
342
346
// ! The sub-descriptor argument (nullptr for everything but SH and WSH).
343
347
// ! In doc/descriptors.m this is referred to as SCRIPT expressions sh(SCRIPT)
344
348
// ! and wsh(SCRIPT), and distinct from KEY expressions and ADDR expressions.
345
349
const std::unique_ptr<DescriptorImpl> m_subdescriptor_arg;
346
- // ! The string name of the descriptor function.
347
- const std::string m_name;
348
350
349
- protected:
350
351
// ! Return a serialization of anything except pubkey and script arguments, to be prepended to those.
351
352
virtual std::string ToStringExtra () const { return " " ; }
352
353
@@ -364,7 +365,7 @@ class DescriptorImpl : public Descriptor
364
365
virtual std::vector<CScript> MakeScripts (const std::vector<CPubKey>& pubkeys, const CScript* script, FlatSigningProvider& out) const = 0;
365
366
366
367
public:
367
- 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 ) {}
368
+ DescriptorImpl (std::vector<std::unique_ptr<PubkeyProvider>> pubkeys, std::unique_ptr<DescriptorImpl> script, const std::string& name) : m_pubkey_args(std::move(pubkeys)), m_name(name), m_subdescriptor_arg(std::move(script)) {}
368
369
369
370
bool IsSolvable () const override
370
371
{
@@ -500,6 +501,8 @@ class DescriptorImpl : public Descriptor
500
501
out = Merge (out, subprovider);
501
502
}
502
503
}
504
+
505
+ Optional<OutputType> GetOutputType () const override { return nullopt; }
503
506
};
504
507
505
508
/* * A parsed addr(A) descriptor. */
@@ -512,6 +515,19 @@ class AddressDescriptor final : public DescriptorImpl
512
515
public:
513
516
AddressDescriptor (CTxDestination destination) : DescriptorImpl({}, {}, " addr" ), m_destination(std::move(destination)) {}
514
517
bool IsSolvable () const final { return false ; }
518
+
519
+ Optional<OutputType> GetOutputType () const override
520
+ {
521
+ switch (m_destination.which ()) {
522
+ case 1 /* PKHash */ :
523
+ case 2 /* ScriptHash */ : return OutputType::LEGACY;
524
+ case 3 /* WitnessV0ScriptHash */ :
525
+ case 4 /* WitnessV0KeyHash */ :
526
+ case 5 /* WitnessUnknown */ : return OutputType::BECH32;
527
+ case 0 /* CNoDestination */ :
528
+ default : return nullopt;
529
+ }
530
+ }
515
531
};
516
532
517
533
/* * A parsed raw(H) descriptor. */
@@ -524,6 +540,21 @@ class RawDescriptor final : public DescriptorImpl
524
540
public:
525
541
RawDescriptor (CScript script) : DescriptorImpl({}, {}, " raw" ), m_script(std::move(script)) {}
526
542
bool IsSolvable () const final { return false ; }
543
+
544
+ Optional<OutputType> GetOutputType () const override
545
+ {
546
+ CTxDestination dest;
547
+ ExtractDestination (m_script, dest);
548
+ switch (dest.which ()) {
549
+ case 1 /* PKHash */ :
550
+ case 2 /* ScriptHash */ : return OutputType::LEGACY;
551
+ case 3 /* WitnessV0ScriptHash */ :
552
+ case 4 /* WitnessV0KeyHash */ :
553
+ case 5 /* WitnessUnknown */ : return OutputType::BECH32;
554
+ case 0 /* CNoDestination */ :
555
+ default : return nullopt;
556
+ }
557
+ }
527
558
};
528
559
529
560
/* * A parsed pk(P) descriptor. */
@@ -547,6 +578,7 @@ class PKHDescriptor final : public DescriptorImpl
547
578
}
548
579
public:
549
580
PKHDescriptor (std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Vector(std::move(prov)), {}, " pkh" ) {}
581
+ Optional<OutputType> GetOutputType () const override { return OutputType::LEGACY; }
550
582
};
551
583
552
584
/* * A parsed wpkh(P) descriptor. */
@@ -561,6 +593,7 @@ class WPKHDescriptor final : public DescriptorImpl
561
593
}
562
594
public:
563
595
WPKHDescriptor (std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Vector(std::move(prov)), {}, " wpkh" ) {}
596
+ Optional<OutputType> GetOutputType () const override { return OutputType::BECH32; }
564
597
};
565
598
566
599
/* * A parsed combo(P) descriptor. */
@@ -612,6 +645,13 @@ class SHDescriptor final : public DescriptorImpl
612
645
std::vector<CScript> MakeScripts (const std::vector<CPubKey>&, const CScript* script, FlatSigningProvider&) const override { return Vector (GetScriptForDestination (ScriptHash (*script))); }
613
646
public:
614
647
SHDescriptor (std::unique_ptr<DescriptorImpl> desc) : DescriptorImpl({}, std::move(desc), " sh" ) {}
648
+
649
+ Optional<OutputType> GetOutputType () const override
650
+ {
651
+ assert (m_subdescriptor_arg);
652
+ if (m_subdescriptor_arg->GetOutputType () == OutputType::BECH32) return OutputType::P2SH_SEGWIT;
653
+ return OutputType::LEGACY;
654
+ }
615
655
};
616
656
617
657
/* * A parsed wsh(...) descriptor. */
@@ -621,6 +661,7 @@ class WSHDescriptor final : public DescriptorImpl
621
661
std::vector<CScript> MakeScripts (const std::vector<CPubKey>&, const CScript* script, FlatSigningProvider&) const override { return Vector (GetScriptForDestination (WitnessV0ScriptHash (*script))); }
622
662
public:
623
663
WSHDescriptor (std::unique_ptr<DescriptorImpl> desc) : DescriptorImpl({}, std::move(desc), " wsh" ) {}
664
+ Optional<OutputType> GetOutputType () const override { return OutputType::BECH32; }
624
665
};
625
666
626
667
// //////////////////////////////////////////////////////////////////////////
0 commit comments