in db58563a34949fbcf8bb4e477622400a8b4be5f5 descriptor: Explicitly handle use_apostrophe cases
The code is duplicated from OriginString. Maybe a helper function?
<details>
<summary>diff</summary>
$ git diff
diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp
index 00028a6eb7..b3f09202cc 100644
--- a/src/script/descriptor.cpp
+++ b/src/script/descriptor.cpp
@@ -249,6 +249,26 @@ public:
/** Whether this PubkeyProvider can always provide a public key without cache or private key arguments */
virtual bool CanSelfExpand() const = 0;
+
+protected:
+ virtual bool UseApostrophe(StringType type, bool normalized, bool apostrophe) const
+ {
+ bool use_apostrophe{false};
+ switch (type) {
+ case StringType::COMPAT:
+ // COMPAT always uses apostrophe to stay compatible with previous versions
+ use_apostrophe = true;
+ break;
+ case StringType::CANONICAL:
+ // CANONICAL always uses h
+ use_apostrophe = false;
+ break;
+ case StringType::PUBLIC:
+ use_apostrophe = (!normalized && apostrophe) ? true : false;
+ break;
+ } // no default case, so the compiler can warn about missing cases
+ return use_apostrophe;
+ }
};
class OriginPubkeyProvider final : public PubkeyProvider
@@ -259,20 +279,7 @@ class OriginPubkeyProvider final : public PubkeyProvider
std::string OriginString(StringType type, bool normalized=false) const
{
- bool use_apostrophe{false};
- switch (type) {
- case StringType::COMPAT:
- // COMPAT always uses apostrophe to stay compatible with previous versions
- use_apostrophe = true;
- break;
- case StringType::CANONICAL:
- // CANONICAL always uses h
- use_apostrophe = false;
- break;
- case StringType::PUBLIC:
- use_apostrophe = (!normalized && m_apostrophe) ? true : false;
- break;
- } // no default case, so the compiler can warn about missing cases
+ bool use_apostrophe{UseApostrophe(type, normalized, m_apostrophe)};
return HexStr(m_origin.fingerprint) + FormatHDKeypath(m_origin.path, use_apostrophe);
}
@@ -521,20 +528,7 @@ public:
}
std::string ToString(StringType type, bool normalized) const
{
- bool use_apostrophe{false};
- switch (type) {
- case StringType::COMPAT:
- // COMPAT always uses apostrophe to stay compatible with previous versions
- use_apostrophe = true;
- break;
- case StringType::CANONICAL:
- // CANONICAL always uses h
- use_apostrophe = false;
- break;
- case StringType::PUBLIC:
- use_apostrophe = (!normalized && m_apostrophe) ? true : false;
- break;
- } // no default case, so the compiler can warn about missing cases
+ bool use_apostrophe{UseApostrophe(type, normalized, m_apostrophe)};
std::string ret = EncodeExtPubKey(m_root_extkey) + FormatHDKeypath(m_path, /*apostrophe=*/use_apostrophe);
if (IsRange()) {
ret += "/*";
</details>