Rename EncryptKeys to Encrypt and pass in the encrypted batch to use
This commit is contained in:
parent
35f962fcf0
commit
77a777118e
|
@ -238,11 +238,15 @@ bool LegacyScriptPubKeyMan::CheckDecryptionKey(const CKeyingMaterial& master_key
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::EncryptKeys(CKeyingMaterial& vMasterKeyIn)
|
bool LegacyScriptPubKeyMan::Encrypt(const CKeyingMaterial& master_key, WalletBatch* batch)
|
||||||
{
|
{
|
||||||
|
AssertLockHeld(cs_wallet);
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
if (!mapCryptedKeys.empty() || IsCrypted())
|
encrypted_batch = batch;
|
||||||
|
if (!mapCryptedKeys.empty() || IsCrypted()) {
|
||||||
|
encrypted_batch = nullptr;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
fUseCrypto = true;
|
fUseCrypto = true;
|
||||||
KeyMap keys_to_encrypt;
|
KeyMap keys_to_encrypt;
|
||||||
|
@ -253,11 +257,16 @@ bool LegacyScriptPubKeyMan::EncryptKeys(CKeyingMaterial& vMasterKeyIn)
|
||||||
CPubKey vchPubKey = key.GetPubKey();
|
CPubKey vchPubKey = key.GetPubKey();
|
||||||
CKeyingMaterial vchSecret(key.begin(), key.end());
|
CKeyingMaterial vchSecret(key.begin(), key.end());
|
||||||
std::vector<unsigned char> vchCryptedSecret;
|
std::vector<unsigned char> vchCryptedSecret;
|
||||||
if (!EncryptSecret(vMasterKeyIn, vchSecret, vchPubKey.GetHash(), vchCryptedSecret))
|
if (!EncryptSecret(master_key, vchSecret, vchPubKey.GetHash(), vchCryptedSecret)) {
|
||||||
return false;
|
encrypted_batch = nullptr;
|
||||||
if (!AddCryptedKey(vchPubKey, vchCryptedSecret))
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!AddCryptedKey(vchPubKey, vchCryptedSecret)) {
|
||||||
|
encrypted_batch = nullptr;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
encrypted_batch = nullptr;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,6 +154,7 @@ public:
|
||||||
|
|
||||||
//! Check that the given decryption key is valid for this ScriptPubKeyMan, i.e. it decrypts all of the keys handled by it.
|
//! Check that the given decryption key is valid for this ScriptPubKeyMan, i.e. it decrypts all of the keys handled by it.
|
||||||
virtual bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) { return false; }
|
virtual bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) { return false; }
|
||||||
|
virtual bool Encrypt(const CKeyingMaterial& master_key, WalletBatch* batch) { return false; }
|
||||||
|
|
||||||
virtual bool GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool) { return false; }
|
virtual bool GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool) { return false; }
|
||||||
virtual void KeepDestination(int64_t index, const OutputType& type) {}
|
virtual void KeepDestination(int64_t index, const OutputType& type) {}
|
||||||
|
@ -280,9 +281,8 @@ public:
|
||||||
bool GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error) override;
|
bool GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error) override;
|
||||||
isminetype IsMine(const CScript& script) const override;
|
isminetype IsMine(const CScript& script) const override;
|
||||||
|
|
||||||
//! will encrypt previously unencrypted keys
|
|
||||||
bool EncryptKeys(CKeyingMaterial& vMasterKeyIn);
|
|
||||||
bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) override;
|
bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) override;
|
||||||
|
bool Encrypt(const CKeyingMaterial& master_key, WalletBatch* batch) override;
|
||||||
|
|
||||||
bool GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool) override;
|
bool GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool) override;
|
||||||
void KeepDestination(int64_t index, const OutputType& type) override;
|
void KeepDestination(int64_t index, const OutputType& type) override;
|
||||||
|
|
|
@ -532,8 +532,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
||||||
{
|
{
|
||||||
LOCK(cs_wallet);
|
LOCK(cs_wallet);
|
||||||
mapMasterKeys[++nMasterKeyMaxID] = kMasterKey;
|
mapMasterKeys[++nMasterKeyMaxID] = kMasterKey;
|
||||||
assert(!encrypted_batch);
|
WalletBatch* encrypted_batch = new WalletBatch(*database);
|
||||||
encrypted_batch = new WalletBatch(*database);
|
|
||||||
if (!encrypted_batch->TxnBegin()) {
|
if (!encrypted_batch->TxnBegin()) {
|
||||||
delete encrypted_batch;
|
delete encrypted_batch;
|
||||||
encrypted_batch = nullptr;
|
encrypted_batch = nullptr;
|
||||||
|
@ -542,7 +541,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
||||||
encrypted_batch->WriteMasterKey(nMasterKeyMaxID, kMasterKey);
|
encrypted_batch->WriteMasterKey(nMasterKeyMaxID, kMasterKey);
|
||||||
|
|
||||||
if (auto spk_man = m_spk_man.get()) {
|
if (auto spk_man = m_spk_man.get()) {
|
||||||
if (!spk_man->EncryptKeys(_vMasterKey)) {
|
if (!spk_man->Encrypt(_vMasterKey, encrypted_batch)) {
|
||||||
encrypted_batch->TxnAbort();
|
encrypted_batch->TxnAbort();
|
||||||
delete encrypted_batch;
|
delete encrypted_batch;
|
||||||
encrypted_batch = nullptr;
|
encrypted_batch = nullptr;
|
||||||
|
|
|
@ -743,8 +743,6 @@ public:
|
||||||
{
|
{
|
||||||
// Should not have slots connected at this point.
|
// Should not have slots connected at this point.
|
||||||
assert(NotifyUnload.empty());
|
assert(NotifyUnload.empty());
|
||||||
delete encrypted_batch;
|
|
||||||
encrypted_batch = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsCrypted() const { return fUseCrypto; }
|
bool IsCrypted() const { return fUseCrypto; }
|
||||||
|
@ -1145,8 +1143,6 @@ public:
|
||||||
LegacyScriptPubKeyMan::CryptedKeyMap& mapCryptedKeys GUARDED_BY(cs_KeyStore) = m_spk_man->mapCryptedKeys;
|
LegacyScriptPubKeyMan::CryptedKeyMap& mapCryptedKeys GUARDED_BY(cs_KeyStore) = m_spk_man->mapCryptedKeys;
|
||||||
LegacyScriptPubKeyMan::WatchOnlySet& setWatchOnly GUARDED_BY(cs_KeyStore) = m_spk_man->setWatchOnly;
|
LegacyScriptPubKeyMan::WatchOnlySet& setWatchOnly GUARDED_BY(cs_KeyStore) = m_spk_man->setWatchOnly;
|
||||||
LegacyScriptPubKeyMan::WatchKeyMap& mapWatchKeys GUARDED_BY(cs_KeyStore) = m_spk_man->mapWatchKeys;
|
LegacyScriptPubKeyMan::WatchKeyMap& mapWatchKeys GUARDED_BY(cs_KeyStore) = m_spk_man->mapWatchKeys;
|
||||||
WalletBatch*& encrypted_batch GUARDED_BY(cs_wallet) = m_spk_man->encrypted_batch;
|
|
||||||
using CryptedKeyMap = LegacyScriptPubKeyMan::CryptedKeyMap;
|
|
||||||
|
|
||||||
/** Get last block processed height */
|
/** Get last block processed height */
|
||||||
int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
|
int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
|
||||||
|
|
Loading…
Reference in a new issue