@@ -718,6 +718,8 @@ class DescriptorImpl : public Descriptor
718718 virtual std::optional<int64_t > MaxSatSize (bool use_max_sig) const { return {}; }
719719
720720 std::optional<int64_t > MaxSatisfactionWeight (bool ) const override { return {}; }
721+
722+ std::optional<int64_t > MaxSatisfactionElems () const override { return {}; }
721723};
722724
723725/* * A parsed addr(A) descriptor. */
@@ -795,6 +797,8 @@ class PKDescriptor final : public DescriptorImpl
795797 std::optional<int64_t > MaxSatisfactionWeight (bool use_max_sig) const override {
796798 return *MaxSatSize (use_max_sig) * WITNESS_SCALE_FACTOR;
797799 }
800+
801+ std::optional<int64_t > MaxSatisfactionElems () const override { return 1 ; }
798802};
799803
800804/* * A parsed pkh(P) descriptor. */
@@ -822,6 +826,8 @@ class PKHDescriptor final : public DescriptorImpl
822826 std::optional<int64_t > MaxSatisfactionWeight (bool use_max_sig) const override {
823827 return *MaxSatSize (use_max_sig) * WITNESS_SCALE_FACTOR;
824828 }
829+
830+ std::optional<int64_t > MaxSatisfactionElems () const override { return 2 ; }
825831};
826832
827833/* * A parsed wpkh(P) descriptor. */
@@ -849,6 +855,8 @@ class WPKHDescriptor final : public DescriptorImpl
849855 std::optional<int64_t > MaxSatisfactionWeight (bool use_max_sig) const override {
850856 return MaxSatSize (use_max_sig);
851857 }
858+
859+ std::optional<int64_t > MaxSatisfactionElems () const override { return 2 ; }
852860};
853861
854862/* * A parsed combo(P) descriptor. */
@@ -909,6 +917,8 @@ class MultisigDescriptor final : public DescriptorImpl
909917 std::optional<int64_t > MaxSatisfactionWeight (bool use_max_sig) const override {
910918 return *MaxSatSize (use_max_sig) * WITNESS_SCALE_FACTOR;
911919 }
920+
921+ std::optional<int64_t > MaxSatisfactionElems () const override { return 1 + m_threshold; }
912922};
913923
914924/* * A parsed (sorted)multi_a(...) descriptor. Always uses x-only pubkeys. */
@@ -943,6 +953,8 @@ class MultiADescriptor final : public DescriptorImpl
943953 std::optional<int64_t > MaxSatSize (bool use_max_sig) const override {
944954 return (1 + 65 ) * m_threshold + (m_pubkey_args.size () - m_threshold);
945955 }
956+
957+ std::optional<int64_t > MaxSatisfactionElems () const override { return m_pubkey_args.size (); }
946958};
947959
948960/* * A parsed sh(...) descriptor. */
@@ -983,6 +995,11 @@ class SHDescriptor final : public DescriptorImpl
983995 }
984996 return {};
985997 }
998+
999+ std::optional<int64_t > MaxSatisfactionElems () const override {
1000+ if (const auto sub_elems = m_subdescriptor_args[0 ]->MaxSatisfactionElems ()) return 1 + *sub_elems;
1001+ return {};
1002+ }
9861003};
9871004
9881005/* * A parsed wsh(...) descriptor. */
@@ -1014,6 +1031,11 @@ class WSHDescriptor final : public DescriptorImpl
10141031 std::optional<int64_t > MaxSatisfactionWeight (bool use_max_sig) const override {
10151032 return MaxSatSize (use_max_sig);
10161033 }
1034+
1035+ std::optional<int64_t > MaxSatisfactionElems () const override {
1036+ if (const auto sub_elems = m_subdescriptor_args[0 ]->MaxSatisfactionElems ()) return 1 + *sub_elems;
1037+ return {};
1038+ }
10171039};
10181040
10191041/* * A parsed tr(...) descriptor. */
@@ -1074,6 +1096,11 @@ class TRDescriptor final : public DescriptorImpl
10741096 // FIXME: We assume keypath spend, which can lead to very large underestimations.
10751097 return 1 + 65 ;
10761098 }
1099+
1100+ std::optional<int64_t > MaxSatisfactionElems () const override {
1101+ // FIXME: See above, we assume keypath spend.
1102+ return 1 ;
1103+ }
10771104};
10781105
10791106/* We instantiate Miniscript here with a simple integer as key type.
@@ -1164,6 +1191,10 @@ class MiniscriptDescriptor final : public DescriptorImpl
11641191 // For Miniscript we always assume high-R ECDSA signatures.
11651192 return m_node->GetWitnessSize ();
11661193 }
1194+
1195+ std::optional<int64_t > MaxSatisfactionElems () const override {
1196+ return m_node->GetStackSize ();
1197+ }
11671198};
11681199
11691200/* * A parsed rawtr(...) descriptor. */
@@ -1189,6 +1220,11 @@ class RawTRDescriptor final : public DescriptorImpl
11891220 // We can't know whether there is a script path, so assume key path spend.
11901221 return 1 + 65 ;
11911222 }
1223+
1224+ std::optional<int64_t > MaxSatisfactionElems () const override {
1225+ // See above, we assume keypath spend.
1226+ return 1 ;
1227+ }
11921228};
11931229
11941230// //////////////////////////////////////////////////////////////////////////
0 commit comments