simplify locking, merge cs_SpendingKeyStore into cs_KeyStore
This commit is contained in:
parent
ffdba7c19e
commit
5a5094bbb5
|
@ -25,7 +25,7 @@ bool CKeyStore::AddKey(const CKey &key) {
|
|||
|
||||
bool CBasicKeyStore::SetHDSeed(const HDSeed& seed)
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
if (!hdSeed.IsNull()) {
|
||||
// Don't allow an existing seed to be changed. We can maybe relax this
|
||||
// restriction later once we have worked out the UX implications.
|
||||
|
@ -37,13 +37,13 @@ bool CBasicKeyStore::SetHDSeed(const HDSeed& seed)
|
|||
|
||||
bool CBasicKeyStore::HaveHDSeed() const
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
return !hdSeed.IsNull();
|
||||
}
|
||||
|
||||
bool CBasicKeyStore::GetHDSeed(HDSeed& seedOut) const
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
if (hdSeed.IsNull()) {
|
||||
return false;
|
||||
} else {
|
||||
|
@ -115,7 +115,7 @@ bool CBasicKeyStore::HaveWatchOnly() const
|
|||
|
||||
bool CBasicKeyStore::AddSproutSpendingKey(const libzcash::SproutSpendingKey &sk)
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
auto address = sk.address();
|
||||
mapSproutSpendingKeys[address] = sk;
|
||||
mapNoteDecryptors.insert(std::make_pair(address, ZCNoteDecryption(sk.receiving_key())));
|
||||
|
@ -127,7 +127,7 @@ bool CBasicKeyStore::AddSaplingSpendingKey(
|
|||
const libzcash::SaplingExtendedSpendingKey &sk,
|
||||
const libzcash::SaplingPaymentAddress &defaultAddr)
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
auto fvk = sk.expsk.full_viewing_key();
|
||||
|
||||
// if SaplingFullViewingKey is not in SaplingFullViewingKeyMap, add it
|
||||
|
@ -142,7 +142,7 @@ bool CBasicKeyStore::AddSaplingSpendingKey(
|
|||
|
||||
bool CBasicKeyStore::AddSproutViewingKey(const libzcash::SproutViewingKey &vk)
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
auto address = vk.address();
|
||||
mapSproutViewingKeys[address] = vk;
|
||||
mapNoteDecryptors.insert(std::make_pair(address, ZCNoteDecryption(vk.sk_enc)));
|
||||
|
@ -153,7 +153,7 @@ bool CBasicKeyStore::AddSaplingFullViewingKey(
|
|||
const libzcash::SaplingFullViewingKey &fvk,
|
||||
const libzcash::SaplingPaymentAddress &defaultAddr)
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
auto ivk = fvk.in_viewing_key();
|
||||
mapSaplingFullViewingKeys[ivk] = fvk;
|
||||
|
||||
|
@ -167,7 +167,7 @@ bool CBasicKeyStore::AddSaplingIncomingViewingKey(
|
|||
const libzcash::SaplingIncomingViewingKey &ivk,
|
||||
const libzcash::SaplingPaymentAddress &addr)
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
|
||||
// Add addr -> SaplingIncomingViewing to SaplingIncomingViewingKeyMap
|
||||
mapSaplingIncomingViewingKeys[addr] = ivk;
|
||||
|
@ -177,26 +177,26 @@ bool CBasicKeyStore::AddSaplingIncomingViewingKey(
|
|||
|
||||
bool CBasicKeyStore::RemoveSproutViewingKey(const libzcash::SproutViewingKey &vk)
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
mapSproutViewingKeys.erase(vk.address());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBasicKeyStore::HaveSproutViewingKey(const libzcash::SproutPaymentAddress &address) const
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
return mapSproutViewingKeys.count(address) > 0;
|
||||
}
|
||||
|
||||
bool CBasicKeyStore::HaveSaplingFullViewingKey(const libzcash::SaplingIncomingViewingKey &ivk) const
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
return mapSaplingFullViewingKeys.count(ivk) > 0;
|
||||
}
|
||||
|
||||
bool CBasicKeyStore::HaveSaplingIncomingViewingKey(const libzcash::SaplingPaymentAddress &addr) const
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
return mapSaplingIncomingViewingKeys.count(addr) > 0;
|
||||
}
|
||||
|
||||
|
@ -204,7 +204,7 @@ bool CBasicKeyStore::GetSproutViewingKey(
|
|||
const libzcash::SproutPaymentAddress &address,
|
||||
libzcash::SproutViewingKey &vkOut) const
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
SproutViewingKeyMap::const_iterator mi = mapSproutViewingKeys.find(address);
|
||||
if (mi != mapSproutViewingKeys.end()) {
|
||||
vkOut = mi->second;
|
||||
|
@ -216,7 +216,7 @@ bool CBasicKeyStore::GetSproutViewingKey(
|
|||
bool CBasicKeyStore::GetSaplingFullViewingKey(const libzcash::SaplingIncomingViewingKey &ivk,
|
||||
libzcash::SaplingFullViewingKey &fvkOut) const
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
SaplingFullViewingKeyMap::const_iterator mi = mapSaplingFullViewingKeys.find(ivk);
|
||||
if (mi != mapSaplingFullViewingKeys.end()) {
|
||||
fvkOut = mi->second;
|
||||
|
@ -228,7 +228,7 @@ bool CBasicKeyStore::GetSaplingFullViewingKey(const libzcash::SaplingIncomingVie
|
|||
bool CBasicKeyStore::GetSaplingIncomingViewingKey(const libzcash::SaplingPaymentAddress &addr,
|
||||
libzcash::SaplingIncomingViewingKey &ivkOut) const
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
SaplingIncomingViewingKeyMap::const_iterator mi = mapSaplingIncomingViewingKeys.find(addr);
|
||||
if (mi != mapSaplingIncomingViewingKeys.end()) {
|
||||
ivkOut = mi->second;
|
||||
|
@ -242,6 +242,7 @@ bool CBasicKeyStore::GetSaplingExtendedSpendingKey(const libzcash::SaplingPaymen
|
|||
libzcash::SaplingIncomingViewingKey ivk;
|
||||
libzcash::SaplingFullViewingKey fvk;
|
||||
|
||||
LOCK(cs_KeyStore);
|
||||
return GetSaplingIncomingViewingKey(addr, ivk) &&
|
||||
GetSaplingFullViewingKey(ivk, fvk) &&
|
||||
GetSaplingSpendingKey(fvk, extskOut);
|
||||
|
|
|
@ -23,7 +23,6 @@ class CKeyStore
|
|||
{
|
||||
protected:
|
||||
mutable CCriticalSection cs_KeyStore;
|
||||
mutable CCriticalSection cs_SpendingKeyStore;
|
||||
|
||||
public:
|
||||
virtual ~CKeyStore() {}
|
||||
|
@ -185,7 +184,7 @@ public:
|
|||
{
|
||||
bool result;
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
result = (mapSproutSpendingKeys.count(address) > 0);
|
||||
}
|
||||
return result;
|
||||
|
@ -193,7 +192,7 @@ public:
|
|||
bool GetSproutSpendingKey(const libzcash::SproutPaymentAddress &address, libzcash::SproutSpendingKey &skOut) const
|
||||
{
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
SproutSpendingKeyMap::const_iterator mi = mapSproutSpendingKeys.find(address);
|
||||
if (mi != mapSproutSpendingKeys.end())
|
||||
{
|
||||
|
@ -206,7 +205,7 @@ public:
|
|||
bool GetNoteDecryptor(const libzcash::SproutPaymentAddress &address, ZCNoteDecryption &decOut) const
|
||||
{
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
NoteDecryptorMap::const_iterator mi = mapNoteDecryptors.find(address);
|
||||
if (mi != mapNoteDecryptors.end())
|
||||
{
|
||||
|
@ -220,7 +219,7 @@ public:
|
|||
{
|
||||
setAddress.clear();
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
SproutSpendingKeyMap::const_iterator mi = mapSproutSpendingKeys.begin();
|
||||
while (mi != mapSproutSpendingKeys.end())
|
||||
{
|
||||
|
@ -244,7 +243,7 @@ public:
|
|||
{
|
||||
bool result;
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
result = (mapSaplingSpendingKeys.count(fvk) > 0);
|
||||
}
|
||||
return result;
|
||||
|
@ -252,7 +251,7 @@ public:
|
|||
bool GetSaplingSpendingKey(const libzcash::SaplingFullViewingKey &fvk, libzcash::SaplingExtendedSpendingKey &skOut) const
|
||||
{
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
|
||||
SaplingSpendingKeyMap::const_iterator mi = mapSaplingSpendingKeys.find(fvk);
|
||||
if (mi != mapSaplingSpendingKeys.end())
|
||||
|
@ -288,7 +287,7 @@ public:
|
|||
{
|
||||
setAddress.clear();
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
auto mi = mapSaplingIncomingViewingKeys.begin();
|
||||
while (mi != mapSaplingIncomingViewingKeys.end())
|
||||
{
|
||||
|
|
|
@ -187,7 +187,7 @@ static bool DecryptSaplingSpendingKey(const CKeyingMaterial& vMasterKey,
|
|||
|
||||
bool CCryptoKeyStore::SetCrypted()
|
||||
{
|
||||
LOCK2(cs_KeyStore, cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
if (fUseCrypto)
|
||||
return true;
|
||||
if (!(mapKeys.empty() && mapSproutSpendingKeys.empty() && mapSaplingSpendingKeys.empty()))
|
||||
|
@ -213,7 +213,7 @@ bool CCryptoKeyStore::Lock()
|
|||
bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn)
|
||||
{
|
||||
{
|
||||
LOCK2(cs_KeyStore, cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
if (!SetCrypted())
|
||||
return false;
|
||||
|
||||
|
@ -290,7 +290,7 @@ bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn)
|
|||
bool CCryptoKeyStore::SetHDSeed(const HDSeed& seed)
|
||||
{
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
if (!IsCrypted()) {
|
||||
return CBasicKeyStore::SetHDSeed(seed);
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ bool CCryptoKeyStore::SetCryptedHDSeed(
|
|||
const std::vector<unsigned char>& vchCryptedSecret)
|
||||
{
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
if (!IsCrypted()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -335,7 +335,7 @@ bool CCryptoKeyStore::SetCryptedHDSeed(
|
|||
|
||||
bool CCryptoKeyStore::HaveHDSeed() const
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
if (!IsCrypted())
|
||||
return CBasicKeyStore::HaveHDSeed();
|
||||
|
||||
|
@ -344,7 +344,7 @@ bool CCryptoKeyStore::HaveHDSeed() const
|
|||
|
||||
bool CCryptoKeyStore::GetHDSeed(HDSeed& seedOut) const
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
if (!IsCrypted())
|
||||
return CBasicKeyStore::GetHDSeed(seedOut);
|
||||
|
||||
|
@ -426,7 +426,7 @@ bool CCryptoKeyStore::GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) co
|
|||
bool CCryptoKeyStore::AddSproutSpendingKey(const libzcash::SproutSpendingKey &sk)
|
||||
{
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
if (!IsCrypted())
|
||||
return CBasicKeyStore::AddSproutSpendingKey(sk);
|
||||
|
||||
|
@ -452,7 +452,7 @@ bool CCryptoKeyStore::AddSaplingSpendingKey(
|
|||
const libzcash::SaplingPaymentAddress &defaultAddr)
|
||||
{
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
if (!IsCrypted()) {
|
||||
return CBasicKeyStore::AddSaplingSpendingKey(sk, defaultAddr);
|
||||
}
|
||||
|
@ -483,7 +483,7 @@ bool CCryptoKeyStore::AddCryptedSproutSpendingKey(
|
|||
const std::vector<unsigned char> &vchCryptedSecret)
|
||||
{
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
if (!SetCrypted())
|
||||
return false;
|
||||
|
||||
|
@ -499,7 +499,7 @@ bool CCryptoKeyStore::AddCryptedSaplingSpendingKey(
|
|||
const libzcash::SaplingPaymentAddress &defaultAddr)
|
||||
{
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
if (!SetCrypted()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -517,7 +517,7 @@ bool CCryptoKeyStore::AddCryptedSaplingSpendingKey(
|
|||
bool CCryptoKeyStore::GetSproutSpendingKey(const libzcash::SproutPaymentAddress &address, libzcash::SproutSpendingKey &skOut) const
|
||||
{
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
if (!IsCrypted())
|
||||
return CBasicKeyStore::GetSproutSpendingKey(address, skOut);
|
||||
|
||||
|
@ -534,7 +534,7 @@ bool CCryptoKeyStore::GetSproutSpendingKey(const libzcash::SproutPaymentAddress
|
|||
bool CCryptoKeyStore::GetSaplingSpendingKey(const libzcash::SaplingFullViewingKey &fvk, libzcash::SaplingExtendedSpendingKey &skOut) const
|
||||
{
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
if (!IsCrypted())
|
||||
return CBasicKeyStore::GetSaplingSpendingKey(fvk, skOut);
|
||||
|
||||
|
@ -551,7 +551,7 @@ bool CCryptoKeyStore::GetSaplingSpendingKey(const libzcash::SaplingFullViewingKe
|
|||
bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn)
|
||||
{
|
||||
{
|
||||
LOCK2(cs_KeyStore, cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
if (!mapCryptedKeys.empty() || IsCrypted())
|
||||
return false;
|
||||
|
||||
|
|
|
@ -216,7 +216,7 @@ public:
|
|||
bool HaveSproutSpendingKey(const libzcash::SproutPaymentAddress &address) const
|
||||
{
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
if (!IsCrypted())
|
||||
return CBasicKeyStore::HaveSproutSpendingKey(address);
|
||||
return mapCryptedSproutSpendingKeys.count(address) > 0;
|
||||
|
@ -250,7 +250,7 @@ public:
|
|||
bool HaveSaplingSpendingKey(const libzcash::SaplingFullViewingKey &fvk) const
|
||||
{
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
if (!IsCrypted())
|
||||
return CBasicKeyStore::HaveSaplingSpendingKey(fvk);
|
||||
for (auto entry : mapCryptedSaplingSpendingKeys) {
|
||||
|
|
|
@ -1802,7 +1802,7 @@ boost::optional<uint256> CWallet::GetSproutNoteNullifier(const JSDescription &js
|
|||
*/
|
||||
mapSproutNoteData_t CWallet::FindMySproutNotes(const CTransaction &tx) const
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
uint256 hash = tx.GetHash();
|
||||
|
||||
mapSproutNoteData_t noteData;
|
||||
|
@ -1850,7 +1850,7 @@ mapSproutNoteData_t CWallet::FindMySproutNotes(const CTransaction &tx) const
|
|||
*/
|
||||
std::pair<mapSaplingNoteData_t, SaplingIncomingViewingKeyMap> CWallet::FindMySaplingNotes(const CTransaction &tx) const
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
LOCK(cs_KeyStore);
|
||||
uint256 hash = tx.GetHash();
|
||||
|
||||
mapSaplingNoteData_t noteData;
|
||||
|
|
Loading…
Reference in New Issue