Skip to content

Commit

Permalink
Merge pull request #251 from VanGrx/master
Browse files Browse the repository at this point in the history
[wallet] Handle load and open corrupted wallet
  • Loading branch information
VanGrx authored Feb 3, 2021
2 parents 7448880 + b817572 commit c4e5d8c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/wallet/api/wallet_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,12 @@ std::pair<std::unique_ptr<wallet>, 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)};
}
Expand Down

0 comments on commit c4e5d8c

Please sign in to comment.