Skip to content

Commit bd87e69

Browse files
committed
gui: Menu action for exporting a watchonly wallet
1 parent fc85c44 commit bd87e69

4 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/interfaces/wallet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ class Wallet
307307

308308
//! Return pointer to internal wallet class, useful for testing.
309309
virtual wallet::CWallet* wallet() { return nullptr; }
310+
311+
//! Export a watchonly wallet file. See CWallet::ExportWatchOnlyWallet
312+
virtual util::Result<std::string> exportWatchOnlyWallet(const fs::path& destination) = 0;
310313
};
311314

312315
//! Wallet chain client that in addition to having chain client methods for

src/qt/bitcoingui.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ void BitcoinGUI::createActions()
377377
m_mask_values_action->setStatusTip(tr("Mask the values in the Overview tab"));
378378
m_mask_values_action->setCheckable(true);
379379

380+
m_export_watchonly_action = new QAction(tr("Export watch-only wallet"), this);
381+
m_export_watchonly_action->setEnabled(false);
382+
m_export_watchonly_action->setStatusTip(tr("Export a watch-only version of the current wallet that can be restored onto another node."));
383+
380384
connect(quitAction, &QAction::triggered, this, &BitcoinGUI::quitRequested);
381385
connect(aboutAction, &QAction::triggered, this, &BitcoinGUI::aboutClicked);
382386
connect(aboutQtAction, &QAction::triggered, qApp, QApplication::aboutQt);
@@ -524,6 +528,11 @@ void BitcoinGUI::createActions()
524528
});
525529
connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::setPrivacy);
526530
connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::enableHistoryAction);
531+
connect(m_export_watchonly_action, &QAction::triggered, [this] {
532+
QString destination = GUIUtil::getSaveFileName(this, tr("Save Watch-only Wallet Export"), QString(), QString(), nullptr);
533+
if (destination.isEmpty()) return;
534+
walletFrame->currentWalletModel()->wallet().exportWatchOnlyWallet(GUIUtil::QStringToPath(destination));
535+
});
527536
}
528537
#endif // ENABLE_WALLET
529538

@@ -547,6 +556,7 @@ void BitcoinGUI::createMenuBar()
547556
file->addSeparator();
548557
file->addAction(backupWalletAction);
549558
file->addAction(m_restore_wallet_action);
559+
file->addAction(m_export_watchonly_action);
550560
file->addSeparator();
551561
file->addAction(openAction);
552562
file->addAction(signMessageAction);
@@ -755,6 +765,7 @@ void BitcoinGUI::setWalletController(WalletController* wallet_controller, bool s
755765
m_restore_wallet_action->setEnabled(true);
756766
m_migrate_wallet_action->setEnabled(true);
757767
m_migrate_wallet_action->setMenu(m_migrate_wallet_menu);
768+
m_export_watchonly_action->setEnabled(true);
758769

759770
GUIUtil::ExceptionSafeConnect(wallet_controller, &WalletController::walletAdded, this, &BitcoinGUI::addWallet);
760771
connect(wallet_controller, &WalletController::walletRemoved, this, &BitcoinGUI::removeWallet);

src/qt/bitcoingui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class BitcoinGUI : public QMainWindow
163163
QAction* m_mask_values_action{nullptr};
164164
QAction* m_migrate_wallet_action{nullptr};
165165
QMenu* m_migrate_wallet_menu{nullptr};
166+
QAction* m_export_watchonly_action{nullptr};
166167

167168
QLabel *m_wallet_selector_label = nullptr;
168169
QComboBox* m_wallet_selector = nullptr;

src/wallet/interfaces.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,11 @@ class WalletImpl : public Wallet
521521
}
522522
CWallet* wallet() override { return m_wallet.get(); }
523523

524+
util::Result<std::string> exportWatchOnlyWallet(const fs::path& destination) override {
525+
LOCK(m_wallet->cs_wallet);
526+
return m_wallet->ExportWatchOnlyWallet(destination, m_context);
527+
}
528+
524529
WalletContext& m_context;
525530
std::shared_ptr<CWallet> m_wallet;
526531
};

0 commit comments

Comments
 (0)