Skip to content

Commit

Permalink
[refactor] Combine the ToString and ToPrivateString implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Nov 28, 2018
1 parent 24d3a7b commit 1eda33a
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/script/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,21 +251,25 @@ class DescriptorImpl : public Descriptor
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;
std::string ret = m_name + "(" + extra;
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) + ")";
Expand All @@ -274,20 +278,13 @@ class DescriptorImpl : public Descriptor

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;
Expand Down

0 comments on commit 1eda33a

Please sign in to comment.