@@ -638,6 +638,19 @@ class DescriptorImpl : public Descriptor
638
638
std::optional<OutputType> GetOutputType () const override { return std::nullopt; }
639
639
};
640
640
641
+ static std::optional<OutputType> OutputTypeFromDestination (const CTxDestination& dest) {
642
+ if (std::holds_alternative<PKHash>(dest) ||
643
+ std::holds_alternative<ScriptHash>(dest)) {
644
+ return OutputType::LEGACY;
645
+ }
646
+ if (std::holds_alternative<WitnessV0KeyHash>(dest) ||
647
+ std::holds_alternative<WitnessV0ScriptHash>(dest) ||
648
+ std::holds_alternative<WitnessUnknown>(dest)) {
649
+ return OutputType::BECH32;
650
+ }
651
+ return std::nullopt;
652
+ }
653
+
641
654
/* * A parsed addr(A) descriptor. */
642
655
class AddressDescriptor final : public DescriptorImpl
643
656
{
@@ -651,15 +664,7 @@ class AddressDescriptor final : public DescriptorImpl
651
664
652
665
std::optional<OutputType> GetOutputType () const override
653
666
{
654
- switch (m_destination.index ()) {
655
- case 1 /* PKHash */ :
656
- case 2 /* ScriptHash */ : return OutputType::LEGACY;
657
- case 3 /* WitnessV0ScriptHash */ :
658
- case 4 /* WitnessV0KeyHash */ :
659
- case 5 /* WitnessUnknown */ : return OutputType::BECH32;
660
- case 0 /* CNoDestination */ :
661
- default : return std::nullopt;
662
- }
667
+ return OutputTypeFromDestination (m_destination);
663
668
}
664
669
bool IsSingleType () const final { return true ; }
665
670
};
@@ -679,15 +684,7 @@ class RawDescriptor final : public DescriptorImpl
679
684
{
680
685
CTxDestination dest;
681
686
ExtractDestination (m_script, dest);
682
- switch (dest.index ()) {
683
- case 1 /* PKHash */ :
684
- case 2 /* ScriptHash */ : return OutputType::LEGACY;
685
- case 3 /* WitnessV0ScriptHash */ :
686
- case 4 /* WitnessV0KeyHash */ :
687
- case 5 /* WitnessUnknown */ : return OutputType::BECH32;
688
- case 0 /* CNoDestination */ :
689
- default : return std::nullopt;
690
- }
687
+ return OutputTypeFromDestination (dest);
691
688
}
692
689
bool IsSingleType () const final { return true ; }
693
690
};
0 commit comments