Skip to content

Commit

Permalink
ui: Support wallets loaded dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
promag committed May 16, 2018
1 parent 1c8fe0b commit 0e674ba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion doc/release-notes-pr10740.md
Expand Up @@ -5,4 +5,4 @@ Previously, wallets could only be loaded at startup, by specifying `-wallet` par

The wallet can be specified as file/directory basename (which must be located in the `walletdir` directory), or as an absolute path to a file/directory.

This feature is currently only available through the RPC interface. Wallets loaded in this way will not display in the bitcoin-qt GUI.
This feature is currently only available through the RPC interface. Wallets loaded in this way will display in the bitcoin-qt GUI.
39 changes: 27 additions & 12 deletions src/qt/bitcoin.cpp
Expand Up @@ -234,6 +234,7 @@ public Q_SLOTS:
void shutdownResult();
/// Handle runaway exceptions. Shows a message box with the problem and quits the program.
void handleRunawayException(const QString &message);
void addWallet(WalletModel* walletModel);

Q_SIGNALS:
void requestedInitialize();
Expand All @@ -251,6 +252,7 @@ public Q_SLOTS:
#ifdef ENABLE_WALLET
PaymentServer* paymentServer;
std::vector<WalletModel*> m_wallet_models;
std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
#endif
int returnValue;
const PlatformStyle *platformStyle;
Expand Down Expand Up @@ -447,6 +449,22 @@ void BitcoinApplication::requestShutdown()
Q_EMIT requestedShutdown();
}

void BitcoinApplication::addWallet(WalletModel* walletModel)
{
#ifdef ENABLE_WALLET
window->addWallet(walletModel);

if (m_wallet_models.empty()) {
window->setCurrentWallet(walletModel->getWalletName());
}

connect(walletModel, SIGNAL(coinsSent(WalletModel*, SendCoinsRecipient, QByteArray)),
paymentServer, SLOT(fetchPaymentACK(WalletModel*, const SendCoinsRecipient&, QByteArray)));

m_wallet_models.push_back(walletModel);
#endif
}

void BitcoinApplication::initializeResult(bool success)
{
qDebug() << __func__ << ": Initialization result: " << success;
Expand All @@ -465,19 +483,13 @@ void BitcoinApplication::initializeResult(bool success)
window->setClientModel(clientModel);

#ifdef ENABLE_WALLET
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 (m_wallet_models.empty()) {
window->setCurrentWallet(walletModel->getWalletName());
}
m_handler_load_wallet = m_node.handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) {
QMetaObject::invokeMethod(this, "addWallet", Qt::QueuedConnection,
Q_ARG(WalletModel*, new WalletModel(std::move(wallet), m_node, platformStyle, optionsModel)));
});

connect(walletModel, SIGNAL(coinsSent(WalletModel*,SendCoinsRecipient,QByteArray)),
paymentServer, SLOT(fetchPaymentACK(WalletModel*,const SendCoinsRecipient&,QByteArray)));

m_wallet_models.push_back(walletModel);
for (auto& wallet : m_node.getWallets()) {
addWallet(new WalletModel(std::move(wallet), m_node, platformStyle, optionsModel));
}
#endif

Expand Down Expand Up @@ -593,6 +605,9 @@ int main(int argc, char *argv[])
// IMPORTANT if it is no longer a typedef use the normal variant above
qRegisterMetaType< CAmount >("CAmount");
qRegisterMetaType< std::function<void(void)> >("std::function<void(void)>");
#ifdef ENABLE_WALLET
qRegisterMetaType<WalletModel*>("WalletModel*");
#endif

/// 3. Application identification
// must be set before OptionsModel is initialized or translations are loaded,
Expand Down

0 comments on commit 0e674ba

Please sign in to comment.