@@ -507,6 +507,13 @@ class DescriptorImpl : public Descriptor
507
507
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_args(Vector(std::move(script))) {}
508
508
DescriptorImpl (std::vector<std::unique_ptr<PubkeyProvider>> pubkeys, std::vector<std::unique_ptr<DescriptorImpl>> scripts, const std::string& name) : m_pubkey_args(std::move(pubkeys)), m_name(name), m_subdescriptor_args(std::move(scripts)) {}
509
509
510
+ enum class StringType
511
+ {
512
+ PUBLIC,
513
+ PRIVATE,
514
+ NORMALIZED,
515
+ };
516
+
510
517
bool IsSolvable () const override
511
518
{
512
519
for (const auto & arg : m_subdescriptor_args) {
@@ -526,37 +533,41 @@ class DescriptorImpl : public Descriptor
526
533
return false ;
527
534
}
528
535
529
- virtual bool ToStringSubScriptHelper (const SigningProvider* arg, std::string& ret, bool priv, bool normalized ) const
536
+ virtual bool ToStringSubScriptHelper (const SigningProvider* arg, std::string& ret, const StringType type ) const
530
537
{
531
538
size_t pos = 0 ;
532
539
for (const auto & scriptarg : m_subdescriptor_args) {
533
540
if (pos++) ret += " ," ;
534
541
std::string tmp;
535
- if (!scriptarg->ToStringHelper (arg, tmp, priv, normalized )) return false ;
542
+ if (!scriptarg->ToStringHelper (arg, tmp, type )) return false ;
536
543
ret += std::move (tmp);
537
544
}
538
545
return true ;
539
546
}
540
547
541
- bool ToStringHelper (const SigningProvider* arg, std::string& out, bool priv, bool normalized ) const
548
+ bool ToStringHelper (const SigningProvider* arg, std::string& out, const StringType type ) const
542
549
{
543
550
std::string extra = ToStringExtra ();
544
551
size_t pos = extra.size () > 0 ? 1 : 0 ;
545
552
std::string ret = m_name + " (" + extra;
546
553
for (const auto & pubkey : m_pubkey_args) {
547
554
if (pos++) ret += " ," ;
548
555
std::string tmp;
549
- if (normalized) {
550
- if (!pubkey->ToNormalizedString (*arg, tmp)) return false ;
551
- } else if (priv) {
552
- if (!pubkey->ToPrivateString (*arg, tmp)) return false ;
553
- } else {
554
- tmp = pubkey->ToString ();
556
+ switch (type) {
557
+ case StringType::NORMALIZED:
558
+ if (!pubkey->ToNormalizedString (*arg, tmp)) return false ;
559
+ break ;
560
+ case StringType::PRIVATE:
561
+ if (!pubkey->ToPrivateString (*arg, tmp)) return false ;
562
+ break ;
563
+ case StringType::PUBLIC:
564
+ tmp = pubkey->ToString ();
565
+ break ;
555
566
}
556
567
ret += std::move (tmp);
557
568
}
558
569
std::string subscript;
559
- if (!ToStringSubScriptHelper (arg, subscript, priv, normalized )) return false ;
570
+ if (!ToStringSubScriptHelper (arg, subscript, type )) return false ;
560
571
if (pos && subscript.size ()) ret += ' ,' ;
561
572
out = std::move (ret) + std::move (subscript) + " )" ;
562
573
return true ;
@@ -565,20 +576,20 @@ class DescriptorImpl : public Descriptor
565
576
std::string ToString () const final
566
577
{
567
578
std::string ret;
568
- ToStringHelper (nullptr , ret, false , false );
579
+ ToStringHelper (nullptr , ret, StringType::PUBLIC );
569
580
return AddChecksum (ret);
570
581
}
571
582
572
583
bool ToPrivateString (const SigningProvider& arg, std::string& out) const final
573
584
{
574
- bool ret = ToStringHelper (&arg, out, true , false );
585
+ bool ret = ToStringHelper (&arg, out, StringType::PRIVATE );
575
586
out = AddChecksum (out);
576
587
return ret;
577
588
}
578
589
579
590
bool ToNormalizedString (const SigningProvider& arg, std::string& out) const override final
580
591
{
581
- bool ret = ToStringHelper (&arg, out, false , true );
592
+ bool ret = ToStringHelper (&arg, out, StringType::NORMALIZED );
582
593
out = AddChecksum (out);
583
594
return ret;
584
595
}
@@ -832,7 +843,7 @@ class TRDescriptor final : public DescriptorImpl
832
843
out.tr_spenddata [output].Merge (builder.GetSpendData ());
833
844
return Vector (GetScriptForDestination (output));
834
845
}
835
- bool ToStringSubScriptHelper (const SigningProvider* arg, std::string& ret, bool priv, bool normalized ) const override
846
+ bool ToStringSubScriptHelper (const SigningProvider* arg, std::string& ret, const StringType type ) const override
836
847
{
837
848
if (m_depths.empty ()) return true ;
838
849
std::vector<bool > path;
@@ -843,7 +854,7 @@ class TRDescriptor final : public DescriptorImpl
843
854
path.push_back (false );
844
855
}
845
856
std::string tmp;
846
- if (!m_subdescriptor_args[pos]->ToStringHelper (arg, tmp, priv, normalized )) return false ;
857
+ if (!m_subdescriptor_args[pos]->ToStringHelper (arg, tmp, type )) return false ;
847
858
ret += std::move (tmp);
848
859
while (!path.empty () && path.back ()) {
849
860
if (path.size () > 1 ) ret += ' }' ;
0 commit comments