From b8175721edfed903a580fac462c65cc537b0499d Mon Sep 17 00:00:00 2001 From: Igor Grkavac Date: Wed, 3 Feb 2021 16:48:49 +0100 Subject: [PATCH] [wallet] Handle load and open corrupted wallet --- src/wallet/api/wallet_manager.cpp | 3 ++- src/wallet/wallet.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/wallet/api/wallet_manager.cpp b/src/wallet/api/wallet_manager.cpp index b3775c4f7..51d97bac6 100644 --- a/src/wallet/api/wallet_manager.cpp +++ b/src/wallet/api/wallet_manager.cpp @@ -61,7 +61,8 @@ Wallet *WalletManagerImpl::createWallet(const std::string &path, const std::stri Wallet *WalletManagerImpl::openWallet(const std::string &path, const std::string &password, NetworkType nettype) { WalletImpl * wallet = new WalletImpl(nettype); - wallet->open(path, password); + if(!wallet->open(path, password)) + return nullptr; //Refresh addressBook wallet->addressBook()->refresh(); return wallet; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 95d34506c..89f959e1e 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -649,7 +649,12 @@ std::pair, password_container> wallet::make_from_file( auto wallet = make_basic(vm, opts, password_prompter); if (wallet) { - wallet->load(wallet_file, pwd->password()); + try { + wallet->load(wallet_file, pwd->password()); + } catch (...) { + std::cout << "Error loading wallet. Due to possible corruption, please remove wallet file and recreate it." << std::endl; + return {nullptr, password_container{}}; + } } return {std::move(wallet), std::move(*pwd)}; }