@@ -3374,16 +3374,8 @@ std::string CWallet::GetWalletHelpString(bool showDebug)
3374
3374
return strUsage;
3375
3375
}
3376
3376
3377
- bool CWallet::InitLoadWallet ( )
3377
+ CWallet* CWallet::CreateWalletFromFile ( const std::string walletFile )
3378
3378
{
3379
- if (GetBoolArg (" -disablewallet" , DEFAULT_DISABLE_WALLET)) {
3380
- pwalletMain = NULL ;
3381
- LogPrintf (" Wallet disabled!\n " );
3382
- return true ;
3383
- }
3384
-
3385
- std::string walletFile = GetArg (" -wallet" , DEFAULT_WALLET_DAT);
3386
-
3387
3379
// needed to restore wallet transaction meta data after -zapwallettxes
3388
3380
std::vector<CWalletTx> vWtx;
3389
3381
@@ -3393,7 +3385,8 @@ bool CWallet::InitLoadWallet()
3393
3385
CWallet *tempWallet = new CWallet (walletFile);
3394
3386
DBErrors nZapWalletRet = tempWallet->ZapWalletTx (vWtx);
3395
3387
if (nZapWalletRet != DB_LOAD_OK) {
3396
- return InitError (strprintf (_ (" Error loading %s: Wallet corrupted" ), walletFile));
3388
+ InitError (strprintf (_ (" Error loading %s: Wallet corrupted" ), walletFile));
3389
+ return NULL ;
3397
3390
}
3398
3391
3399
3392
delete tempWallet;
@@ -3408,23 +3401,29 @@ bool CWallet::InitLoadWallet()
3408
3401
DBErrors nLoadWalletRet = walletInstance->LoadWallet (fFirstRun );
3409
3402
if (nLoadWalletRet != DB_LOAD_OK)
3410
3403
{
3411
- if (nLoadWalletRet == DB_CORRUPT)
3412
- return InitError (strprintf (_ (" Error loading %s: Wallet corrupted" ), walletFile));
3404
+ if (nLoadWalletRet == DB_CORRUPT) {
3405
+ InitError (strprintf (_ (" Error loading %s: Wallet corrupted" ), walletFile));
3406
+ return NULL ;
3407
+ }
3413
3408
else if (nLoadWalletRet == DB_NONCRITICAL_ERROR)
3414
3409
{
3415
3410
InitWarning (strprintf (_ (" Error reading %s! All keys read correctly, but transaction data"
3416
3411
" or address book entries might be missing or incorrect." ),
3417
3412
walletFile));
3418
3413
}
3419
- else if (nLoadWalletRet == DB_TOO_NEW)
3420
- return InitError (strprintf (_ (" Error loading %s: Wallet requires newer version of %s" ),
3421
- walletFile, _ (PACKAGE_NAME)));
3414
+ else if (nLoadWalletRet == DB_TOO_NEW) {
3415
+ InitError (strprintf (_ (" Error loading %s: Wallet requires newer version of %s" ), walletFile, _ (PACKAGE_NAME)));
3416
+ return NULL ;
3417
+ }
3422
3418
else if (nLoadWalletRet == DB_NEED_REWRITE)
3423
3419
{
3424
- return InitError (strprintf (_ (" Wallet needed to be rewritten: restart %s to complete" ), _ (PACKAGE_NAME)));
3420
+ InitError (strprintf (_ (" Wallet needed to be rewritten: restart %s to complete" ), _ (PACKAGE_NAME)));
3421
+ return NULL ;
3422
+ }
3423
+ else {
3424
+ InitError (strprintf (_ (" Error loading %s" ), walletFile));
3425
+ return NULL ;
3425
3426
}
3426
- else
3427
- return InitError (strprintf (_ (" Error loading %s" ), walletFile));
3428
3427
}
3429
3428
3430
3429
if (GetBoolArg (" -upgradewallet" , fFirstRun ))
@@ -3440,7 +3439,8 @@ bool CWallet::InitLoadWallet()
3440
3439
LogPrintf (" Allowing wallet upgrade up to %i\n " , nMaxVersion);
3441
3440
if (nMaxVersion < walletInstance->GetVersion ())
3442
3441
{
3443
- return InitError (_ (" Cannot downgrade wallet" ));
3442
+ InitError (_ (" Cannot downgrade wallet" ));
3443
+ return NULL ;
3444
3444
}
3445
3445
walletInstance->SetMaxVersion (nMaxVersion);
3446
3446
}
@@ -3457,18 +3457,24 @@ bool CWallet::InitLoadWallet()
3457
3457
CPubKey newDefaultKey;
3458
3458
if (walletInstance->GetKeyFromPool (newDefaultKey)) {
3459
3459
walletInstance->SetDefaultKey (newDefaultKey);
3460
- if (!walletInstance->SetAddressBook (walletInstance->vchDefaultKey .GetID (), " " , " receive" ))
3461
- return InitError (_ (" Cannot write default address" ) += " \n " );
3460
+ if (!walletInstance->SetAddressBook (walletInstance->vchDefaultKey .GetID (), " " , " receive" )) {
3461
+ InitError (_ (" Cannot write default address" ) += " \n " );
3462
+ return NULL ;
3463
+ }
3462
3464
}
3463
3465
3464
3466
walletInstance->SetBestChain (chainActive.GetLocator ());
3465
3467
}
3466
3468
else if (mapArgs.count (" -usehd" )) {
3467
3469
bool useHD = GetBoolArg (" -usehd" , DEFAULT_USE_HD_WALLET);
3468
- if (walletInstance->IsHDEnabled () && !useHD)
3469
- return InitError (strprintf (_ (" Error loading %s: You can't disable HD on a already existing HD wallet" ), walletFile));
3470
- if (!walletInstance->IsHDEnabled () && useHD)
3471
- return InitError (strprintf (_ (" Error loading %s: You can't enable HD on a already existing non-HD wallet" ), walletFile));
3470
+ if (walletInstance->IsHDEnabled () && !useHD) {
3471
+ InitError (strprintf (_ (" Error loading %s: You can't disable HD on a already existing HD wallet" ), walletFile));
3472
+ return NULL ;
3473
+ }
3474
+ if (!walletInstance->IsHDEnabled () && useHD) {
3475
+ InitError (strprintf (_ (" Error loading %s: You can't enable HD on a already existing non-HD wallet" ), walletFile));
3476
+ return NULL ;
3477
+ }
3472
3478
}
3473
3479
3474
3480
LogPrintf (" wallet %15dms\n " , GetTimeMillis () - nStart);
@@ -3498,8 +3504,10 @@ bool CWallet::InitLoadWallet()
3498
3504
while (block && block->pprev && (block->pprev ->nStatus & BLOCK_HAVE_DATA) && block->pprev ->nTx > 0 && pindexRescan != block)
3499
3505
block = block->pprev ;
3500
3506
3501
- if (pindexRescan != block)
3502
- return InitError (_ (" Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node)" ));
3507
+ if (pindexRescan != block) {
3508
+ InitError (_ (" Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node)" ));
3509
+ return NULL ;
3510
+ }
3503
3511
}
3504
3512
3505
3513
uiInterface.InitMessage (_ (" Rescanning..." ));
@@ -3544,7 +3552,24 @@ bool CWallet::InitLoadWallet()
3544
3552
LogPrintf (" mapAddressBook.size() = %u\n " , walletInstance->mapAddressBook .size ());
3545
3553
}
3546
3554
3547
- pwalletMain = walletInstance;
3555
+ return walletInstance;
3556
+ }
3557
+
3558
+ bool CWallet::InitLoadWallet ()
3559
+ {
3560
+ if (GetBoolArg (" -disablewallet" , DEFAULT_DISABLE_WALLET)) {
3561
+ pwalletMain = NULL ;
3562
+ LogPrintf (" Wallet disabled!\n " );
3563
+ return true ;
3564
+ }
3565
+
3566
+ std::string walletFile = GetArg (" -wallet" , DEFAULT_WALLET_DAT);
3567
+
3568
+ CWallet * const pwallet = CreateWalletFromFile (walletFile);
3569
+ if (!pwallet) {
3570
+ return false ;
3571
+ }
3572
+ pwalletMain = pwallet;
3548
3573
3549
3574
return true ;
3550
3575
}
0 commit comments