Permalink
Browse files

Modified init.h/init.cpp to use the wallet manager class to load the …

…default wallet.
  • Loading branch information...
1 parent 693d569 commit 5f0ae957e56537c6b1028be4e3ab72f8cb98aa17 @CodeShark committed Mar 24, 2013
Showing with 12 additions and 79 deletions.
  1. +10 −79 src/init.cpp
  2. +2 −0 src/init.h
View
@@ -5,6 +5,7 @@
#include "txdb.h"
#include "walletdb.h"
+#include "walletmanager.h"
#include "bitcoinrpc.h"
#include "net.h"
#include "init.h"
@@ -25,6 +26,7 @@
using namespace std;
using namespace boost;
+CWalletManager* pWalletManager;
CWallet* pwalletMain;
CClientUIInterface uiInterface;
@@ -102,8 +104,7 @@ void Shutdown(void* parg)
}
bitdb.Flush(true);
boost::filesystem::remove(GetPidFile());
- UnregisterWallet(pwalletMain);
- delete pwalletMain;
+ delete pWalletManager;
NewThread(ExitTimeout, NULL);
Sleep(50);
printf("Bitcoin exited\n\n");
@@ -900,85 +901,15 @@ bool AppInit2()
// ********************************************************* Step 8: load wallet
uiInterface.InitMessage(_("Loading wallet..."));
-
- nStart = GetTimeMillis();
- bool fFirstRun = true;
- pwalletMain = new CWallet("wallet.dat");
- DBErrors nLoadWalletRet = pwalletMain->LoadWallet(fFirstRun);
- if (nLoadWalletRet != DB_LOAD_OK)
- {
- if (nLoadWalletRet == DB_CORRUPT)
- strErrors << _("Error loading wallet.dat: Wallet corrupted") << "\n";
- else if (nLoadWalletRet == DB_NONCRITICAL_ERROR)
- {
- string msg(_("Warning: error reading wallet.dat! All keys read correctly, but transaction data"
- " or address book entries might be missing or incorrect."));
- InitWarning(msg);
- }
- else if (nLoadWalletRet == DB_TOO_NEW)
- strErrors << _("Error loading wallet.dat: Wallet requires newer version of Bitcoin") << "\n";
- else if (nLoadWalletRet == DB_NEED_REWRITE)
- {
- strErrors << _("Wallet needed to be rewritten: restart Bitcoin to complete") << "\n";
- printf("%s", strErrors.str().c_str());
- return InitError(strErrors.str());
- }
- else
- strErrors << _("Error loading wallet.dat") << "\n";
- }
-
- if (GetBoolArg("-upgradewallet", fFirstRun))
+
+ pWalletManager = new CWalletManager();
+ ostringstream ossErrors;
+ if (!pWalletManager->LoadWallet("", ossErrors))
{
- int nMaxVersion = GetArg("-upgradewallet", 0);
- if (nMaxVersion == 0) // the -upgradewallet without argument case
- {
- printf("Performing wallet upgrade to %i\n", FEATURE_LATEST);
- nMaxVersion = CLIENT_VERSION;
- pwalletMain->SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately
- }
- else
- printf("Allowing wallet upgrade up to %i\n", nMaxVersion);
- if (nMaxVersion < pwalletMain->GetVersion())
- strErrors << _("Cannot downgrade wallet") << "\n";
- pwalletMain->SetMaxVersion(nMaxVersion);
- }
-
- if (fFirstRun)
- {
- // Create new keyUser and set as default key
- RandAddSeedPerfmon();
-
- CPubKey newDefaultKey;
- if (!pwalletMain->GetKeyFromPool(newDefaultKey, false))
- strErrors << _("Cannot initialize keypool") << "\n";
- pwalletMain->SetDefaultKey(newDefaultKey);
- if (!pwalletMain->SetAddressBookName(pwalletMain->vchDefaultKey.GetID(), ""))
- strErrors << _("Cannot write default address") << "\n";
- }
-
- printf("%s", strErrors.str().c_str());
- printf(" wallet %15"PRI64d"ms\n", GetTimeMillis() - nStart);
-
- RegisterWallet(pwalletMain);
-
- CBlockIndex *pindexRescan = pindexBest;
- if (GetBoolArg("-rescan"))
- pindexRescan = pindexGenesisBlock;
- else
- {
- CWalletDB walletdb("wallet.dat");
- CBlockLocator locator;
- if (walletdb.ReadBestBlock(locator))
- pindexRescan = locator.GetBlockIndex();
- }
- if (pindexBest && pindexBest != pindexRescan)
- {
- uiInterface.InitMessage(_("Rescanning..."));
- printf("Rescanning last %i blocks (from block %i)...\n", pindexBest->nHeight - pindexRescan->nHeight, pindexRescan->nHeight);
- nStart = GetTimeMillis();
- pwalletMain->ScanForWalletTransactions(pindexRescan, true);
- printf(" rescan %15"PRI64d"ms\n", GetTimeMillis() - nStart);
+ printf("Failed to load default wallet: %s\nExiting...\n", ossErrors.str().c_str());
+ return false;
}
+ pwalletMain = pWalletManager->GetDefaultWallet().get();
// ********************************************************* Step 9: import blocks
View
@@ -5,8 +5,10 @@
#ifndef BITCOIN_INIT_H
#define BITCOIN_INIT_H
+#include "walletmanager.h"
#include "wallet.h"
+extern CWalletManager* pWalletManager;
extern CWallet* pwalletMain;
void StartShutdown();

0 comments on commit 5f0ae95

Please sign in to comment.