aboutsummaryrefslogtreecommitdiff
path: root/src/qt/bitcoin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qt/bitcoin.cpp')
-rw-r--r--src/qt/bitcoin.cpp108
1 files changed, 41 insertions, 67 deletions
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index 140e56123f..599c3c0985 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -27,18 +27,17 @@
#endif
#include <init.h>
+#include <interfaces/handler.h>
+#include <interfaces/node.h>
#include <rpc/server.h>
#include <ui_interface.h>
#include <uint256.h>
#include <util.h>
#include <warnings.h>
-#ifdef ENABLE_WALLET
-#include <wallet/init.h>
-#include <wallet/wallet.h>
-#endif
#include <walletinitinterface.h>
+#include <memory>
#include <stdint.h>
#include <boost/thread.hpp>
@@ -180,11 +179,7 @@ class BitcoinCore: public QObject
{
Q_OBJECT
public:
- explicit BitcoinCore();
- /** Basic initialization, before starting initialization/shutdown thread.
- * Return true on success.
- */
- static bool baseInitialize();
+ explicit BitcoinCore(interfaces::Node& node);
public Q_SLOTS:
void initialize();
@@ -196,9 +191,10 @@ Q_SIGNALS:
void runawayException(const QString &message);
private:
-
/// Pass fatal exception message to UI thread
void handleRunawayException(const std::exception *e);
+
+ interfaces::Node& m_node;
};
/** Main Bitcoin application object */
@@ -206,7 +202,7 @@ class BitcoinApplication: public QApplication
{
Q_OBJECT
public:
- explicit BitcoinApplication(int &argc, char **argv);
+ explicit BitcoinApplication(interfaces::Node& node, int &argc, char **argv);
~BitcoinApplication();
#ifdef ENABLE_WALLET
@@ -247,6 +243,7 @@ Q_SIGNALS:
private:
QThread *coreThread;
+ interfaces::Node& m_node;
OptionsModel *optionsModel;
ClientModel *clientModel;
BitcoinGUI *window;
@@ -264,36 +261,15 @@ private:
#include <qt/bitcoin.moc>
-BitcoinCore::BitcoinCore():
- QObject()
+BitcoinCore::BitcoinCore(interfaces::Node& node) :
+ QObject(), m_node(node)
{
}
void BitcoinCore::handleRunawayException(const std::exception *e)
{
PrintExceptionContinue(e, "Runaway exception");
- Q_EMIT runawayException(QString::fromStdString(GetWarnings("gui")));
-}
-
-bool BitcoinCore::baseInitialize()
-{
- if (!AppInitBasicSetup())
- {
- return false;
- }
- if (!AppInitParameterInteraction())
- {
- return false;
- }
- if (!AppInitSanityChecks())
- {
- return false;
- }
- if (!AppInitLockDataDirectory())
- {
- return false;
- }
- return true;
+ Q_EMIT runawayException(QString::fromStdString(m_node.getWarnings("gui")));
}
void BitcoinCore::initialize()
@@ -301,7 +277,7 @@ void BitcoinCore::initialize()
try
{
qDebug() << __func__ << ": Running initialization in thread";
- bool rv = AppInitMain();
+ bool rv = m_node.appInitMain();
Q_EMIT initializeResult(rv);
} catch (const std::exception& e) {
handleRunawayException(&e);
@@ -315,8 +291,7 @@ void BitcoinCore::shutdown()
try
{
qDebug() << __func__ << ": Running Shutdown in thread";
- Interrupt();
- Shutdown();
+ m_node.appShutdown();
qDebug() << __func__ << ": Shutdown finished";
Q_EMIT shutdownResult();
} catch (const std::exception& e) {
@@ -326,9 +301,10 @@ void BitcoinCore::shutdown()
}
}
-BitcoinApplication::BitcoinApplication(int &argc, char **argv):
+BitcoinApplication::BitcoinApplication(interfaces::Node& node, int &argc, char **argv):
QApplication(argc, argv),
coreThread(0),
+ m_node(node),
optionsModel(0),
clientModel(0),
window(0),
@@ -383,12 +359,12 @@ void BitcoinApplication::createPaymentServer()
void BitcoinApplication::createOptionsModel(bool resetSettings)
{
- optionsModel = new OptionsModel(nullptr, resetSettings);
+ optionsModel = new OptionsModel(m_node, nullptr, resetSettings);
}
void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)
{
- window = new BitcoinGUI(platformStyle, networkStyle, 0);
+ window = new BitcoinGUI(m_node, platformStyle, networkStyle, 0);
pollShutdownTimer = new QTimer(window);
connect(pollShutdownTimer, SIGNAL(timeout()), window, SLOT(detectShutdown()));
@@ -396,7 +372,7 @@ void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)
void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle)
{
- SplashScreen *splash = new SplashScreen(0, networkStyle);
+ SplashScreen *splash = new SplashScreen(m_node, 0, networkStyle);
// We don't hold a direct pointer to the splash screen after creation, but the splash
// screen will take care of deleting itself when slotFinish happens.
splash->show();
@@ -409,7 +385,7 @@ void BitcoinApplication::startThread()
if(coreThread)
return;
coreThread = new QThread(this);
- BitcoinCore *executor = new BitcoinCore();
+ BitcoinCore *executor = new BitcoinCore(m_node);
executor->moveToThread(coreThread);
/* communication to and from thread */
@@ -427,8 +403,8 @@ void BitcoinApplication::startThread()
void BitcoinApplication::parameterSetup()
{
- InitLogging();
- InitParameterInteraction();
+ m_node.initLogging();
+ m_node.initParameterInteraction();
}
void BitcoinApplication::requestInitialize()
@@ -461,7 +437,7 @@ void BitcoinApplication::requestShutdown()
delete clientModel;
clientModel = 0;
- StartShutdown();
+ m_node.startShutdown();
// Request shutdown from core thread
Q_EMIT requestedShutdown();
@@ -481,13 +457,14 @@ void BitcoinApplication::initializeResult(bool success)
paymentServer->setOptionsModel(optionsModel);
#endif
- clientModel = new ClientModel(optionsModel);
+ clientModel = new ClientModel(m_node, optionsModel);
window->setClientModel(clientModel);
#ifdef ENABLE_WALLET
bool fFirstWallet = true;
- for (CWalletRef pwallet : vpwallets) {
- WalletModel * const walletModel = new WalletModel(platformStyle, pwallet, optionsModel);
+ auto wallets = m_node.getWallets();
+ for (auto& wallet : wallets) {
+ WalletModel * const walletModel = new WalletModel(std::move(wallet), m_node, platformStyle, optionsModel);
window->addWallet(walletModel);
if (fFirstWallet) {
@@ -495,8 +472,8 @@ void BitcoinApplication::initializeResult(bool success)
fFirstWallet = false;
}
- connect(walletModel, SIGNAL(coinsSent(CWallet*,SendCoinsRecipient,QByteArray)),
- paymentServer, SLOT(fetchPaymentACK(CWallet*,const SendCoinsRecipient&,QByteArray)));
+ connect(walletModel, SIGNAL(coinsSent(WalletModel*,SendCoinsRecipient,QByteArray)),
+ paymentServer, SLOT(fetchPaymentACK(WalletModel*,const SendCoinsRecipient&,QByteArray)));
m_wallet_models.push_back(walletModel);
}
@@ -555,9 +532,11 @@ int main(int argc, char *argv[])
{
SetupEnvironment();
+ std::unique_ptr<interfaces::Node> node = interfaces::MakeNode();
+
/// 1. Parse command-line options. These take precedence over anything else.
// Command-line options take precedence:
- gArgs.ParseParameters(argc, argv);
+ node->parseParameters(argc, argv);
// Do not refer to data directory yet, this can be overridden by Intro::pickDataDirectory
@@ -571,7 +550,7 @@ int main(int argc, char *argv[])
Q_INIT_RESOURCE(bitcoin);
Q_INIT_RESOURCE(bitcoin_locale);
- BitcoinApplication app(argc, argv);
+ BitcoinApplication app(*node, argc, argv);
#if QT_VERSION > 0x050100
// Generate high-dpi pixmaps
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
@@ -614,14 +593,14 @@ int main(int argc, char *argv[])
// Show help message immediately after parsing command-line options (for "-lang") and setting locale,
// but before showing splash screen.
if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
- HelpMessageDialog help(nullptr, gArgs.IsArgSet("-version"));
+ HelpMessageDialog help(*node, nullptr, gArgs.IsArgSet("-version"));
help.showOrPrint();
return EXIT_SUCCESS;
}
/// 5. Now that settings and translations are available, ask user for data directory
// User language is set up: pick a data directory
- if (!Intro::pickDataDirectory())
+ if (!Intro::pickDataDirectory(*node))
return EXIT_SUCCESS;
/// 6. Determine availability of data and blocks directory and parse bitcoin.conf
@@ -633,7 +612,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
try {
- gArgs.ReadConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME));
+ node->readConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME));
} catch (const std::exception& e) {
QMessageBox::critical(0, QObject::tr(PACKAGE_NAME),
QObject::tr("Error: Cannot parse configuration file: %1. Only use key=value syntax.").arg(e.what()));
@@ -648,14 +627,14 @@ int main(int argc, char *argv[])
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
try {
- SelectParams(ChainNameFromCommandLine());
+ node->selectParams(gArgs.GetChainName());
} catch(std::exception &e) {
QMessageBox::critical(0, QObject::tr(PACKAGE_NAME), QObject::tr("Error: %1").arg(e.what()));
return EXIT_FAILURE;
}
#ifdef ENABLE_WALLET
// Parse URIs on command line -- this can affect Params()
- PaymentServer::ipcParseCommandLine(argc, argv);
+ PaymentServer::ipcParseCommandLine(*node, argc, argv);
#endif
QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(QString::fromStdString(Params().NetworkIDString())));
@@ -678,11 +657,6 @@ int main(int argc, char *argv[])
// Start up the payment server early, too, so impatient users that click on
// bitcoin: links repeatedly have their payment requests routed to this process:
app.createPaymentServer();
-
- // Hook up the wallet init interface
- g_wallet_init_interface.reset(new WalletInit);
-#else
- g_wallet_init_interface.reset(new DummyWalletInit);
#endif
/// 9. Main GUI initialization
@@ -705,7 +679,7 @@ int main(int argc, char *argv[])
app.createOptionsModel(gArgs.GetBoolArg("-resetguisettings", false));
// Subscribe to global signals from core
- uiInterface.InitMessage.connect(InitMessage);
+ std::unique_ptr<interfaces::Handler> handler = node->handleInitMessage(InitMessage);
if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false))
app.createSplashScreen(networkStyle.data());
@@ -717,7 +691,7 @@ int main(int argc, char *argv[])
// Perform base initialization before spinning up initialization/shutdown thread
// This is acceptable because this function only contains steps that are quick to execute,
// so the GUI thread won't be held up.
- if (BitcoinCore::baseInitialize()) {
+ if (node->baseInitialize()) {
app.requestInitialize();
#if defined(Q_OS_WIN) && QT_VERSION >= 0x050000
WinShutdownMonitor::registerShutdownBlockReason(QObject::tr("%1 didn't yet exit safely...").arg(QObject::tr(PACKAGE_NAME)), (HWND)app.getMainWinId());
@@ -732,10 +706,10 @@ int main(int argc, char *argv[])
}
} catch (const std::exception& e) {
PrintExceptionContinue(&e, "Runaway exception");
- app.handleRunawayException(QString::fromStdString(GetWarnings("gui")));
+ app.handleRunawayException(QString::fromStdString(node->getWarnings("gui")));
} catch (...) {
PrintExceptionContinue(nullptr, "Runaway exception");
- app.handleRunawayException(QString::fromStdString(GetWarnings("gui")));
+ app.handleRunawayException(QString::fromStdString(node->getWarnings("gui")));
}
return rv;
}