Skip to content
Permalink
Browse files

Remove uses of InitMessage/Warning/Error in wallet code

This commit does not change behavior.
  • Loading branch information...
ryanofsky committed Jul 29, 2017
1 parent 090411a commit 64ad91dbf5f20236b57c7c522836661bf768ee3d
Showing with 27 additions and 14 deletions.
  1. +9 −0 src/ipc/interfaces.h
  2. +4 −0 src/ipc/local/bitcoind.cpp
  3. +14 −14 src/wallet/wallet.cpp
@@ -168,6 +168,15 @@ class Chain
//! Get adjusted time.
virtual int64_t getAdjustedTime() = 0;

//! Send init message.
virtual void initMessage(const std::string& message) = 0;

//! Send init warning.
virtual void initWarning(const std::string& message) = 0;

//! Send init error.
virtual bool initError(const std::string& message) = 0;

//! Interface to let node manage chain clients (wallets, or maybe tools for
//! monitoring and analysis in the future).
class Client
@@ -5,6 +5,7 @@
#include <net.h>
#include <policy/fees.h>
#include <policy/policy.h>
#include <ui_interface.h>
#include <validation.h>

#if defined(HAVE_CONFIG_H)
@@ -197,6 +198,9 @@ class ChainImpl : public Chain
bool getPruneMode() override { return ::fPruneMode; }
bool p2pEnabled() override { return g_connman != nullptr; }
int64_t getAdjustedTime() override { return GetAdjustedTime(); }
void initMessage(const std::string& message) override { ::uiInterface.InitMessage(message); }
void initWarning(const std::string& message) override { InitWarning(message); }
bool initError(const std::string& message) override { return InitError(message); }
};

} // namespace
@@ -3816,18 +3816,18 @@ CWallet* CWallet::CreateWalletFromFile(ipc::Chain& ipc_chain, const std::string
std::vector<CWalletTx> vWtx;

if (gArgs.GetBoolArg("-zapwallettxes", false)) {
uiInterface.InitMessage(_("Zapping all transactions from wallet..."));
ipc_chain.initMessage(_("Zapping all transactions from wallet..."));

std::unique_ptr<CWalletDBWrapper> dbw(new CWalletDBWrapper(&bitdb, walletFile));
std::unique_ptr<CWallet> tempWallet(new CWallet(&ipc_chain, std::move(dbw)));
DBErrors nZapWalletRet = tempWallet->ZapWalletTx(vWtx);
if (nZapWalletRet != DB_LOAD_OK) {
InitError(strprintf(_("Error loading %s: Wallet corrupted"), walletFile));
ipc_chain.initError(strprintf(_("Error loading %s: Wallet corrupted"), walletFile));
return nullptr;
}
}

uiInterface.InitMessage(_("Loading wallet..."));
ipc_chain.initMessage(_("Loading wallet..."));

int64_t nStart = GetTimeMillis();
bool fFirstRun = true;
@@ -3837,26 +3837,26 @@ CWallet* CWallet::CreateWalletFromFile(ipc::Chain& ipc_chain, const std::string
if (nLoadWalletRet != DB_LOAD_OK)
{
if (nLoadWalletRet == DB_CORRUPT) {
InitError(strprintf(_("Error loading %s: Wallet corrupted"), walletFile));
ipc_chain.initError(strprintf(_("Error loading %s: Wallet corrupted"), walletFile));
return nullptr;
}
else if (nLoadWalletRet == DB_NONCRITICAL_ERROR)
{
InitWarning(strprintf(_("Error reading %s! All keys read correctly, but transaction data"
ipc_chain.initWarning(strprintf(_("Error reading %s! All keys read correctly, but transaction data"
" or address book entries might be missing or incorrect."),
walletFile));
}
else if (nLoadWalletRet == DB_TOO_NEW) {
InitError(strprintf(_("Error loading %s: Wallet requires newer version of %s"), walletFile, _(PACKAGE_NAME)));
ipc_chain.initError(strprintf(_("Error loading %s: Wallet requires newer version of %s"), walletFile, _(PACKAGE_NAME)));
return nullptr;
}
else if (nLoadWalletRet == DB_NEED_REWRITE)
{
InitError(strprintf(_("Wallet needed to be rewritten: restart %s to complete"), _(PACKAGE_NAME)));
ipc_chain.initError(strprintf(_("Wallet needed to be rewritten: restart %s to complete"), _(PACKAGE_NAME)));
return nullptr;
}
else {
InitError(strprintf(_("Error loading %s"), walletFile));
ipc_chain.initError(strprintf(_("Error loading %s"), walletFile));
return nullptr;
}
}
@@ -3874,7 +3874,7 @@ CWallet* CWallet::CreateWalletFromFile(ipc::Chain& ipc_chain, const std::string
LogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion);
if (nMaxVersion < walletInstance->GetVersion())
{
InitError(_("Cannot downgrade wallet"));
ipc_chain.initError(_("Cannot downgrade wallet"));
return nullptr;
}
walletInstance->SetMaxVersion(nMaxVersion);
@@ -3897,7 +3897,7 @@ CWallet* CWallet::CreateWalletFromFile(ipc::Chain& ipc_chain, const std::string

// Top up the keypool
if (!walletInstance->TopUpKeyPool()) {
InitError(_("Unable to generate initial keys") += "\n");
ipc_chain.initError(_("Unable to generate initial keys") += "\n");
return NULL;
}

@@ -3906,11 +3906,11 @@ CWallet* CWallet::CreateWalletFromFile(ipc::Chain& ipc_chain, const std::string
else if (gArgs.IsArgSet("-usehd")) {
bool useHD = gArgs.GetBoolArg("-usehd", DEFAULT_USE_HD_WALLET);
if (walletInstance->IsHDEnabled() && !useHD) {
InitError(strprintf(_("Error loading %s: You can't disable HD on an already existing HD wallet"), walletFile));
ipc_chain.initError(strprintf(_("Error loading %s: You can't disable HD on an already existing HD wallet"), walletFile));
return nullptr;
}
if (!walletInstance->IsHDEnabled() && useHD) {
InitError(strprintf(_("Error loading %s: You can't enable HD on an already existing non-HD wallet"), walletFile));
ipc_chain.initError(strprintf(_("Error loading %s: You can't enable HD on an already existing non-HD wallet"), walletFile));
return nullptr;
}
}
@@ -3953,12 +3953,12 @@ CWallet* CWallet::CreateWalletFromFile(ipc::Chain& ipc_chain, const std::string
}

if (index_rescan != block) {
InitError(_("Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node)"));
ipc_chain.initError(_("Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node)"));
return nullptr;
}
}

uiInterface.InitMessage(_("Rescanning..."));
ipc_chain.initMessage(_("Rescanning..."));
LogPrintf("Rescanning last %i blocks (from block %i)...\n", tip_height - index_rescan, index_rescan);

// No need to read and scan block if block was created before

0 comments on commit 64ad91d

Please sign in to comment.
You can’t perform that action at this time.