mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-29 21:42:32 +02:00
walletdb: Refactor encryption key loading to its own function
This commit is contained in:
parent
3ccde4599b
commit
72c2a54ebb
@ -425,6 +425,33 @@ bool LoadCryptedKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, st
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LoadEncryptionKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, std::string& strErr)
|
||||||
|
{
|
||||||
|
LOCK(pwallet->cs_wallet);
|
||||||
|
try {
|
||||||
|
// Master encryption key is loaded into only the wallet and not any of the ScriptPubKeyMans.
|
||||||
|
unsigned int nID;
|
||||||
|
ssKey >> nID;
|
||||||
|
CMasterKey kMasterKey;
|
||||||
|
ssValue >> kMasterKey;
|
||||||
|
if(pwallet->mapMasterKeys.count(nID) != 0)
|
||||||
|
{
|
||||||
|
strErr = strprintf("Error reading wallet database: duplicate CMasterKey id %u", nID);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
pwallet->mapMasterKeys[nID] = kMasterKey;
|
||||||
|
if (pwallet->nMasterKeyMaxID < nID)
|
||||||
|
pwallet->nMasterKeyMaxID = nID;
|
||||||
|
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
if (strErr.empty()) {
|
||||||
|
strErr = e.what();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
ReadKeyValue(CWallet* pwallet, DataStream& ssKey, CDataStream& ssValue,
|
ReadKeyValue(CWallet* pwallet, DataStream& ssKey, CDataStream& ssValue,
|
||||||
CWalletScanState &wss, std::string& strType, std::string& strErr, const KeyFilterFn& filter_fn = nullptr) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
|
CWalletScanState &wss, std::string& strType, std::string& strErr, const KeyFilterFn& filter_fn = nullptr) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
|
||||||
@ -518,19 +545,7 @@ ReadKeyValue(CWallet* pwallet, DataStream& ssKey, CDataStream& ssValue,
|
|||||||
wss.nKeys++;
|
wss.nKeys++;
|
||||||
if (!LoadKey(pwallet, ssKey, ssValue, strErr)) return false;
|
if (!LoadKey(pwallet, ssKey, ssValue, strErr)) return false;
|
||||||
} else if (strType == DBKeys::MASTER_KEY) {
|
} else if (strType == DBKeys::MASTER_KEY) {
|
||||||
// Master encryption key is loaded into only the wallet and not any of the ScriptPubKeyMans.
|
if (!LoadEncryptionKey(pwallet, ssKey, ssValue, strErr)) return false;
|
||||||
unsigned int nID;
|
|
||||||
ssKey >> nID;
|
|
||||||
CMasterKey kMasterKey;
|
|
||||||
ssValue >> kMasterKey;
|
|
||||||
if(pwallet->mapMasterKeys.count(nID) != 0)
|
|
||||||
{
|
|
||||||
strErr = strprintf("Error reading wallet database: duplicate CMasterKey id %u", nID);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
pwallet->mapMasterKeys[nID] = kMasterKey;
|
|
||||||
if (pwallet->nMasterKeyMaxID < nID)
|
|
||||||
pwallet->nMasterKeyMaxID = nID;
|
|
||||||
} else if (strType == DBKeys::CRYPTED_KEY) {
|
} else if (strType == DBKeys::CRYPTED_KEY) {
|
||||||
wss.nCKeys++;
|
wss.nCKeys++;
|
||||||
if (!LoadCryptedKey(pwallet, ssKey, ssValue, strErr)) return false;
|
if (!LoadCryptedKey(pwallet, ssKey, ssValue, strErr)) return false;
|
||||||
|
@ -308,6 +308,7 @@ bool ReadKeyValue(CWallet* pwallet, DataStream& ssKey, CDataStream& ssValue, std
|
|||||||
|
|
||||||
bool LoadKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, std::string& strErr);
|
bool LoadKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, std::string& strErr);
|
||||||
bool LoadCryptedKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, std::string& strErr);
|
bool LoadCryptedKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, std::string& strErr);
|
||||||
|
bool LoadEncryptionKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, std::string& strErr);
|
||||||
} // namespace wallet
|
} // namespace wallet
|
||||||
|
|
||||||
#endif // BITCOIN_WALLET_WALLETDB_H
|
#endif // BITCOIN_WALLET_WALLETDB_H
|
||||||
|
Loading…
Reference in New Issue
Block a user