mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-16 11:53:07 +02:00
Remove priv option for ToNormalizedString
This commit is contained in:
parent
74fede3b8b
commit
75530c93a8
@ -181,7 +181,7 @@ public:
|
|||||||
virtual bool ToPrivateString(const SigningProvider& arg, std::string& out) const = 0;
|
virtual bool ToPrivateString(const SigningProvider& arg, std::string& out) const = 0;
|
||||||
|
|
||||||
/** Get the descriptor string form with the xpub at the last hardened derivation */
|
/** Get the descriptor string form with the xpub at the last hardened derivation */
|
||||||
virtual bool ToNormalizedString(const SigningProvider& arg, std::string& out, bool priv) const = 0;
|
virtual bool ToNormalizedString(const SigningProvider& arg, std::string& out) const = 0;
|
||||||
|
|
||||||
/** Derive a private key, if private data is available in arg. */
|
/** Derive a private key, if private data is available in arg. */
|
||||||
virtual bool GetPrivKey(int pos, const SigningProvider& arg, CKey& key) const = 0;
|
virtual bool GetPrivKey(int pos, const SigningProvider& arg, CKey& key) const = 0;
|
||||||
@ -216,10 +216,10 @@ public:
|
|||||||
ret = "[" + OriginString() + "]" + std::move(sub);
|
ret = "[" + OriginString() + "]" + std::move(sub);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool ToNormalizedString(const SigningProvider& arg, std::string& ret, bool priv) const override
|
bool ToNormalizedString(const SigningProvider& arg, std::string& ret) const override
|
||||||
{
|
{
|
||||||
std::string sub;
|
std::string sub;
|
||||||
if (!m_provider->ToNormalizedString(arg, sub, priv)) return false;
|
if (!m_provider->ToNormalizedString(arg, sub)) return false;
|
||||||
// If m_provider is a BIP32PubkeyProvider, we may get a string formatted like a OriginPubkeyProvider
|
// If m_provider is a BIP32PubkeyProvider, we may get a string formatted like a OriginPubkeyProvider
|
||||||
// In that case, we need to strip out the leading square bracket and fingerprint from the substring,
|
// In that case, we need to strip out the leading square bracket and fingerprint from the substring,
|
||||||
// and append that to our own origin string.
|
// and append that to our own origin string.
|
||||||
@ -263,9 +263,8 @@ public:
|
|||||||
ret = EncodeSecret(key);
|
ret = EncodeSecret(key);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool ToNormalizedString(const SigningProvider& arg, std::string& ret, bool priv) const override
|
bool ToNormalizedString(const SigningProvider& arg, std::string& ret) const override
|
||||||
{
|
{
|
||||||
if (priv) return ToPrivateString(arg, ret);
|
|
||||||
ret = ToString();
|
ret = ToString();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -413,11 +412,10 @@ public:
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool ToNormalizedString(const SigningProvider& arg, std::string& out, bool priv) const override
|
bool ToNormalizedString(const SigningProvider& arg, std::string& out) const override
|
||||||
{
|
{
|
||||||
// For hardened derivation type, just return the typical string, nothing to normalize
|
// For hardened derivation type, just return the typical string, nothing to normalize
|
||||||
if (m_derive == DeriveType::HARDENED) {
|
if (m_derive == DeriveType::HARDENED) {
|
||||||
if (priv) return ToPrivateString(arg, out);
|
|
||||||
out = ToString();
|
out = ToString();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -430,7 +428,6 @@ public:
|
|||||||
}
|
}
|
||||||
// Either no derivation or all unhardened derivation
|
// Either no derivation or all unhardened derivation
|
||||||
if (i == -1) {
|
if (i == -1) {
|
||||||
if (priv) return ToPrivateString(arg, out);
|
|
||||||
out = ToString();
|
out = ToString();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -456,7 +453,7 @@ public:
|
|||||||
}
|
}
|
||||||
// Build the string
|
// Build the string
|
||||||
std::string origin_str = HexStr(origin.fingerprint) + FormatHDKeypath(origin.path);
|
std::string origin_str = HexStr(origin.fingerprint) + FormatHDKeypath(origin.path);
|
||||||
out = "[" + origin_str + "]" + (priv ? EncodeExtKey(xprv) : EncodeExtPubKey(xprv.Neuter())) + FormatHDKeypath(end_path);
|
out = "[" + origin_str + "]" + EncodeExtPubKey(xprv.Neuter()) + FormatHDKeypath(end_path);
|
||||||
if (IsRange()) {
|
if (IsRange()) {
|
||||||
out += "/*";
|
out += "/*";
|
||||||
assert(m_derive == DeriveType::UNHARDENED);
|
assert(m_derive == DeriveType::UNHARDENED);
|
||||||
@ -550,7 +547,7 @@ public:
|
|||||||
if (pos++) ret += ",";
|
if (pos++) ret += ",";
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
if (normalized) {
|
if (normalized) {
|
||||||
if (!pubkey->ToNormalizedString(*arg, tmp, priv)) return false;
|
if (!pubkey->ToNormalizedString(*arg, tmp)) return false;
|
||||||
} else if (priv) {
|
} else if (priv) {
|
||||||
if (!pubkey->ToPrivateString(*arg, tmp)) return false;
|
if (!pubkey->ToPrivateString(*arg, tmp)) return false;
|
||||||
} else {
|
} else {
|
||||||
@ -579,9 +576,9 @@ public:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ToNormalizedString(const SigningProvider& arg, std::string& out, bool priv) const override final
|
bool ToNormalizedString(const SigningProvider& arg, std::string& out) const override final
|
||||||
{
|
{
|
||||||
bool ret = ToStringHelper(&arg, out, priv, true);
|
bool ret = ToStringHelper(&arg, out, false, true);
|
||||||
out = AddChecksum(out);
|
out = AddChecksum(out);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ struct Descriptor {
|
|||||||
virtual bool ToPrivateString(const SigningProvider& provider, std::string& out) const = 0;
|
virtual bool ToPrivateString(const SigningProvider& provider, std::string& out) const = 0;
|
||||||
|
|
||||||
/** 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. */
|
/** 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. */
|
||||||
virtual bool ToNormalizedString(const SigningProvider& provider, std::string& out, bool priv) const = 0;
|
virtual bool ToNormalizedString(const SigningProvider& provider, std::string& out) const = 0;
|
||||||
|
|
||||||
/** Expand a descriptor at a specified position.
|
/** Expand a descriptor at a specified position.
|
||||||
*
|
*
|
||||||
|
@ -124,14 +124,10 @@ void DoCheck(const std::string& prv, const std::string& pub, const std::string&
|
|||||||
|
|
||||||
// Check that private can produce the normalized descriptors
|
// Check that private can produce the normalized descriptors
|
||||||
std::string norm1;
|
std::string norm1;
|
||||||
BOOST_CHECK(parse_priv->ToNormalizedString(keys_priv, norm1, false));
|
BOOST_CHECK(parse_priv->ToNormalizedString(keys_priv, norm1));
|
||||||
BOOST_CHECK(EqualDescriptor(norm1, norm_pub));
|
BOOST_CHECK(EqualDescriptor(norm1, norm_pub));
|
||||||
BOOST_CHECK(parse_pub->ToNormalizedString(keys_priv, norm1, false));
|
BOOST_CHECK(parse_pub->ToNormalizedString(keys_priv, norm1));
|
||||||
BOOST_CHECK(EqualDescriptor(norm1, norm_pub));
|
BOOST_CHECK(EqualDescriptor(norm1, norm_pub));
|
||||||
BOOST_CHECK(parse_priv->ToNormalizedString(keys_priv, norm1, true));
|
|
||||||
BOOST_CHECK(EqualDescriptor(norm1, norm_prv));
|
|
||||||
BOOST_CHECK(parse_pub->ToNormalizedString(keys_priv, norm1, true));
|
|
||||||
BOOST_CHECK(EqualDescriptor(norm1, norm_prv));
|
|
||||||
|
|
||||||
// Check whether IsRange on both returns the expected result
|
// Check whether IsRange on both returns the expected result
|
||||||
BOOST_CHECK_EQUAL(parse_pub->IsRange(), (flags & RANGE) != 0);
|
BOOST_CHECK_EQUAL(parse_pub->IsRange(), (flags & RANGE) != 0);
|
||||||
|
@ -1802,7 +1802,7 @@ RPCHelpMan listdescriptors()
|
|||||||
LOCK(desc_spk_man->cs_desc_man);
|
LOCK(desc_spk_man->cs_desc_man);
|
||||||
const auto& wallet_descriptor = desc_spk_man->GetWalletDescriptor();
|
const auto& wallet_descriptor = desc_spk_man->GetWalletDescriptor();
|
||||||
std::string descriptor;
|
std::string descriptor;
|
||||||
if (!desc_spk_man->GetDescriptorString(descriptor, false)) {
|
if (!desc_spk_man->GetDescriptorString(descriptor)) {
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, "Can't get normalized descriptor string.");
|
throw JSONRPCError(RPC_WALLET_ERROR, "Can't get normalized descriptor string.");
|
||||||
}
|
}
|
||||||
spk.pushKV("desc", descriptor);
|
spk.pushKV("desc", descriptor);
|
||||||
|
@ -3872,7 +3872,7 @@ RPCHelpMan getaddressinfo()
|
|||||||
DescriptorScriptPubKeyMan* desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(pwallet->GetScriptPubKeyMan(scriptPubKey));
|
DescriptorScriptPubKeyMan* desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(pwallet->GetScriptPubKeyMan(scriptPubKey));
|
||||||
if (desc_spk_man) {
|
if (desc_spk_man) {
|
||||||
std::string desc_str;
|
std::string desc_str;
|
||||||
if (desc_spk_man->GetDescriptorString(desc_str, false)) {
|
if (desc_spk_man->GetDescriptorString(desc_str)) {
|
||||||
ret.pushKV("parent_desc", desc_str);
|
ret.pushKV("parent_desc", desc_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2266,7 +2266,7 @@ const std::vector<CScript> DescriptorScriptPubKeyMan::GetScriptPubKeys() const
|
|||||||
return script_pub_keys;
|
return script_pub_keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DescriptorScriptPubKeyMan::GetDescriptorString(std::string& out, bool priv) const
|
bool DescriptorScriptPubKeyMan::GetDescriptorString(std::string& out) const
|
||||||
{
|
{
|
||||||
LOCK(cs_desc_man);
|
LOCK(cs_desc_man);
|
||||||
if (m_storage.IsLocked()) {
|
if (m_storage.IsLocked()) {
|
||||||
@ -2276,7 +2276,7 @@ bool DescriptorScriptPubKeyMan::GetDescriptorString(std::string& out, bool priv)
|
|||||||
FlatSigningProvider provider;
|
FlatSigningProvider provider;
|
||||||
provider.keys = GetKeys();
|
provider.keys = GetKeys();
|
||||||
|
|
||||||
return m_wallet_descriptor.descriptor->ToNormalizedString(provider, out, priv);
|
return m_wallet_descriptor.descriptor->ToNormalizedString(provider, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DescriptorScriptPubKeyMan::UpgradeDescriptorCache()
|
void DescriptorScriptPubKeyMan::UpgradeDescriptorCache()
|
||||||
|
@ -630,7 +630,7 @@ public:
|
|||||||
const WalletDescriptor GetWalletDescriptor() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
|
const WalletDescriptor GetWalletDescriptor() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
|
||||||
const std::vector<CScript> GetScriptPubKeys() const;
|
const std::vector<CScript> GetScriptPubKeys() const;
|
||||||
|
|
||||||
bool GetDescriptorString(std::string& out, bool priv) const;
|
bool GetDescriptorString(std::string& out) const;
|
||||||
|
|
||||||
void UpgradeDescriptorCache();
|
void UpgradeDescriptorCache();
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user