aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2018-11-02 20:47:50 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2018-11-28 15:24:49 -0800
commit1eda33aabc15b905a1e23ffab648ecf2a8f5322b (patch)
tree091db0b0802e88505eb71a80d1f54314b030bab2
parent24d3a7b3a9e81c04505d130eb7e41885eda9d35f (diff)
[refactor] Combine the ToString and ToPrivateString implementations
-rw-r--r--src/script/descriptor.cpp27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp
index 44e6112f2d..adb5d20edb 100644
--- a/src/script/descriptor.cpp
+++ b/src/script/descriptor.cpp
@@ -251,7 +251,7 @@ public:
return false;
}
- bool ToPrivateString(const SigningProvider& arg, std::string& out) const final
+ bool ToStringHelper(const SigningProvider* arg, std::string& out, bool priv) const
{
std::string extra = ToStringExtra();
size_t pos = extra.size() > 0 ? 1 : 0;
@@ -259,13 +259,17 @@ public:
for (const auto& pubkey : m_pubkey_args) {
if (pos++) ret += ",";
std::string tmp;
- if (!pubkey->ToPrivateString(arg, tmp)) return false;
+ if (priv) {
+ if (!pubkey->ToPrivateString(*arg, tmp)) return false;
+ } else {
+ tmp = pubkey->ToString();
+ }
ret += std::move(tmp);
}
if (m_script_arg) {
if (pos++) ret += ",";
std::string tmp;
- if (!m_script_arg->ToPrivateString(arg, tmp)) return false;
+ if (!m_script_arg->ToStringHelper(arg, tmp, priv)) return false;
ret += std::move(tmp);
}
out = std::move(ret) + ")";
@@ -274,20 +278,13 @@ public:
std::string ToString() const final
{
- std::string extra = ToStringExtra();
- size_t pos = extra.size() > 0 ? 1 : 0;
- std::string ret = m_name + "(" + extra;
- for (const auto& pubkey : m_pubkey_args) {
- if (pos++) ret += ",";
- ret += pubkey->ToString();
- }
- if (m_script_arg) {
- if (pos++) ret += ",";
- ret += m_script_arg->ToString();
- }
- return std::move(ret) + ")";
+ std::string ret;
+ ToStringHelper(nullptr, ret, false);
+ return ret;
}
+ bool ToPrivateString(const SigningProvider& arg, std::string& out) const override final { return ToStringHelper(&arg, out, true); }
+
bool Expand(int pos, const SigningProvider& arg, std::vector<CScript>& output_scripts, FlatSigningProvider& out) const final
{
std::vector<std::pair<CPubKey, KeyOriginInfo>> entries;