13
13
14
14
bool LegacyScriptPubKeyMan::GetNewDestination (const OutputType type, CTxDestination& dest, std::string& error)
15
15
{
16
+ LOCK (cs_KeyStore);
16
17
error.clear ();
17
18
18
19
// Generate a new key that is added to wallet
@@ -238,7 +239,6 @@ bool LegacyScriptPubKeyMan::CheckDecryptionKey(const CKeyingMaterial& master_key
238
239
239
240
bool LegacyScriptPubKeyMan::Encrypt (const CKeyingMaterial& master_key, WalletBatch* batch)
240
241
{
241
- AssertLockHeld (cs_wallet);
242
242
LOCK (cs_KeyStore);
243
243
encrypted_batch = batch;
244
244
if (!mapCryptedKeys.empty ()) {
@@ -269,6 +269,7 @@ bool LegacyScriptPubKeyMan::Encrypt(const CKeyingMaterial& master_key, WalletBat
269
269
270
270
bool LegacyScriptPubKeyMan::GetReservedDestination (const OutputType type, bool internal, CTxDestination& address, int64_t & index, CKeyPool& keypool)
271
271
{
272
+ LOCK (cs_KeyStore);
272
273
if (!CanGetAddresses (internal)) {
273
274
return false ;
274
275
}
@@ -282,7 +283,7 @@ bool LegacyScriptPubKeyMan::GetReservedDestination(const OutputType type, bool i
282
283
283
284
void LegacyScriptPubKeyMan::MarkUnusedAddresses (const CScript& script)
284
285
{
285
- AssertLockHeld (cs_wallet );
286
+ LOCK (cs_KeyStore );
286
287
// extract addresses and check if they match with an unused keypool key
287
288
for (const auto & keyid : GetAffectedKeys (script, *this )) {
288
289
std::map<CKeyID, int64_t >::const_iterator mi = m_pool_key_to_index.find (keyid);
@@ -299,7 +300,7 @@ void LegacyScriptPubKeyMan::MarkUnusedAddresses(const CScript& script)
299
300
300
301
void LegacyScriptPubKeyMan::UpgradeKeyMetadata ()
301
302
{
302
- AssertLockHeld (cs_wallet );
303
+ LOCK (cs_KeyStore );
303
304
if (m_storage.IsLocked () || m_storage.IsWalletFlagSet (WALLET_FLAG_KEY_ORIGIN_METADATA)) {
304
305
return ;
305
306
}
@@ -352,7 +353,7 @@ bool LegacyScriptPubKeyMan::IsHDEnabled() const
352
353
353
354
bool LegacyScriptPubKeyMan::CanGetAddresses (bool internal)
354
355
{
355
- LOCK (cs_wallet );
356
+ LOCK (cs_KeyStore );
356
357
// Check if the keypool has keys
357
358
bool keypool_has_keys;
358
359
if (internal && m_storage.CanSupportFeature (FEATURE_HD_SPLIT)) {
@@ -369,7 +370,7 @@ bool LegacyScriptPubKeyMan::CanGetAddresses(bool internal)
369
370
370
371
bool LegacyScriptPubKeyMan::Upgrade (int prev_version, std::string& error)
371
372
{
372
- AssertLockHeld (cs_wallet );
373
+ LOCK (cs_KeyStore );
373
374
error = " " ;
374
375
bool hd_upgrade = false ;
375
376
bool split_upgrade = false ;
@@ -410,7 +411,7 @@ bool LegacyScriptPubKeyMan::HavePrivateKeys() const
410
411
411
412
void LegacyScriptPubKeyMan::RewriteDB ()
412
413
{
413
- AssertLockHeld (cs_wallet );
414
+ LOCK (cs_KeyStore );
414
415
setInternalKeyPool.clear ();
415
416
setExternalKeyPool.clear ();
416
417
m_pool_key_to_index.clear ();
@@ -435,7 +436,7 @@ static int64_t GetOldestKeyTimeInPool(const std::set<int64_t>& setKeyPool, Walle
435
436
436
437
int64_t LegacyScriptPubKeyMan::GetOldestKeyPoolTime ()
437
438
{
438
- LOCK (cs_wallet );
439
+ LOCK (cs_KeyStore );
439
440
440
441
WalletBatch batch (m_storage.GetDatabase ());
441
442
@@ -453,25 +454,25 @@ int64_t LegacyScriptPubKeyMan::GetOldestKeyPoolTime()
453
454
454
455
size_t LegacyScriptPubKeyMan::KeypoolCountExternalKeys ()
455
456
{
456
- AssertLockHeld (cs_wallet );
457
+ LOCK (cs_KeyStore );
457
458
return setExternalKeyPool.size () + set_pre_split_keypool.size ();
458
459
}
459
460
460
461
unsigned int LegacyScriptPubKeyMan::GetKeyPoolSize () const
461
462
{
462
- AssertLockHeld (cs_wallet );
463
+ LOCK (cs_KeyStore );
463
464
return setInternalKeyPool.size () + setExternalKeyPool.size () + set_pre_split_keypool.size ();
464
465
}
465
466
466
467
int64_t LegacyScriptPubKeyMan::GetTimeFirstKey () const
467
468
{
468
- AssertLockHeld (cs_wallet );
469
+ LOCK (cs_KeyStore );
469
470
return nTimeFirstKey;
470
471
}
471
472
472
473
const CKeyMetadata* LegacyScriptPubKeyMan::GetMetadata (const CTxDestination& dest) const
473
474
{
474
- AssertLockHeld (cs_wallet );
475
+ LOCK (cs_KeyStore );
475
476
476
477
CKeyID key_id = GetKeyForDestination (*this , dest);
477
478
if (!key_id.IsNull ()) {
@@ -496,7 +497,7 @@ const CKeyMetadata* LegacyScriptPubKeyMan::GetMetadata(const CTxDestination& des
496
497
*/
497
498
void LegacyScriptPubKeyMan::UpdateTimeFirstKey (int64_t nCreateTime)
498
499
{
499
- AssertLockHeld (cs_wallet );
500
+ AssertLockHeld (cs_KeyStore );
500
501
if (nCreateTime <= 1 ) {
501
502
// Cannot determine birthday information, so set the wallet birthday to
502
503
// the beginning of time.
@@ -513,13 +514,14 @@ bool LegacyScriptPubKeyMan::LoadKey(const CKey& key, const CPubKey &pubkey)
513
514
514
515
bool LegacyScriptPubKeyMan::AddKeyPubKey (const CKey& secret, const CPubKey &pubkey)
515
516
{
517
+ LOCK (cs_KeyStore);
516
518
WalletBatch batch (m_storage.GetDatabase ());
517
519
return LegacyScriptPubKeyMan::AddKeyPubKeyWithDB (batch, secret, pubkey);
518
520
}
519
521
520
522
bool LegacyScriptPubKeyMan::AddKeyPubKeyWithDB (WalletBatch& batch, const CKey& secret, const CPubKey& pubkey)
521
523
{
522
- AssertLockHeld (cs_wallet );
524
+ AssertLockHeld (cs_KeyStore );
523
525
524
526
// Make sure we aren't adding private keys to private key disabled wallets
525
527
assert (!m_storage.IsWalletFlagSet (WALLET_FLAG_DISABLE_PRIVATE_KEYS));
@@ -574,14 +576,14 @@ bool LegacyScriptPubKeyMan::LoadCScript(const CScript& redeemScript)
574
576
575
577
void LegacyScriptPubKeyMan::LoadKeyMetadata (const CKeyID& keyID, const CKeyMetadata& meta)
576
578
{
577
- AssertLockHeld (cs_wallet );
579
+ LOCK (cs_KeyStore );
578
580
UpdateTimeFirstKey (meta.nCreateTime );
579
581
mapKeyMetadata[keyID] = meta;
580
582
}
581
583
582
584
void LegacyScriptPubKeyMan::LoadScriptMetadata (const CScriptID& script_id, const CKeyMetadata& meta)
583
585
{
584
- AssertLockHeld (cs_wallet );
586
+ LOCK (cs_KeyStore );
585
587
UpdateTimeFirstKey (meta.nCreateTime );
586
588
m_script_metadata[script_id] = meta;
587
589
}
@@ -630,7 +632,7 @@ bool LegacyScriptPubKeyMan::AddCryptedKey(const CPubKey &vchPubKey,
630
632
if (!AddCryptedKeyInner (vchPubKey, vchCryptedSecret))
631
633
return false ;
632
634
{
633
- LOCK (cs_wallet );
635
+ LOCK (cs_KeyStore );
634
636
if (encrypted_batch)
635
637
return encrypted_batch->WriteCryptedKey (vchPubKey,
636
638
vchCryptedSecret,
@@ -663,7 +665,6 @@ static bool ExtractPubKey(const CScript &dest, CPubKey& pubKeyOut)
663
665
664
666
bool LegacyScriptPubKeyMan::RemoveWatchOnly (const CScript &dest)
665
667
{
666
- AssertLockHeld (cs_wallet);
667
668
{
668
669
LOCK (cs_KeyStore);
669
670
setWatchOnly.erase (dest);
@@ -734,7 +735,7 @@ bool LegacyScriptPubKeyMan::AddWatchOnly(const CScript& dest, int64_t nCreateTim
734
735
735
736
void LegacyScriptPubKeyMan::SetHDChain (const CHDChain& chain, bool memonly)
736
737
{
737
- LOCK (cs_wallet );
738
+ LOCK (cs_KeyStore );
738
739
if (!memonly && !WalletBatch (m_storage.GetDatabase ()).WriteHDChain (chain))
739
740
throw std::runtime_error (std::string (__func__) + " : writing chain failed" );
740
741
@@ -771,7 +772,7 @@ bool LegacyScriptPubKeyMan::GetKeyOrigin(const CKeyID& keyID, KeyOriginInfo& inf
771
772
{
772
773
CKeyMetadata meta;
773
774
{
774
- LOCK (cs_wallet );
775
+ LOCK (cs_KeyStore );
775
776
auto it = mapKeyMetadata.find (keyID);
776
777
if (it != mapKeyMetadata.end ()) {
777
778
meta = it->second ;
@@ -821,7 +822,7 @@ CPubKey LegacyScriptPubKeyMan::GenerateNewKey(WalletBatch &batch, bool internal)
821
822
{
822
823
assert (!m_storage.IsWalletFlagSet (WALLET_FLAG_DISABLE_PRIVATE_KEYS));
823
824
assert (!m_storage.IsWalletFlagSet (WALLET_FLAG_BLANK_WALLET));
824
- AssertLockHeld (cs_wallet );
825
+ AssertLockHeld (cs_KeyStore );
825
826
bool fCompressed = m_storage.CanSupportFeature (FEATURE_COMPRPUBKEY); // default to compressed public keys if we want 0.6.0 wallets
826
827
827
828
CKey secret;
@@ -913,7 +914,7 @@ void LegacyScriptPubKeyMan::DeriveNewChildKey(WalletBatch &batch, CKeyMetadata&
913
914
914
915
void LegacyScriptPubKeyMan::LoadKeyPool (int64_t nIndex, const CKeyPool &keypool)
915
916
{
916
- AssertLockHeld (cs_wallet );
917
+ LOCK (cs_KeyStore );
917
918
if (keypool.m_pre_split ) {
918
919
set_pre_split_keypool.insert (nIndex);
919
920
} else if (keypool.fInternal ) {
@@ -935,7 +936,7 @@ void LegacyScriptPubKeyMan::LoadKeyPool(int64_t nIndex, const CKeyPool &keypool)
935
936
bool LegacyScriptPubKeyMan::CanGenerateKeys ()
936
937
{
937
938
// A wallet can generate keys if it has an HD seed (IsHDEnabled) or it is a non-HD wallet (pre FEATURE_HD)
938
- LOCK (cs_wallet );
939
+ LOCK (cs_KeyStore );
939
940
return IsHDEnabled () || !m_storage.CanSupportFeature (FEATURE_HD);
940
941
}
941
942
@@ -962,7 +963,7 @@ CPubKey LegacyScriptPubKeyMan::DeriveNewSeed(const CKey& key)
962
963
metadata.hd_seed_id = seed.GetID ();
963
964
964
965
{
965
- LOCK (cs_wallet );
966
+ LOCK (cs_KeyStore );
966
967
967
968
// mem store the metadata
968
969
mapKeyMetadata[seed.GetID ()] = metadata;
@@ -977,7 +978,7 @@ CPubKey LegacyScriptPubKeyMan::DeriveNewSeed(const CKey& key)
977
978
978
979
void LegacyScriptPubKeyMan::SetHDSeed (const CPubKey& seed)
979
980
{
980
- LOCK (cs_wallet );
981
+ LOCK (cs_KeyStore );
981
982
// store the keyid (hash160) together with
982
983
// the child index counter in the database
983
984
// as a hdchain object
@@ -1000,7 +1001,7 @@ bool LegacyScriptPubKeyMan::NewKeyPool()
1000
1001
return false ;
1001
1002
}
1002
1003
{
1003
- LOCK (cs_wallet );
1004
+ LOCK (cs_KeyStore );
1004
1005
WalletBatch batch (m_storage.GetDatabase ());
1005
1006
1006
1007
for (const int64_t nIndex : setInternalKeyPool) {
@@ -1034,7 +1035,7 @@ bool LegacyScriptPubKeyMan::TopUp(unsigned int kpSize)
1034
1035
return false ;
1035
1036
}
1036
1037
{
1037
- LOCK (cs_wallet );
1038
+ LOCK (cs_KeyStore );
1038
1039
1039
1040
if (m_storage.IsLocked ()) return false ;
1040
1041
@@ -1076,7 +1077,7 @@ bool LegacyScriptPubKeyMan::TopUp(unsigned int kpSize)
1076
1077
1077
1078
void LegacyScriptPubKeyMan::AddKeypoolPubkeyWithDB (const CPubKey& pubkey, const bool internal, WalletBatch& batch)
1078
1079
{
1079
- LOCK (cs_wallet );
1080
+ LOCK (cs_KeyStore );
1080
1081
assert (m_max_keypool_index < std::numeric_limits<int64_t >::max ()); // How in the hell did you use so many keys?
1081
1082
int64_t index = ++m_max_keypool_index;
1082
1083
if (!batch.WritePool (index, CKeyPool (pubkey, internal))) {
@@ -1107,7 +1108,7 @@ void LegacyScriptPubKeyMan::ReturnDestination(int64_t nIndex, bool fInternal, co
1107
1108
{
1108
1109
// Return to key pool
1109
1110
{
1110
- LOCK (cs_wallet );
1111
+ LOCK (cs_KeyStore );
1111
1112
if (fInternal ) {
1112
1113
setInternalKeyPool.insert (nIndex);
1113
1114
} else if (!set_pre_split_keypool.empty ()) {
@@ -1131,7 +1132,7 @@ bool LegacyScriptPubKeyMan::GetKeyFromPool(CPubKey& result, const OutputType typ
1131
1132
1132
1133
CKeyPool keypool;
1133
1134
{
1134
- LOCK (cs_wallet );
1135
+ LOCK (cs_KeyStore );
1135
1136
int64_t nIndex;
1136
1137
if (!ReserveKeyFromKeyPool (nIndex, keypool, internal) && !m_storage.IsWalletFlagSet (WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
1137
1138
if (m_storage.IsLocked ()) return false ;
@@ -1150,7 +1151,7 @@ bool LegacyScriptPubKeyMan::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& key
1150
1151
nIndex = -1 ;
1151
1152
keypool.vchPubKey = CPubKey ();
1152
1153
{
1153
- LOCK (cs_wallet );
1154
+ LOCK (cs_KeyStore );
1154
1155
1155
1156
bool fReturningInternal = fRequestedInternal ;
1156
1157
fReturningInternal &= (IsHDEnabled () && m_storage.CanSupportFeature (FEATURE_HD_SPLIT)) || m_storage.IsWalletFlagSet (WALLET_FLAG_DISABLE_PRIVATE_KEYS);
@@ -1210,7 +1211,7 @@ void LegacyScriptPubKeyMan::LearnAllRelatedScripts(const CPubKey& key)
1210
1211
1211
1212
void LegacyScriptPubKeyMan::MarkReserveKeysAsUsed (int64_t keypool_id)
1212
1213
{
1213
- AssertLockHeld (cs_wallet );
1214
+ AssertLockHeld (cs_KeyStore );
1214
1215
bool internal = setInternalKeyPool.count (keypool_id);
1215
1216
if (!internal) assert (setExternalKeyPool.count (keypool_id) || set_pre_split_keypool.count (keypool_id));
1216
1217
std::set<int64_t > *setKeyPool = internal ? &setInternalKeyPool : (set_pre_split_keypool.empty () ? &setExternalKeyPool : &set_pre_split_keypool);
@@ -1281,7 +1282,7 @@ bool LegacyScriptPubKeyMan::AddCScriptWithDB(WalletBatch& batch, const CScript&
1281
1282
1282
1283
bool LegacyScriptPubKeyMan::AddKeyOriginWithDB (WalletBatch& batch, const CPubKey& pubkey, const KeyOriginInfo& info)
1283
1284
{
1284
- LOCK (cs_wallet );
1285
+ LOCK (cs_KeyStore );
1285
1286
std::copy (info.fingerprint , info.fingerprint + 4 , mapKeyMetadata[pubkey.GetID ()].key_origin .fingerprint );
1286
1287
mapKeyMetadata[pubkey.GetID ()].key_origin .path = info.path ;
1287
1288
mapKeyMetadata[pubkey.GetID ()].has_key_origin = true ;
@@ -1397,8 +1398,7 @@ std::set<CKeyID> LegacyScriptPubKeyMan::GetKeys() const
1397
1398
// Temporary CWallet accessors and aliases.
1398
1399
LegacyScriptPubKeyMan::LegacyScriptPubKeyMan (CWallet& wallet)
1399
1400
: ScriptPubKeyMan(wallet),
1400
- m_wallet(wallet),
1401
- cs_wallet(wallet.cs_wallet) {}
1401
+ m_wallet(wallet) {}
1402
1402
1403
1403
void LegacyScriptPubKeyMan::NotifyWatchonlyChanged (bool fHaveWatchOnly ) const { return m_wallet.NotifyWatchonlyChanged (fHaveWatchOnly ); }
1404
1404
void LegacyScriptPubKeyMan::NotifyCanGetAddressesChanged () const { return m_wallet.NotifyCanGetAddressesChanged (); }
0 commit comments