Skip to content

Commit d1ec3e4

Browse files
committed
Add IsSingleType to Descriptors
IsSingleType will return whether the descriptor will give one or multiple scriptPubKeys
1 parent 953feb3 commit d1ec3e4

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/script/descriptor.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ class AddressDescriptor final : public DescriptorImpl
575575
default: return nullopt;
576576
}
577577
}
578+
bool IsSingleType() const final { return true; }
578579
};
579580

580581
/** A parsed raw(H) descriptor. */
@@ -602,6 +603,7 @@ class RawDescriptor final : public DescriptorImpl
602603
default: return nullopt;
603604
}
604605
}
606+
bool IsSingleType() const final { return true; }
605607
};
606608

607609
/** A parsed pk(P) descriptor. */
@@ -611,6 +613,7 @@ class PKDescriptor final : public DescriptorImpl
611613
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, const CScript*, FlatSigningProvider&) const override { return Vector(GetScriptForRawPubKey(keys[0])); }
612614
public:
613615
PKDescriptor(std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Vector(std::move(prov)), {}, "pk") {}
616+
bool IsSingleType() const final { return true; }
614617
};
615618

616619
/** A parsed pkh(P) descriptor. */
@@ -626,6 +629,7 @@ class PKHDescriptor final : public DescriptorImpl
626629
public:
627630
PKHDescriptor(std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Vector(std::move(prov)), {}, "pkh") {}
628631
Optional<OutputType> GetOutputType() const override { return OutputType::LEGACY; }
632+
bool IsSingleType() const final { return true; }
629633
};
630634

631635
/** A parsed wpkh(P) descriptor. */
@@ -641,6 +645,7 @@ class WPKHDescriptor final : public DescriptorImpl
641645
public:
642646
WPKHDescriptor(std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Vector(std::move(prov)), {}, "wpkh") {}
643647
Optional<OutputType> GetOutputType() const override { return OutputType::BECH32; }
648+
bool IsSingleType() const final { return true; }
644649
};
645650

646651
/** A parsed combo(P) descriptor. */
@@ -664,6 +669,7 @@ class ComboDescriptor final : public DescriptorImpl
664669
}
665670
public:
666671
ComboDescriptor(std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Vector(std::move(prov)), {}, "combo") {}
672+
bool IsSingleType() const final { return false; }
667673
};
668674

669675
/** A parsed multi(...) or sortedmulti(...) descriptor */
@@ -683,6 +689,7 @@ class MultisigDescriptor final : public DescriptorImpl
683689
}
684690
public:
685691
MultisigDescriptor(int threshold, std::vector<std::unique_ptr<PubkeyProvider>> providers, bool sorted = false) : DescriptorImpl(std::move(providers), {}, sorted ? "sortedmulti" : "multi"), m_threshold(threshold), m_sorted(sorted) {}
692+
bool IsSingleType() const final { return true; }
686693
};
687694

688695
/** A parsed sh(...) descriptor. */
@@ -699,6 +706,7 @@ class SHDescriptor final : public DescriptorImpl
699706
if (m_subdescriptor_arg->GetOutputType() == OutputType::BECH32) return OutputType::P2SH_SEGWIT;
700707
return OutputType::LEGACY;
701708
}
709+
bool IsSingleType() const final { return true; }
702710
};
703711

704712
/** A parsed wsh(...) descriptor. */
@@ -709,6 +717,7 @@ class WSHDescriptor final : public DescriptorImpl
709717
public:
710718
WSHDescriptor(std::unique_ptr<DescriptorImpl> desc) : DescriptorImpl({}, std::move(desc), "wsh") {}
711719
Optional<OutputType> GetOutputType() const override { return OutputType::BECH32; }
720+
bool IsSingleType() const final { return true; }
712721
};
713722

714723
////////////////////////////////////////////////////////////////////////////

src/script/descriptor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ struct Descriptor {
8787
/** Convert the descriptor back to a string, undoing parsing. */
8888
virtual std::string ToString() const = 0;
8989

90+
/** Whether this descriptor will return one scriptPubKey or multiple (aka is or is not combo) */
91+
virtual bool IsSingleType() const = 0;
92+
9093
/** Convert the descriptor to a private string. This fails if the provided provider does not have the relevant private keys. */
9194
virtual bool ToPrivateString(const SigningProvider& provider, std::string& out) const = 0;
9295

0 commit comments

Comments
 (0)