refactor: Move wallet methods out of chain.h and node.h
Add WalletClient interface so node interface is cleaner and don't need wallet-specific methods. The new NodeContext::wallet_client pointer will also be needed to eliminate global wallet variables like ::vpwallets, because createWallet(), loadWallet(), getWallets(), etc methods called by the GUI need a way to get a reference to the list of open wallets if it is no longer a global variable. Also tweaks splash screen registration for load wallet events to be delayed until after wallet client is created.
This commit is contained in:
1 parent
b266b3e0bf
commit
e4f4350471
20 files changed
+111
-139
No files matched your search
@@ -266,6 +266,7 @@ void BitcoinApplication::createSplashScreen(const NetworkStyle *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 finish() happens.
|
||||
m_splash->show();
|
||||
connect(this, &BitcoinApplication::requestedInitialize, m_splash, &SplashScreen::handleLoadWallet);
|
||||
connect(this, &BitcoinApplication::splashFinished, m_splash, &SplashScreen::finish);
|
||||
connect(this, &BitcoinApplication::requestedShutdown, m_splash, &QWidget::close);
|
||||
}
|
||||
|
||||
@@ -1189,7 +1189,7 @@ void BitcoinGUI::incomingTransaction(const QString& date, int unit, const CAmoun
|
||||
// On new transaction, make an info balloon
|
||||
QString msg = tr("Date: %1\n").arg(date) +
|
||||
tr("Amount: %1\n").arg(BitcoinUnits::formatWithUnit(unit, amount, true));
|
||||
if (m_node.getWallets().size() > 1 && !walletName.isEmpty()) {
|
||||
if (m_node.walletClient().getWallets().size() > 1 && !walletName.isEmpty()) {
|
||||
msg += tr("Wallet: %1\n").arg(walletName);
|
||||
}
|
||||
msg += tr("Type: %1\n").arg(type);
|
||||
|
||||
@@ -198,8 +198,12 @@ void SplashScreen::subscribeToCoreSignals()
|
||||
// Connect signals to client
|
||||
m_handler_init_message = m_node->handleInitMessage(std::bind(InitMessage, this, std::placeholders::_1));
|
||||
m_handler_show_progress = m_node->handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
||||
}
|
||||
|
||||
void SplashScreen::handleLoadWallet()
|
||||
{
|
||||
#ifdef ENABLE_WALLET
|
||||
m_handler_load_wallet = m_node->handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) { ConnectWallet(std::move(wallet)); });
|
||||
m_handler_load_wallet = m_node->walletClient().handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) { ConnectWallet(std::move(wallet)); });
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,9 @@ public Q_SLOTS:
|
||||
/** Show message and progress */
|
||||
void showMessage(const QString &message, int alignment, const QColor &color);
|
||||
|
||||
/** Handle wallet load notifications. */
|
||||
void handleLoadWallet();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject * obj, QEvent * ev) override;
|
||||
|
||||
|
||||
@@ -35,11 +35,11 @@ WalletController::WalletController(ClientModel& client_model, const PlatformStyl
|
||||
, m_platform_style(platform_style)
|
||||
, m_options_model(client_model.getOptionsModel())
|
||||
{
|
||||
m_handler_load_wallet = m_node.handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) {
|
||||
m_handler_load_wallet = m_node.walletClient().handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) {
|
||||
getOrCreateWallet(std::move(wallet));
|
||||
});
|
||||
|
||||
for (std::unique_ptr<interfaces::Wallet>& wallet : m_node.getWallets()) {
|
||||
for (std::unique_ptr<interfaces::Wallet>& wallet : m_node.walletClient().getWallets()) {
|
||||
getOrCreateWallet(std::move(wallet));
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ std::map<std::string, bool> WalletController::listWalletDir() const
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
std::map<std::string, bool> wallets;
|
||||
for (const std::string& name : m_node.listWalletDir()) {
|
||||
for (const std::string& name : m_node.walletClient().listWalletDir()) {
|
||||
wallets[name] = false;
|
||||
}
|
||||
for (WalletModel* wallet_model : m_wallets) {
|
||||
@@ -250,7 +250,7 @@ void CreateWalletActivity::createWallet()
|
||||
|
||||
QTimer::singleShot(500, worker(), [this, name, flags] {
|
||||
WalletCreationStatus status;
|
||||
std::unique_ptr<interfaces::Wallet> wallet = node().createWallet(m_passphrase, flags, name, m_error_message, m_warning_message, status);
|
||||
std::unique_ptr<interfaces::Wallet> wallet = node().walletClient().createWallet(name, m_passphrase, flags, status, m_error_message, m_warning_message);
|
||||
|
||||
if (status == WalletCreationStatus::SUCCESS) m_wallet_model = m_wallet_controller->getOrCreateWallet(std::move(wallet));
|
||||
|
||||
@@ -321,7 +321,7 @@ void OpenWalletActivity::open(const std::string& path)
|
||||
showProgressDialog(tr("Opening Wallet <b>%1</b>...").arg(name.toHtmlEscaped()));
|
||||
|
||||
QTimer::singleShot(0, worker(), [this, path] {
|
||||
std::unique_ptr<interfaces::Wallet> wallet = node().loadWallet(path, m_error_message, m_warning_message);
|
||||
std::unique_ptr<interfaces::Wallet> wallet = node().walletClient().loadWallet(path, m_error_message, m_warning_message);
|
||||
|
||||
if (wallet) m_wallet_model = m_wallet_controller->getOrCreateWallet(std::move(wallet));
|
||||
|
||||
|
||||
@@ -581,7 +581,7 @@ QString WalletModel::getDisplayName() const
|
||||
|
||||
bool WalletModel::isMultiwallet()
|
||||
{
|
||||
return m_node.getWallets().size() > 1;
|
||||
return m_node.walletClient().getWallets().size() > 1;
|
||||
}
|
||||
|
||||
void WalletModel::refresh(bool pk_hash_only)
|
||||
|
||||
Reference in new issue
Block a user