Skip to content

Commit 0e674ba

Browse files
committed
ui: Support wallets loaded dynamically
1 parent 1c8fe0b commit 0e674ba

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

doc/release-notes-pr10740.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Previously, wallets could only be loaded at startup, by specifying `-wallet` par
55

66
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.
77

8-
This feature is currently only available through the RPC interface. Wallets loaded in this way will not display in the bitcoin-qt GUI.
8+
This feature is currently only available through the RPC interface. Wallets loaded in this way will display in the bitcoin-qt GUI.

src/qt/bitcoin.cpp

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public Q_SLOTS:
234234
void shutdownResult();
235235
/// Handle runaway exceptions. Shows a message box with the problem and quits the program.
236236
void handleRunawayException(const QString &message);
237+
void addWallet(WalletModel* walletModel);
237238

238239
Q_SIGNALS:
239240
void requestedInitialize();
@@ -251,6 +252,7 @@ public Q_SLOTS:
251252
#ifdef ENABLE_WALLET
252253
PaymentServer* paymentServer;
253254
std::vector<WalletModel*> m_wallet_models;
255+
std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
254256
#endif
255257
int returnValue;
256258
const PlatformStyle *platformStyle;
@@ -447,6 +449,22 @@ void BitcoinApplication::requestShutdown()
447449
Q_EMIT requestedShutdown();
448450
}
449451

452+
void BitcoinApplication::addWallet(WalletModel* walletModel)
453+
{
454+
#ifdef ENABLE_WALLET
455+
window->addWallet(walletModel);
456+
457+
if (m_wallet_models.empty()) {
458+
window->setCurrentWallet(walletModel->getWalletName());
459+
}
460+
461+
connect(walletModel, SIGNAL(coinsSent(WalletModel*, SendCoinsRecipient, QByteArray)),
462+
paymentServer, SLOT(fetchPaymentACK(WalletModel*, const SendCoinsRecipient&, QByteArray)));
463+
464+
m_wallet_models.push_back(walletModel);
465+
#endif
466+
}
467+
450468
void BitcoinApplication::initializeResult(bool success)
451469
{
452470
qDebug() << __func__ << ": Initialization result: " << success;
@@ -465,19 +483,13 @@ void BitcoinApplication::initializeResult(bool success)
465483
window->setClientModel(clientModel);
466484

467485
#ifdef ENABLE_WALLET
468-
auto wallets = m_node.getWallets();
469-
for (auto& wallet : wallets) {
470-
WalletModel * const walletModel = new WalletModel(std::move(wallet), m_node, platformStyle, optionsModel);
471-
472-
window->addWallet(walletModel);
473-
if (m_wallet_models.empty()) {
474-
window->setCurrentWallet(walletModel->getWalletName());
475-
}
486+
m_handler_load_wallet = m_node.handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) {
487+
QMetaObject::invokeMethod(this, "addWallet", Qt::QueuedConnection,
488+
Q_ARG(WalletModel*, new WalletModel(std::move(wallet), m_node, platformStyle, optionsModel)));
489+
});
476490

477-
connect(walletModel, SIGNAL(coinsSent(WalletModel*,SendCoinsRecipient,QByteArray)),
478-
paymentServer, SLOT(fetchPaymentACK(WalletModel*,const SendCoinsRecipient&,QByteArray)));
479-
480-
m_wallet_models.push_back(walletModel);
491+
for (auto& wallet : m_node.getWallets()) {
492+
addWallet(new WalletModel(std::move(wallet), m_node, platformStyle, optionsModel));
481493
}
482494
#endif
483495

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

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

0 commit comments

Comments
 (0)