@@ -425,6 +425,33 @@ bool LoadCryptedKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, st
425
425
return true ;
426
426
}
427
427
428
+ bool LoadEncryptionKey (CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, std::string& strErr)
429
+ {
430
+ LOCK (pwallet->cs_wallet );
431
+ try {
432
+ // Master encryption key is loaded into only the wallet and not any of the ScriptPubKeyMans.
433
+ unsigned int nID;
434
+ ssKey >> nID;
435
+ CMasterKey kMasterKey ;
436
+ ssValue >> kMasterKey ;
437
+ if (pwallet->mapMasterKeys .count (nID) != 0 )
438
+ {
439
+ strErr = strprintf (" Error reading wallet database: duplicate CMasterKey id %u" , nID);
440
+ return false ;
441
+ }
442
+ pwallet->mapMasterKeys [nID] = kMasterKey ;
443
+ if (pwallet->nMasterKeyMaxID < nID)
444
+ pwallet->nMasterKeyMaxID = nID;
445
+
446
+ } catch (const std::exception& e) {
447
+ if (strErr.empty ()) {
448
+ strErr = e.what ();
449
+ }
450
+ return false ;
451
+ }
452
+ return true ;
453
+ }
454
+
428
455
static bool
429
456
ReadKeyValue (CWallet* pwallet, DataStream& ssKey, CDataStream& ssValue,
430
457
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,
518
545
wss.nKeys ++;
519
546
if (!LoadKey (pwallet, ssKey, ssValue, strErr)) return false ;
520
547
} else if (strType == DBKeys::MASTER_KEY) {
521
- // Master encryption key is loaded into only the wallet and not any of the ScriptPubKeyMans.
522
- unsigned int nID;
523
- ssKey >> nID;
524
- CMasterKey kMasterKey ;
525
- ssValue >> kMasterKey ;
526
- if (pwallet->mapMasterKeys .count (nID) != 0 )
527
- {
528
- strErr = strprintf (" Error reading wallet database: duplicate CMasterKey id %u" , nID);
529
- return false ;
530
- }
531
- pwallet->mapMasterKeys [nID] = kMasterKey ;
532
- if (pwallet->nMasterKeyMaxID < nID)
533
- pwallet->nMasterKeyMaxID = nID;
548
+ if (!LoadEncryptionKey (pwallet, ssKey, ssValue, strErr)) return false ;
534
549
} else if (strType == DBKeys::CRYPTED_KEY) {
535
550
wss.nCKeys ++;
536
551
if (!LoadCryptedKey (pwallet, ssKey, ssValue, strErr)) return false ;
0 commit comments