mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-23 15:22:46 +02:00
Remove SetCrypted() and fUseCrypto; Change IsCrypted()'s implementation
Removes SetCrypted() and fUseCrypto as we don't need them anymore. SetCrypted calls in LegacyScriptPubKeyMan are replaced with mapKeys.empty() IsCrypted() is changed to just call HasEncryptionKeys()
This commit is contained in:
parent
77a777118e
commit
bf6417142f
@ -206,8 +206,7 @@ bool LegacyScriptPubKeyMan::CheckDecryptionKey(const CKeyingMaterial& master_key
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
if (!SetCrypted())
|
assert(mapKeys.empty());
|
||||||
return false;
|
|
||||||
|
|
||||||
bool keyPass = mapCryptedKeys.empty(); // Always pass when there are no encrypted keys
|
bool keyPass = mapCryptedKeys.empty(); // Always pass when there are no encrypted keys
|
||||||
bool keyFail = false;
|
bool keyFail = false;
|
||||||
@ -243,12 +242,11 @@ bool LegacyScriptPubKeyMan::Encrypt(const CKeyingMaterial& master_key, WalletBat
|
|||||||
AssertLockHeld(cs_wallet);
|
AssertLockHeld(cs_wallet);
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
encrypted_batch = batch;
|
encrypted_batch = batch;
|
||||||
if (!mapCryptedKeys.empty() || IsCrypted()) {
|
if (!mapCryptedKeys.empty()) {
|
||||||
encrypted_batch = nullptr;
|
encrypted_batch = nullptr;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fUseCrypto = true;
|
|
||||||
KeyMap keys_to_encrypt;
|
KeyMap keys_to_encrypt;
|
||||||
keys_to_encrypt.swap(mapKeys); // Clear mapKeys so AddCryptedKeyInner will succeed.
|
keys_to_encrypt.swap(mapKeys); // Clear mapKeys so AddCryptedKeyInner will succeed.
|
||||||
for (const KeyMap::value_type& mKey : keys_to_encrypt)
|
for (const KeyMap::value_type& mKey : keys_to_encrypt)
|
||||||
@ -620,9 +618,7 @@ bool LegacyScriptPubKeyMan::LoadCryptedKey(const CPubKey &vchPubKey, const std::
|
|||||||
bool LegacyScriptPubKeyMan::AddCryptedKeyInner(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret)
|
bool LegacyScriptPubKeyMan::AddCryptedKeyInner(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret)
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
if (!SetCrypted()) {
|
assert(mapKeys.empty());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
mapCryptedKeys[vchPubKey.GetID()] = make_pair(vchPubKey, vchCryptedSecret);
|
mapCryptedKeys[vchPubKey.GetID()] = make_pair(vchPubKey, vchCryptedSecret);
|
||||||
ImplicitlyLearnRelatedKeyScripts(vchPubKey);
|
ImplicitlyLearnRelatedKeyScripts(vchPubKey);
|
||||||
@ -1405,10 +1401,8 @@ std::set<CKeyID> LegacyScriptPubKeyMan::GetKeys() const
|
|||||||
LegacyScriptPubKeyMan::LegacyScriptPubKeyMan(CWallet& wallet)
|
LegacyScriptPubKeyMan::LegacyScriptPubKeyMan(CWallet& wallet)
|
||||||
: ScriptPubKeyMan(wallet),
|
: ScriptPubKeyMan(wallet),
|
||||||
m_wallet(wallet),
|
m_wallet(wallet),
|
||||||
cs_wallet(wallet.cs_wallet),
|
cs_wallet(wallet.cs_wallet) {}
|
||||||
fUseCrypto(wallet.fUseCrypto) {}
|
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::SetCrypted() { return m_wallet.SetCrypted(); }
|
|
||||||
bool LegacyScriptPubKeyMan::IsCrypted() const { return m_wallet.IsCrypted(); }
|
bool LegacyScriptPubKeyMan::IsCrypted() const { return m_wallet.IsCrypted(); }
|
||||||
void LegacyScriptPubKeyMan::NotifyWatchonlyChanged(bool fHaveWatchOnly) const { return m_wallet.NotifyWatchonlyChanged(fHaveWatchOnly); }
|
void LegacyScriptPubKeyMan::NotifyWatchonlyChanged(bool fHaveWatchOnly) const { return m_wallet.NotifyWatchonlyChanged(fHaveWatchOnly); }
|
||||||
void LegacyScriptPubKeyMan::NotifyCanGetAddressesChanged() const { return m_wallet.NotifyCanGetAddressesChanged(); }
|
void LegacyScriptPubKeyMan::NotifyCanGetAddressesChanged() const { return m_wallet.NotifyCanGetAddressesChanged(); }
|
||||||
|
@ -412,14 +412,12 @@ public:
|
|||||||
friend class CWallet;
|
friend class CWallet;
|
||||||
friend class ReserveDestination;
|
friend class ReserveDestination;
|
||||||
LegacyScriptPubKeyMan(CWallet& wallet);
|
LegacyScriptPubKeyMan(CWallet& wallet);
|
||||||
bool SetCrypted();
|
|
||||||
bool IsCrypted() const;
|
bool IsCrypted() const;
|
||||||
void NotifyWatchonlyChanged(bool fHaveWatchOnly) const;
|
void NotifyWatchonlyChanged(bool fHaveWatchOnly) const;
|
||||||
void NotifyCanGetAddressesChanged() const;
|
void NotifyCanGetAddressesChanged() const;
|
||||||
template<typename... Params> void WalletLogPrintf(const std::string& fmt, const Params&... parameters) const;
|
template<typename... Params> void WalletLogPrintf(const std::string& fmt, const Params&... parameters) const;
|
||||||
CWallet& m_wallet;
|
CWallet& m_wallet;
|
||||||
CCriticalSection& cs_wallet;
|
CCriticalSection& cs_wallet;
|
||||||
std::atomic<bool>& fUseCrypto;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BITCOIN_WALLET_SCRIPTPUBKEYMAN_H
|
#endif // BITCOIN_WALLET_SCRIPTPUBKEYMAN_H
|
||||||
|
@ -4002,15 +4002,9 @@ std::vector<OutputGroup> CWallet::GroupOutputs(const std::vector<COutput>& outpu
|
|||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::SetCrypted()
|
bool CWallet::IsCrypted() const
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
return HasEncryptionKeys();
|
||||||
if (fUseCrypto)
|
|
||||||
return true;
|
|
||||||
if (!mapKeys.empty())
|
|
||||||
return false;
|
|
||||||
fUseCrypto = true;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::IsLocked() const
|
bool CWallet::IsLocked() const
|
||||||
@ -4024,7 +4018,7 @@ bool CWallet::IsLocked() const
|
|||||||
|
|
||||||
bool CWallet::Lock()
|
bool CWallet::Lock()
|
||||||
{
|
{
|
||||||
if (!SetCrypted())
|
if (!IsCrypted())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -597,12 +597,7 @@ class CWallet final : public WalletStorage, private interfaces::Chain::Notificat
|
|||||||
private:
|
private:
|
||||||
CKeyingMaterial vMasterKey GUARDED_BY(cs_KeyStore);
|
CKeyingMaterial vMasterKey GUARDED_BY(cs_KeyStore);
|
||||||
|
|
||||||
//! if fUseCrypto is true, mapKeys must be empty
|
|
||||||
//! if fUseCrypto is false, vMasterKey must be empty
|
|
||||||
std::atomic<bool> fUseCrypto;
|
|
||||||
|
|
||||||
|
|
||||||
bool SetCrypted();
|
|
||||||
bool Unlock(const CKeyingMaterial& vMasterKeyIn, bool accept_no_keys = false);
|
bool Unlock(const CKeyingMaterial& vMasterKeyIn, bool accept_no_keys = false);
|
||||||
|
|
||||||
std::atomic<bool> fAbortRescan{false};
|
std::atomic<bool> fAbortRescan{false};
|
||||||
@ -732,8 +727,7 @@ public:
|
|||||||
|
|
||||||
/** Construct wallet with specified name and database implementation. */
|
/** Construct wallet with specified name and database implementation. */
|
||||||
CWallet(interfaces::Chain* chain, const WalletLocation& location, std::unique_ptr<WalletDatabase> database)
|
CWallet(interfaces::Chain* chain, const WalletLocation& location, std::unique_ptr<WalletDatabase> database)
|
||||||
: fUseCrypto(false),
|
: m_chain(chain),
|
||||||
m_chain(chain),
|
|
||||||
m_location(location),
|
m_location(location),
|
||||||
database(std::move(database))
|
database(std::move(database))
|
||||||
{
|
{
|
||||||
@ -745,7 +739,7 @@ public:
|
|||||||
assert(NotifyUnload.empty());
|
assert(NotifyUnload.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsCrypted() const { return fUseCrypto; }
|
bool IsCrypted() const;
|
||||||
bool IsLocked() const override;
|
bool IsLocked() const override;
|
||||||
bool Lock();
|
bool Lock();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user