aboutsummaryrefslogtreecommitdiff
path: root/src/script/descriptor.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter@wuille.net>2021-02-07 19:18:07 -0800
committerPieter Wuille <pieter@wuille.net>2021-03-29 17:44:07 -0700
commit17e006ff8d5e42f22474c5191d1b745bbc97571f (patch)
treec085dd32cf856ac73a23e7d7268ef23043e63390 /src/script/descriptor.cpp
parent6ba5dda0c9de75196c6a427d9e59d39e5a41bff7 (diff)
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.
Diffstat (limited to 'src/script/descriptor.cpp')
-rw-r--r--src/script/descriptor.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp
index a1ef23ea1a..6253f1b2b0 100644
--- a/src/script/descriptor.cpp
+++ b/src/script/descriptor.cpp
@@ -525,6 +525,18 @@ public:
return false;
}
+ virtual bool ToStringSubScriptHelper(const SigningProvider* arg, std::string& ret, bool priv, bool normalized) const
+ {
+ size_t pos = 0;
+ for (const auto& scriptarg : m_subdescriptor_args) {
+ if (pos++) ret += ",";
+ std::string tmp;
+ if (!scriptarg->ToStringHelper(arg, tmp, priv, normalized)) return false;
+ ret += std::move(tmp);
+ }
+ return true;
+ }
+
bool ToStringHelper(const SigningProvider* arg, std::string& out, bool priv, bool normalized) const
{
std::string extra = ToStringExtra();
@@ -542,13 +554,10 @@ public:
}
ret += std::move(tmp);
}
- for (const auto& scriptarg : m_subdescriptor_args) {
- if (pos++) ret += ",";
- std::string tmp;
- if (!scriptarg->ToStringHelper(arg, tmp, priv, normalized)) return false;
- ret += std::move(tmp);
- }
- out = std::move(ret) + ")";
+ std::string subscript;
+ if (!ToStringSubScriptHelper(arg, subscript, priv, normalized)) return false;
+ if (pos && subscript.size()) ret += ',';
+ out = std::move(ret) + std::move(subscript) + ")";
return true;
}