Skip to content

Commit 75530c9

Browse files
committed
Remove priv option for ToNormalizedString
1 parent 74fede3 commit 75530c9

File tree

7 files changed

+17
-24
lines changed

7 files changed

+17
-24
lines changed

src/script/descriptor.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ struct PubkeyProvider
181181
virtual bool ToPrivateString(const SigningProvider& arg, std::string& out) const = 0;
182182

183183
/** Get the descriptor string form with the xpub at the last hardened derivation */
184-
virtual bool ToNormalizedString(const SigningProvider& arg, std::string& out, bool priv) const = 0;
184+
virtual bool ToNormalizedString(const SigningProvider& arg, std::string& out) const = 0;
185185

186186
/** Derive a private key, if private data is available in arg. */
187187
virtual bool GetPrivKey(int pos, const SigningProvider& arg, CKey& key) const = 0;
@@ -216,10 +216,10 @@ class OriginPubkeyProvider final : public PubkeyProvider
216216
ret = "[" + OriginString() + "]" + std::move(sub);
217217
return true;
218218
}
219-
bool ToNormalizedString(const SigningProvider& arg, std::string& ret, bool priv) const override
219+
bool ToNormalizedString(const SigningProvider& arg, std::string& ret) const override
220220
{
221221
std::string sub;
222-
if (!m_provider->ToNormalizedString(arg, sub, priv)) return false;
222+
if (!m_provider->ToNormalizedString(arg, sub)) return false;
223223
// If m_provider is a BIP32PubkeyProvider, we may get a string formatted like a OriginPubkeyProvider
224224
// In that case, we need to strip out the leading square bracket and fingerprint from the substring,
225225
// and append that to our own origin string.
@@ -263,9 +263,8 @@ class ConstPubkeyProvider final : public PubkeyProvider
263263
ret = EncodeSecret(key);
264264
return true;
265265
}
266-
bool ToNormalizedString(const SigningProvider& arg, std::string& ret, bool priv) const override
266+
bool ToNormalizedString(const SigningProvider& arg, std::string& ret) const override
267267
{
268-
if (priv) return ToPrivateString(arg, ret);
269268
ret = ToString();
270269
return true;
271270
}
@@ -413,11 +412,10 @@ class BIP32PubkeyProvider final : public PubkeyProvider
413412
}
414413
return true;
415414
}
416-
bool ToNormalizedString(const SigningProvider& arg, std::string& out, bool priv) const override
415+
bool ToNormalizedString(const SigningProvider& arg, std::string& out) const override
417416
{
418417
// For hardened derivation type, just return the typical string, nothing to normalize
419418
if (m_derive == DeriveType::HARDENED) {
420-
if (priv) return ToPrivateString(arg, out);
421419
out = ToString();
422420
return true;
423421
}
@@ -430,7 +428,6 @@ class BIP32PubkeyProvider final : public PubkeyProvider
430428
}
431429
// Either no derivation or all unhardened derivation
432430
if (i == -1) {
433-
if (priv) return ToPrivateString(arg, out);
434431
out = ToString();
435432
return true;
436433
}
@@ -456,7 +453,7 @@ class BIP32PubkeyProvider final : public PubkeyProvider
456453
}
457454
// Build the string
458455
std::string origin_str = HexStr(origin.fingerprint) + FormatHDKeypath(origin.path);
459-
out = "[" + origin_str + "]" + (priv ? EncodeExtKey(xprv) : EncodeExtPubKey(xprv.Neuter())) + FormatHDKeypath(end_path);
456+
out = "[" + origin_str + "]" + EncodeExtPubKey(xprv.Neuter()) + FormatHDKeypath(end_path);
460457
if (IsRange()) {
461458
out += "/*";
462459
assert(m_derive == DeriveType::UNHARDENED);
@@ -550,7 +547,7 @@ class DescriptorImpl : public Descriptor
550547
if (pos++) ret += ",";
551548
std::string tmp;
552549
if (normalized) {
553-
if (!pubkey->ToNormalizedString(*arg, tmp, priv)) return false;
550+
if (!pubkey->ToNormalizedString(*arg, tmp)) return false;
554551
} else if (priv) {
555552
if (!pubkey->ToPrivateString(*arg, tmp)) return false;
556553
} else {
@@ -579,9 +576,9 @@ class DescriptorImpl : public Descriptor
579576
return ret;
580577
}
581578

582-
bool ToNormalizedString(const SigningProvider& arg, std::string& out, bool priv) const override final
579+
bool ToNormalizedString(const SigningProvider& arg, std::string& out) const override final
583580
{
584-
bool ret = ToStringHelper(&arg, out, priv, true);
581+
bool ret = ToStringHelper(&arg, out, false, true);
585582
out = AddChecksum(out);
586583
return ret;
587584
}

src/script/descriptor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ struct Descriptor {
115115
virtual bool ToPrivateString(const SigningProvider& provider, std::string& out) const = 0;
116116

117117
/** Convert the descriptor to a normalized string. Normalized descriptors have the xpub at the last hardened step. This fails if the provided provider does not have the private keys to derive that xpub. */
118-
virtual bool ToNormalizedString(const SigningProvider& provider, std::string& out, bool priv) const = 0;
118+
virtual bool ToNormalizedString(const SigningProvider& provider, std::string& out) const = 0;
119119

120120
/** Expand a descriptor at a specified position.
121121
*

src/test/descriptor_tests.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,10 @@ void DoCheck(const std::string& prv, const std::string& pub, const std::string&
124124

125125
// Check that private can produce the normalized descriptors
126126
std::string norm1;
127-
BOOST_CHECK(parse_priv->ToNormalizedString(keys_priv, norm1, false));
127+
BOOST_CHECK(parse_priv->ToNormalizedString(keys_priv, norm1));
128128
BOOST_CHECK(EqualDescriptor(norm1, norm_pub));
129-
BOOST_CHECK(parse_pub->ToNormalizedString(keys_priv, norm1, false));
129+
BOOST_CHECK(parse_pub->ToNormalizedString(keys_priv, norm1));
130130
BOOST_CHECK(EqualDescriptor(norm1, norm_pub));
131-
BOOST_CHECK(parse_priv->ToNormalizedString(keys_priv, norm1, true));
132-
BOOST_CHECK(EqualDescriptor(norm1, norm_prv));
133-
BOOST_CHECK(parse_pub->ToNormalizedString(keys_priv, norm1, true));
134-
BOOST_CHECK(EqualDescriptor(norm1, norm_prv));
135131

136132
// Check whether IsRange on both returns the expected result
137133
BOOST_CHECK_EQUAL(parse_pub->IsRange(), (flags & RANGE) != 0);

src/wallet/rpcdump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@ RPCHelpMan listdescriptors()
18021802
LOCK(desc_spk_man->cs_desc_man);
18031803
const auto& wallet_descriptor = desc_spk_man->GetWalletDescriptor();
18041804
std::string descriptor;
1805-
if (!desc_spk_man->GetDescriptorString(descriptor, false)) {
1805+
if (!desc_spk_man->GetDescriptorString(descriptor)) {
18061806
throw JSONRPCError(RPC_WALLET_ERROR, "Can't get normalized descriptor string.");
18071807
}
18081808
spk.pushKV("desc", descriptor);

src/wallet/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3872,7 +3872,7 @@ RPCHelpMan getaddressinfo()
38723872
DescriptorScriptPubKeyMan* desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(pwallet->GetScriptPubKeyMan(scriptPubKey));
38733873
if (desc_spk_man) {
38743874
std::string desc_str;
3875-
if (desc_spk_man->GetDescriptorString(desc_str, false)) {
3875+
if (desc_spk_man->GetDescriptorString(desc_str)) {
38763876
ret.pushKV("parent_desc", desc_str);
38773877
}
38783878
}

src/wallet/scriptpubkeyman.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,7 @@ const std::vector<CScript> DescriptorScriptPubKeyMan::GetScriptPubKeys() const
22662266
return script_pub_keys;
22672267
}
22682268

2269-
bool DescriptorScriptPubKeyMan::GetDescriptorString(std::string& out, bool priv) const
2269+
bool DescriptorScriptPubKeyMan::GetDescriptorString(std::string& out) const
22702270
{
22712271
LOCK(cs_desc_man);
22722272
if (m_storage.IsLocked()) {
@@ -2276,7 +2276,7 @@ bool DescriptorScriptPubKeyMan::GetDescriptorString(std::string& out, bool priv)
22762276
FlatSigningProvider provider;
22772277
provider.keys = GetKeys();
22782278

2279-
return m_wallet_descriptor.descriptor->ToNormalizedString(provider, out, priv);
2279+
return m_wallet_descriptor.descriptor->ToNormalizedString(provider, out);
22802280
}
22812281

22822282
void DescriptorScriptPubKeyMan::UpgradeDescriptorCache()

src/wallet/scriptpubkeyman.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan
630630
const WalletDescriptor GetWalletDescriptor() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
631631
const std::vector<CScript> GetScriptPubKeys() const;
632632

633-
bool GetDescriptorString(std::string& out, bool priv) const;
633+
bool GetDescriptorString(std::string& out) const;
634634

635635
void UpgradeDescriptorCache();
636636
};

0 commit comments

Comments
 (0)