@@ -221,6 +221,9 @@ struct PubkeyProvider
221
221
222
222
/* * Make a deep copy of this PubkeyProvider */
223
223
virtual std::unique_ptr<PubkeyProvider> Clone () const = 0;
224
+
225
+ /* * Whether this PubkeyProvider can always provide a public key without cache or private key arguments */
226
+ virtual bool CanSelfExpand () const = 0;
224
227
};
225
228
226
229
class OriginPubkeyProvider final : public PubkeyProvider
@@ -290,6 +293,7 @@ class OriginPubkeyProvider final : public PubkeyProvider
290
293
{
291
294
return std::make_unique<OriginPubkeyProvider>(m_expr_index, m_origin, m_provider->Clone (), m_apostrophe);
292
295
}
296
+ bool CanSelfExpand () const override { return m_provider->CanSelfExpand (); }
293
297
};
294
298
295
299
/* * An object representing a parsed constant public key in a descriptor. */
@@ -350,6 +354,7 @@ class ConstPubkeyProvider final : public PubkeyProvider
350
354
{
351
355
return std::make_unique<ConstPubkeyProvider>(m_expr_index, m_pubkey, m_xonly);
352
356
}
357
+ bool CanSelfExpand () const final { return true ; }
353
358
};
354
359
355
360
enum class DeriveType {
@@ -572,6 +577,7 @@ class BIP32PubkeyProvider final : public PubkeyProvider
572
577
{
573
578
return std::make_unique<BIP32PubkeyProvider>(m_expr_index, m_root_extkey, m_path, m_derive, m_apostrophe);
574
579
}
580
+ bool CanSelfExpand () const override { return !IsHardened (); }
575
581
};
576
582
577
583
/* * Base class for all Descriptor implementations. */
@@ -800,6 +806,7 @@ class AddressDescriptor final : public DescriptorImpl
800
806
}
801
807
bool IsSingleType () const final { return true ; }
802
808
bool ToPrivateString (const SigningProvider& arg, std::string& out) const final { return false ; }
809
+ bool CanSelfExpand () const final { return true ; }
803
810
804
811
std::optional<int64_t > ScriptSize () const override { return GetScriptForDestination (m_destination).size (); }
805
812
std::unique_ptr<DescriptorImpl> Clone () const override
@@ -827,6 +834,7 @@ class RawDescriptor final : public DescriptorImpl
827
834
}
828
835
bool IsSingleType () const final { return true ; }
829
836
bool ToPrivateString (const SigningProvider& arg, std::string& out) const final { return false ; }
837
+ bool CanSelfExpand () const final { return true ; }
830
838
831
839
std::optional<int64_t > ScriptSize () const override { return m_script.size (); }
832
840
@@ -854,6 +862,7 @@ class PKDescriptor final : public DescriptorImpl
854
862
public:
855
863
PKDescriptor (std::unique_ptr<PubkeyProvider> prov, bool xonly = false ) : DescriptorImpl(Vector(std::move(prov)), " pk" ), m_xonly(xonly) {}
856
864
bool IsSingleType () const final { return true ; }
865
+ bool CanSelfExpand () const override { return m_pubkey_args[0 ]->CanSelfExpand (); }
857
866
858
867
std::optional<int64_t > ScriptSize () const override {
859
868
return 1 + (m_xonly ? 32 : m_pubkey_args[0 ]->GetSize ()) + 1 ;
@@ -889,6 +898,7 @@ class PKHDescriptor final : public DescriptorImpl
889
898
PKHDescriptor (std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Vector(std::move(prov)), " pkh" ) {}
890
899
std::optional<OutputType> GetOutputType () const override { return OutputType::LEGACY; }
891
900
bool IsSingleType () const final { return true ; }
901
+ bool CanSelfExpand () const override { return m_pubkey_args[0 ]->CanSelfExpand (); }
892
902
893
903
std::optional<int64_t > ScriptSize () const override { return 1 + 1 + 1 + 20 + 1 + 1 ; }
894
904
@@ -922,6 +932,7 @@ class WPKHDescriptor final : public DescriptorImpl
922
932
WPKHDescriptor (std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Vector(std::move(prov)), " wpkh" ) {}
923
933
std::optional<OutputType> GetOutputType () const override { return OutputType::BECH32; }
924
934
bool IsSingleType () const final { return true ; }
935
+ bool CanSelfExpand () const override { return m_pubkey_args[0 ]->CanSelfExpand (); }
925
936
926
937
std::optional<int64_t > ScriptSize () const override { return 1 + 1 + 20 ; }
927
938
@@ -963,6 +974,7 @@ class ComboDescriptor final : public DescriptorImpl
963
974
public:
964
975
ComboDescriptor (std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Vector(std::move(prov)), " combo" ) {}
965
976
bool IsSingleType () const final { return false ; }
977
+ bool CanSelfExpand () const override { return m_pubkey_args[0 ]->CanSelfExpand (); }
966
978
std::unique_ptr<DescriptorImpl> Clone () const override
967
979
{
968
980
return std::make_unique<ComboDescriptor>(m_pubkey_args.at (0 )->Clone ());
@@ -987,6 +999,13 @@ class MultisigDescriptor final : public DescriptorImpl
987
999
public:
988
1000
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) {}
989
1001
bool IsSingleType () const final { return true ; }
1002
+ bool CanSelfExpand () const override {
1003
+ bool can_expand = true ;
1004
+ for (const auto & key : m_pubkey_args) {
1005
+ can_expand &= key->CanSelfExpand ();
1006
+ }
1007
+ return can_expand;
1008
+ }
990
1009
991
1010
std::optional<int64_t > ScriptSize () const override {
992
1011
const auto n_keys = m_pubkey_args.size ();
@@ -1038,6 +1057,13 @@ class MultiADescriptor final : public DescriptorImpl
1038
1057
public:
1039
1058
MultiADescriptor (int threshold, std::vector<std::unique_ptr<PubkeyProvider>> providers, bool sorted = false ) : DescriptorImpl(std::move(providers), sorted ? " sortedmulti_a" : " multi_a" ), m_threshold(threshold), m_sorted(sorted) {}
1040
1059
bool IsSingleType () const final { return true ; }
1060
+ bool CanSelfExpand () const override {
1061
+ bool can_expand = true ;
1062
+ for (const auto & key : m_pubkey_args) {
1063
+ can_expand &= key->CanSelfExpand ();
1064
+ }
1065
+ return can_expand;
1066
+ }
1041
1067
1042
1068
std::optional<int64_t > ScriptSize () const override {
1043
1069
const auto n_keys = m_pubkey_args.size ();
@@ -1084,6 +1110,7 @@ class SHDescriptor final : public DescriptorImpl
1084
1110
return OutputType::LEGACY;
1085
1111
}
1086
1112
bool IsSingleType () const final { return true ; }
1113
+ bool CanSelfExpand () const override { return m_subdescriptor_args[0 ]->CanSelfExpand (); }
1087
1114
1088
1115
std::optional<int64_t > ScriptSize () const override { return 1 + 1 + 20 + 1 ; }
1089
1116
@@ -1125,6 +1152,7 @@ class WSHDescriptor final : public DescriptorImpl
1125
1152
WSHDescriptor (std::unique_ptr<DescriptorImpl> desc) : DescriptorImpl({}, std::move(desc), " wsh" ) {}
1126
1153
std::optional<OutputType> GetOutputType () const override { return OutputType::BECH32; }
1127
1154
bool IsSingleType () const final { return true ; }
1155
+ bool CanSelfExpand () const override { return m_subdescriptor_args[0 ]->CanSelfExpand (); }
1128
1156
1129
1157
std::optional<int64_t > ScriptSize () const override { return 1 + 1 + 32 ; }
1130
1158
@@ -1202,6 +1230,13 @@ class TRDescriptor final : public DescriptorImpl
1202
1230
}
1203
1231
std::optional<OutputType> GetOutputType () const override { return OutputType::BECH32M; }
1204
1232
bool IsSingleType () const final { return true ; }
1233
+ bool CanSelfExpand () const override {
1234
+ bool can_expand = m_pubkey_args[0 ]->CanSelfExpand ();
1235
+ for (const auto & sub : m_subdescriptor_args) {
1236
+ can_expand &= sub->CanSelfExpand ();
1237
+ }
1238
+ return can_expand;
1239
+ }
1205
1240
1206
1241
std::optional<int64_t > ScriptSize () const override { return 1 + 1 + 32 ; }
1207
1242
@@ -1329,6 +1364,13 @@ class MiniscriptDescriptor final : public DescriptorImpl
1329
1364
1330
1365
bool IsSolvable () const override { return true ; }
1331
1366
bool IsSingleType () const final { return true ; }
1367
+ bool CanSelfExpand () const override {
1368
+ bool can_expand = true ;
1369
+ for (const auto & key : m_pubkey_args) {
1370
+ can_expand &= key->CanSelfExpand ();
1371
+ }
1372
+ return can_expand;
1373
+ }
1332
1374
1333
1375
std::optional<int64_t > ScriptSize () const override { return m_node->ScriptSize (); }
1334
1376
@@ -1368,6 +1410,7 @@ class RawTRDescriptor final : public DescriptorImpl
1368
1410
RawTRDescriptor (std::unique_ptr<PubkeyProvider> output_key) : DescriptorImpl(Vector(std::move(output_key)), " rawtr" ) {}
1369
1411
std::optional<OutputType> GetOutputType () const override { return OutputType::BECH32M; }
1370
1412
bool IsSingleType () const final { return true ; }
1413
+ bool CanSelfExpand () const override { return m_pubkey_args[0 ]->CanSelfExpand (); }
1371
1414
1372
1415
std::optional<int64_t > ScriptSize () const override { return 1 + 1 + 32 ; }
1373
1416
0 commit comments