From db2effaca4cf82bf806596d16f9797d3692e2da7 Mon Sep 17 00:00:00 2001 From: David Gumberg Date: Wed, 28 May 2025 16:23:35 -0700 Subject: [PATCH] scripted-diff: refactor: CWallet::Create() -> CreateNew() Aside from being more legible, changing the name of `CWallet::Create()` also validates that every instance where a new wallet is `Create()`'ed is handled in this branch. -BEGIN VERIFY SCRIPT- sed -i 's|\bCreate(|CreateNew(|g' src/wallet/wallet.cpp src/wallet/wallet.h src/wallet/test/util.cpp src/wallet/test/wallet_tests.cpp -END VERIFY SCRIPT- --- src/wallet/test/util.cpp | 2 +- src/wallet/test/wallet_tests.cpp | 2 +- src/wallet/wallet.cpp | 8 ++++---- src/wallet/wallet.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/wallet/test/util.cpp b/src/wallet/test/util.cpp index db85b5efe8f..0cc9217bb8a 100644 --- a/src/wallet/test/util.cpp +++ b/src/wallet/test/util.cpp @@ -51,7 +51,7 @@ std::shared_ptr TestCreateWallet(std::unique_ptr databa { bilingual_str _error; std::vector _warnings; - auto wallet = CWallet::Create(context, "", std::move(database), create_flags, _error, _warnings); + auto wallet = CWallet::CreateNew(context, "", std::move(database), create_flags, _error, _warnings); NotifyWalletLoaded(context, wallet); if (context.chain) { wallet->postInitProcess(); diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp index 4c422904990..e2d23602149 100644 --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -559,7 +559,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_descriptor_test, BasicTestingSetup) BOOST_CHECK_EXCEPTION(vr >> w_desc, std::ios_base::failure, malformed_descriptor); } -//! Test CWallet::Create() and its behavior handling potential race +//! Test CWallet::CreateNew() and its behavior handling potential race //! conditions if it's called the same time an incoming transaction shows up in //! the mempool or a new block. //! diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index d7663ed0e62..a21109a6041 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -414,7 +414,7 @@ std::shared_ptr CreateWallet(WalletContext& context, const std::string& // Make the wallet context.chain->initMessage(_("Creating wallet…")); - std::shared_ptr wallet = CWallet::Create(context, name, std::move(database), wallet_creation_flags, error, warnings); + std::shared_ptr wallet = CWallet::CreateNew(context, name, std::move(database), wallet_creation_flags, error, warnings); if (!wallet) { error = Untranslated("Wallet creation failed.") + Untranslated(" ") + error; status = DatabaseStatus::FAILED_CREATE; @@ -3025,7 +3025,7 @@ bool CWallet::LoadWalletArgs(std::shared_ptr wallet, const WalletContex return true; } -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::CreateNew(WalletContext& context, const std::string& name, std::unique_ptr database, uint64_t wallet_creation_flags, bilingual_str& error, std::vector& warnings) { interfaces::Chain* chain = context.chain; const std::string& walletFile = database->Filename(); @@ -4117,7 +4117,7 @@ bool DoMigration(CWallet& wallet, WalletContext& context, bilingual_str& error, return false; } - data->watchonly_wallet = CWallet::Create(empty_context, wallet_name, std::move(database), options.create_flags, error, warnings); + data->watchonly_wallet = CWallet::CreateNew(empty_context, wallet_name, std::move(database), options.create_flags, error, warnings); if (!data->watchonly_wallet) { error = _("Error: Failed to create new watchonly wallet"); return false; @@ -4156,7 +4156,7 @@ bool DoMigration(CWallet& wallet, WalletContext& context, bilingual_str& error, return false; } - data->solvable_wallet = CWallet::Create(empty_context, wallet_name, std::move(database), options.create_flags, error, warnings); + data->solvable_wallet = CWallet::CreateNew(empty_context, wallet_name, std::move(database), options.create_flags, error, warnings); if (!data->solvable_wallet) { error = _("Error: Failed to create new watchonly wallet"); return false; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index d09612a1f3f..b6c70dc54f4 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -874,7 +874,7 @@ public: static bool LoadWalletArgs(std::shared_ptr wallet, const WalletContext& context, bilingual_str& error, std::vector& warnings); /* Initializes, creates and returns a new CWallet; returns 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 CreateNew(WalletContext& context, const std::string& name, std::unique_ptr database, uint64_t wallet_creation_flags, bilingual_str& error, std::vector& warnings); /* Initializes, loads, and returns a CWallet from an existing wallet; returns a null pointer in case of an error */ static std::shared_ptr LoadExisting(WalletContext& context, const std::string& name, std::unique_ptr database, bilingual_str& error, std::vector& warnings);