Skip to content

Commit 6bdd515

Browse files
committed
Merge #16923: wallet: Handle duplicate fileid exception
9eefc6e gui: Delete progress dialog instead of hidding it (João Barbosa) ee9e88b wallet: Handle duplicate fileid exception (João Barbosa) Pull request description: Handle the duplicate fileid exception thrown at `CheckUniqueFileid` in tow cases: - when duplicate wallets are set on the command line - catch in `LoadWallets`; - when a duplicate wallet is loaded dynamically - catch in `LoadWallet`. Fixes #16776. ACKs for top commit: jonatack: Re-ACK 9eefc6e no change since last review 68e0ff0e1f530c942721aab49cf67ffc07104628 hebasto: re-ACK 9eefc6e Tree-SHA512: 46e3c1cd6708b54e2d1c4973a74c8d5428822e04cecbc147cf200eb034efa385e867bd749c7c639020e83c9813fae8fed64a851bdd99abf60c33b07e0363f5d5
2 parents 5c1ba3a + 9eefc6e commit 6bdd515

File tree

5 files changed

+43
-25
lines changed

5 files changed

+43
-25
lines changed

src/qt/walletcontroller.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ WalletControllerActivity::~WalletControllerActivity()
166166

167167
void WalletControllerActivity::showProgressDialog(const QString& label_text)
168168
{
169+
assert(!m_progress_dialog);
169170
m_progress_dialog = new QProgressDialog(m_parent_widget);
170171

171172
m_progress_dialog->setLabelText(label_text);
@@ -175,6 +176,13 @@ void WalletControllerActivity::showProgressDialog(const QString& label_text)
175176
GUIUtil::PolishProgressDialog(m_progress_dialog);
176177
}
177178

179+
void WalletControllerActivity::destroyProgressDialog()
180+
{
181+
assert(m_progress_dialog);
182+
delete m_progress_dialog;
183+
m_progress_dialog = nullptr;
184+
}
185+
178186
CreateWalletActivity::CreateWalletActivity(WalletController* wallet_controller, QWidget* parent_widget)
179187
: WalletControllerActivity(wallet_controller, parent_widget)
180188
{
@@ -229,7 +237,7 @@ void CreateWalletActivity::createWallet()
229237

230238
void CreateWalletActivity::finish()
231239
{
232-
m_progress_dialog->hide();
240+
destroyProgressDialog();
233241

234242
if (!m_error_message.empty()) {
235243
QMessageBox::critical(m_parent_widget, tr("Create wallet failed"), QString::fromStdString(m_error_message));
@@ -270,7 +278,7 @@ OpenWalletActivity::OpenWalletActivity(WalletController* wallet_controller, QWid
270278

271279
void OpenWalletActivity::finish()
272280
{
273-
m_progress_dialog->hide();
281+
destroyProgressDialog();
274282

275283
if (!m_error_message.empty()) {
276284
QMessageBox::critical(m_parent_widget, tr("Open wallet failed"), QString::fromStdString(m_error_message));

src/qt/walletcontroller.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class WalletControllerActivity : public QObject
9696
QObject* worker() const { return m_wallet_controller->m_activity_worker; }
9797

9898
void showProgressDialog(const QString& label_text);
99+
void destroyProgressDialog();
99100

100101
WalletController* const m_wallet_controller;
101102
QWidget* const m_parent_widget;

src/wallet/load.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,23 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
6666

6767
bool LoadWallets(interfaces::Chain& chain, const std::vector<std::string>& wallet_files)
6868
{
69-
for (const std::string& walletFile : wallet_files) {
70-
std::string error;
71-
std::vector<std::string> warnings;
72-
std::shared_ptr<CWallet> pwallet = CWallet::CreateWalletFromFile(chain, WalletLocation(walletFile), error, warnings);
73-
if (!warnings.empty()) chain.initWarning(Join(warnings, "\n"));
74-
if (!pwallet) {
75-
chain.initError(error);
76-
return false;
69+
try {
70+
for (const std::string& walletFile : wallet_files) {
71+
std::string error;
72+
std::vector<std::string> warnings;
73+
std::shared_ptr<CWallet> pwallet = CWallet::CreateWalletFromFile(chain, WalletLocation(walletFile), error, warnings);
74+
if (!warnings.empty()) chain.initWarning(Join(warnings, "\n"));
75+
if (!pwallet) {
76+
chain.initError(error);
77+
return false;
78+
}
79+
AddWallet(pwallet);
7780
}
78-
AddWallet(pwallet);
81+
return true;
82+
} catch (const std::runtime_error& e) {
83+
chain.initError(e.what());
84+
return false;
7985
}
80-
81-
return true;
8286
}
8387

8488
void StartWallets(CScheduler& scheduler)

src/wallet/wallet.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,24 @@ void UnloadWallet(std::shared_ptr<CWallet>&& wallet)
148148

149149
std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const WalletLocation& location, std::string& error, std::vector<std::string>& warnings)
150150
{
151-
if (!CWallet::Verify(chain, location, false, error, warnings)) {
152-
error = "Wallet file verification failed: " + error;
153-
return nullptr;
154-
}
151+
try {
152+
if (!CWallet::Verify(chain, location, false, error, warnings)) {
153+
error = "Wallet file verification failed: " + error;
154+
return nullptr;
155+
}
155156

156-
std::shared_ptr<CWallet> wallet = CWallet::CreateWalletFromFile(chain, location, error, warnings);
157-
if (!wallet) {
158-
error = "Wallet loading failed: " + error;
157+
std::shared_ptr<CWallet> wallet = CWallet::CreateWalletFromFile(chain, location, error, warnings);
158+
if (!wallet) {
159+
error = "Wallet loading failed: " + error;
160+
return nullptr;
161+
}
162+
AddWallet(wallet);
163+
wallet->postInitProcess();
164+
return wallet;
165+
} catch (const std::runtime_error& e) {
166+
error = e.what();
159167
return nullptr;
160168
}
161-
AddWallet(wallet);
162-
wallet->postInitProcess();
163-
return wallet;
164169
}
165170

166171
std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const std::string& name, std::string& error, std::vector<std::string>& warnings)

test/functional/wallet_multiwallet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,10 @@ def wallet_file(name):
236236
assert_raises_rpc_error(-4, "Wallet file verification failed: Error loading wallet wallet.dat. Duplicate -wallet filename specified.", self.nodes[0].loadwallet, 'wallet.dat')
237237

238238
# Fail to load if one wallet is a copy of another
239-
assert_raises_rpc_error(-1, "BerkeleyBatch: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
239+
assert_raises_rpc_error(-4, "BerkeleyBatch: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
240240

241241
# Fail to load if one wallet is a copy of another, test this twice to make sure that we don't re-introduce #14304
242-
assert_raises_rpc_error(-1, "BerkeleyBatch: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
242+
assert_raises_rpc_error(-4, "BerkeleyBatch: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
243243

244244

245245
# Fail to load if wallet file is a symlink

0 commit comments

Comments
 (0)