From d11471a9a04e1b00efd67f9cd5b184feb3e1945e Mon Sep 17 00:00:00 2001 From: tecnovert Date: Thu, 13 Jun 2024 17:25:48 +0200 Subject: [PATCH] wallet: Disable missing account warning in benchmarks. --- src/bench/particl_add_tx.cpp | 2 +- src/wallet/hdwallet.cpp | 2 +- src/wallet/hdwallet.h | 5 ++++- src/wallet/test/hdwallet_test_fixture.cpp | 1 + src/wallet/wallet.cpp | 4 ++-- src/wallet/wallet.h | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/bench/particl_add_tx.cpp b/src/bench/particl_add_tx.cpp index efc3ce750e87d..a5cbb52349fe3 100644 --- a/src/bench/particl_add_tx.cpp +++ b/src/bench/particl_add_tx.cpp @@ -128,7 +128,7 @@ static std::shared_ptr CreateTestWallet(wallet::WalletContext& wallet std::vector warnings; options.create_flags = WALLET_FLAG_BLANK_WALLET; auto database = MakeWalletDatabase(wallet_name, options, status, error); - auto wallet = CWallet::Create(wallet_context, wallet_name, std::move(database), options.create_flags, error, warnings); + auto wallet = CWallet::Create(wallet_context, wallet_name, std::move(database), options.create_flags, error, warnings, /*warn_no_active_acc*/ false); return std::static_pointer_cast(wallet); } diff --git a/src/wallet/hdwallet.cpp b/src/wallet/hdwallet.cpp index db83d8ec29f97..642416176f1e7 100644 --- a/src/wallet/hdwallet.cpp +++ b/src/wallet/hdwallet.cpp @@ -1628,7 +1628,7 @@ DBErrors CHDWallet::LoadWallet() */ } } - if (idDefaultAccount.IsNull() && m_chain) { // If !m_chain, probably running from particl-wallet + if (idDefaultAccount.IsNull() && m_chain && m_warn_no_active_acc) { // If !m_chain, probably running from particl-wallet std::string sWarning = "Warning: Wallet " + GetName() + " has no active account, please view the readme."; #ifndef ENABLE_QT tfm::format(std::cout, "%s\n", sWarning.c_str()); diff --git a/src/wallet/hdwallet.h b/src/wallet/hdwallet.h index fcda51b7779fa..cca089c52e5ad 100644 --- a/src/wallet/hdwallet.h +++ b/src/wallet/hdwallet.h @@ -39,8 +39,9 @@ class TxValidationState; class CHDWallet : public wallet::CWallet { public: - CHDWallet(interfaces::Chain* chain, const std::string& name, std::unique_ptr database) : CWallet(chain, name, std::move(database)) + CHDWallet(interfaces::Chain* chain, const std::string& name, std::unique_ptr database, bool warn_no_active_acc=true) : CWallet(chain, name, std::move(database)) { + m_warn_no_active_acc = warn_no_active_acc; m_default_address_type = OutputType::LEGACY; // In Particl segwit is enabled for all types m_fallback_fee = CFeeRate(DEFAULT_FALLBACK_FEE_PART); } @@ -580,6 +581,8 @@ class CHDWallet : public wallet::CWallet std::map m_derived_keys; // Allows multiple provisional derivations from the same extkey + bool m_warn_no_active_acc{true}; + private: void ParseAddressForMetaData(const CTxDestination &addr, COutputRecord &rec); diff --git a/src/wallet/test/hdwallet_test_fixture.cpp b/src/wallet/test/hdwallet_test_fixture.cpp index fab5376701cc7..35d7a8722ef17 100644 --- a/src/wallet/test/hdwallet_test_fixture.cpp +++ b/src/wallet/test/hdwallet_test_fixture.cpp @@ -24,6 +24,7 @@ HDWalletTestingSetup::HDWalletTestingSetup(const ChainType chain_type): m_wallet_loader{interfaces::MakeWalletLoader(*m_node.chain, *Assert(m_node.args))} { pwalletMain = std::make_shared(m_node.chain.get(), "", CreateMockWalletDatabaseBDB()); + pwalletMain->m_warn_no_active_acc = false; WalletContext& wallet_context = *m_wallet_loader->context(); AddWallet(wallet_context, pwalletMain); pwalletMain->LoadWallet(); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 358be0fcb7418..e38418c6a7ff1 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3092,7 +3092,7 @@ std::unique_ptr MakeWalletDatabase(const std::string& name, cons return MakeDatabase(wallet_path, options, status, error_string); } -std::shared_ptr CWallet::Create(WalletContext& context, const std::string& name, std::unique_ptr database, uint64_t wallet_creation_flags, bilingual_str& error, std::vector& warnings) +std::shared_ptr CWallet::Create(WalletContext& context, const std::string& name, std::unique_ptr database, uint64_t wallet_creation_flags, bilingual_str& error, std::vector& warnings, bool warn_no_active_acc) { interfaces::Chain* chain = context.chain; ArgsManager& args = *Assert(context.args); @@ -3102,7 +3102,7 @@ std::shared_ptr CWallet::Create(WalletContext& context, const std::stri // 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(fParticlMode - ? std::shared_ptr(new CHDWallet(chain, name, std::move(database)), ReleaseWallet) + ? std::shared_ptr(new CHDWallet(chain, name, std::move(database), warn_no_active_acc), ReleaseWallet) : std::shared_ptr(new CWallet(chain, name, std::move(database)), ReleaseWallet)); walletInstance->m_keypool_size = std::max(args.GetIntArg("-keypool", DEFAULT_KEYPOOL_SIZE), int64_t{1}); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index fed16167151ce..478a41a6b6b95 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -979,7 +979,7 @@ friend class CWalletTx; bool MarkReplaced(const uint256& originalHash, const uint256& newHash); /* Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error */ - static std::shared_ptr Create(WalletContext& context, const std::string& name, std::unique_ptr database, uint64_t wallet_creation_flags, bilingual_str& error, std::vector& warnings); + static std::shared_ptr Create(WalletContext& context, const std::string& name, std::unique_ptr database, uint64_t wallet_creation_flags, bilingual_str& error, std::vector& warnings, bool warn_no_active_acc=true); /** * Wallet post-init setup