Skip to content

Commit bf64171

Browse files
committed
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()
1 parent 77a7771 commit bf64171

File tree

4 files changed

+9
-29
lines changed

4 files changed

+9
-29
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ bool LegacyScriptPubKeyMan::CheckDecryptionKey(const CKeyingMaterial& master_key
206206
{
207207
{
208208
LOCK(cs_KeyStore);
209-
if (!SetCrypted())
210-
return false;
209+
assert(mapKeys.empty());
211210

212211
bool keyPass = mapCryptedKeys.empty(); // Always pass when there are no encrypted keys
213212
bool keyFail = false;
@@ -243,12 +242,11 @@ bool LegacyScriptPubKeyMan::Encrypt(const CKeyingMaterial& master_key, WalletBat
243242
AssertLockHeld(cs_wallet);
244243
LOCK(cs_KeyStore);
245244
encrypted_batch = batch;
246-
if (!mapCryptedKeys.empty() || IsCrypted()) {
245+
if (!mapCryptedKeys.empty()) {
247246
encrypted_batch = nullptr;
248247
return false;
249248
}
250249

251-
fUseCrypto = true;
252250
KeyMap keys_to_encrypt;
253251
keys_to_encrypt.swap(mapKeys); // Clear mapKeys so AddCryptedKeyInner will succeed.
254252
for (const KeyMap::value_type& mKey : keys_to_encrypt)
@@ -620,9 +618,7 @@ bool LegacyScriptPubKeyMan::LoadCryptedKey(const CPubKey &vchPubKey, const std::
620618
bool LegacyScriptPubKeyMan::AddCryptedKeyInner(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret)
621619
{
622620
LOCK(cs_KeyStore);
623-
if (!SetCrypted()) {
624-
return false;
625-
}
621+
assert(mapKeys.empty());
626622

627623
mapCryptedKeys[vchPubKey.GetID()] = make_pair(vchPubKey, vchCryptedSecret);
628624
ImplicitlyLearnRelatedKeyScripts(vchPubKey);
@@ -1405,10 +1401,8 @@ std::set<CKeyID> LegacyScriptPubKeyMan::GetKeys() const
14051401
LegacyScriptPubKeyMan::LegacyScriptPubKeyMan(CWallet& wallet)
14061402
: ScriptPubKeyMan(wallet),
14071403
m_wallet(wallet),
1408-
cs_wallet(wallet.cs_wallet),
1409-
fUseCrypto(wallet.fUseCrypto) {}
1404+
cs_wallet(wallet.cs_wallet) {}
14101405

1411-
bool LegacyScriptPubKeyMan::SetCrypted() { return m_wallet.SetCrypted(); }
14121406
bool LegacyScriptPubKeyMan::IsCrypted() const { return m_wallet.IsCrypted(); }
14131407
void LegacyScriptPubKeyMan::NotifyWatchonlyChanged(bool fHaveWatchOnly) const { return m_wallet.NotifyWatchonlyChanged(fHaveWatchOnly); }
14141408
void LegacyScriptPubKeyMan::NotifyCanGetAddressesChanged() const { return m_wallet.NotifyCanGetAddressesChanged(); }

src/wallet/scriptpubkeyman.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,12 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
412412
friend class CWallet;
413413
friend class ReserveDestination;
414414
LegacyScriptPubKeyMan(CWallet& wallet);
415-
bool SetCrypted();
416415
bool IsCrypted() const;
417416
void NotifyWatchonlyChanged(bool fHaveWatchOnly) const;
418417
void NotifyCanGetAddressesChanged() const;
419418
template<typename... Params> void WalletLogPrintf(const std::string& fmt, const Params&... parameters) const;
420419
CWallet& m_wallet;
421420
CCriticalSection& cs_wallet;
422-
std::atomic<bool>& fUseCrypto;
423421
};
424422

425423
#endif // BITCOIN_WALLET_SCRIPTPUBKEYMAN_H

src/wallet/wallet.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4002,15 +4002,9 @@ std::vector<OutputGroup> CWallet::GroupOutputs(const std::vector<COutput>& outpu
40024002
return groups;
40034003
}
40044004

4005-
bool CWallet::SetCrypted()
4005+
bool CWallet::IsCrypted() const
40064006
{
4007-
LOCK(cs_KeyStore);
4008-
if (fUseCrypto)
4009-
return true;
4010-
if (!mapKeys.empty())
4011-
return false;
4012-
fUseCrypto = true;
4013-
return true;
4007+
return HasEncryptionKeys();
40144008
}
40154009

40164010
bool CWallet::IsLocked() const
@@ -4024,7 +4018,7 @@ bool CWallet::IsLocked() const
40244018

40254019
bool CWallet::Lock()
40264020
{
4027-
if (!SetCrypted())
4021+
if (!IsCrypted())
40284022
return false;
40294023

40304024
{

src/wallet/wallet.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -597,12 +597,7 @@ class CWallet final : public WalletStorage, private interfaces::Chain::Notificat
597597
private:
598598
CKeyingMaterial vMasterKey GUARDED_BY(cs_KeyStore);
599599

600-
//! if fUseCrypto is true, mapKeys must be empty
601-
//! if fUseCrypto is false, vMasterKey must be empty
602-
std::atomic<bool> fUseCrypto;
603600

604-
605-
bool SetCrypted();
606601
bool Unlock(const CKeyingMaterial& vMasterKeyIn, bool accept_no_keys = false);
607602

608603
std::atomic<bool> fAbortRescan{false};
@@ -732,8 +727,7 @@ class CWallet final : public WalletStorage, private interfaces::Chain::Notificat
732727

733728
/** Construct wallet with specified name and database implementation. */
734729
CWallet(interfaces::Chain* chain, const WalletLocation& location, std::unique_ptr<WalletDatabase> database)
735-
: fUseCrypto(false),
736-
m_chain(chain),
730+
: m_chain(chain),
737731
m_location(location),
738732
database(std::move(database))
739733
{
@@ -745,7 +739,7 @@ class CWallet final : public WalletStorage, private interfaces::Chain::Notificat
745739
assert(NotifyUnload.empty());
746740
}
747741

748-
bool IsCrypted() const { return fUseCrypto; }
742+
bool IsCrypted() const;
749743
bool IsLocked() const override;
750744
bool Lock();
751745

0 commit comments

Comments
 (0)