Skip to content

Commit 17e006f

Browse files
committed
refactor: split off subscript logic from ToStringHelper
This will allow subclasses to overwrite the serialization of subscript arguments without needing to reimplement all the rest of the ToString logic.
1 parent 6ba5dda commit 17e006f

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/script/descriptor.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,18 @@ class DescriptorImpl : public Descriptor
525525
return false;
526526
}
527527

528+
virtual bool ToStringSubScriptHelper(const SigningProvider* arg, std::string& ret, bool priv, bool normalized) const
529+
{
530+
size_t pos = 0;
531+
for (const auto& scriptarg : m_subdescriptor_args) {
532+
if (pos++) ret += ",";
533+
std::string tmp;
534+
if (!scriptarg->ToStringHelper(arg, tmp, priv, normalized)) return false;
535+
ret += std::move(tmp);
536+
}
537+
return true;
538+
}
539+
528540
bool ToStringHelper(const SigningProvider* arg, std::string& out, bool priv, bool normalized) const
529541
{
530542
std::string extra = ToStringExtra();
@@ -542,13 +554,10 @@ class DescriptorImpl : public Descriptor
542554
}
543555
ret += std::move(tmp);
544556
}
545-
for (const auto& scriptarg : m_subdescriptor_args) {
546-
if (pos++) ret += ",";
547-
std::string tmp;
548-
if (!scriptarg->ToStringHelper(arg, tmp, priv, normalized)) return false;
549-
ret += std::move(tmp);
550-
}
551-
out = std::move(ret) + ")";
557+
std::string subscript;
558+
if (!ToStringSubScriptHelper(arg, subscript, priv, normalized)) return false;
559+
if (pos && subscript.size()) ret += ',';
560+
out = std::move(ret) + std::move(subscript) + ")";
552561
return true;
553562
}
554563

0 commit comments

Comments
 (0)