From e2a47ce08528dfb39c0340145c6977f6afd587f6 Mon Sep 17 00:00:00 2001 From: Ivan Metlushko Date: Fri, 18 Dec 2020 17:45:11 +0100 Subject: refactor: move first run detection to client code --- src/wallet/wallet.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/wallet/wallet.cpp') diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 456c26ea31..c4619a622b 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3247,11 +3247,10 @@ void CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::ve } } -DBErrors CWallet::LoadWallet(bool& fFirstRunRet) +DBErrors CWallet::LoadWallet() { LOCK(cs_wallet); - fFirstRunRet = false; DBErrors nLoadWalletRet = WalletBatch(GetDatabase()).LoadWallet(this); if (nLoadWalletRet == DBErrors::NEED_REWRITE) { @@ -3263,9 +3262,7 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet) } } - // This wallet is in its first run if there are no ScriptPubKeyMans and it isn't blank or no privkeys - fFirstRunRet = m_spk_managers.empty() && !IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && !IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET); - if (fFirstRunRet) { + if (m_spk_managers.empty()) { assert(m_external_spk_managers.empty()); assert(m_internal_spk_managers.empty()); } @@ -3893,11 +3890,10 @@ std::shared_ptr CWallet::Create(interfaces::Chain& chain, const std::st chain.initMessage(_("Loading wallet…").translated); int64_t nStart = GetTimeMillis(); - bool fFirstRun = true; // TODO: Can't use std::make_shared because we need a custom deleter but // should be possible to use std::allocate_shared. std::shared_ptr walletInstance(new CWallet(&chain, name, std::move(database)), ReleaseWallet); - DBErrors nLoadWalletRet = walletInstance->LoadWallet(fFirstRun); + DBErrors nLoadWalletRet = walletInstance->LoadWallet(); if (nLoadWalletRet != DBErrors::LOAD_OK) { if (nLoadWalletRet == DBErrors::CORRUPT) { error = strprintf(_("Error loading %s: Wallet corrupted"), walletFile); @@ -3924,6 +3920,10 @@ std::shared_ptr CWallet::Create(interfaces::Chain& chain, const std::st } } + // This wallet is in its first run if there are no ScriptPubKeyMans and it isn't blank or no privkeys + const bool fFirstRun = walletInstance->m_spk_managers.empty() && + !walletInstance->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && + !walletInstance->IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET); if (fFirstRun) { // ensure this wallet.dat can only be opened by clients supporting HD with chain split and expects no default key -- cgit v1.2.3