diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp index b250d3510aff..634afe91696d 100644 --- a/src/bench/coin_selection.cpp +++ b/src/bench/coin_selection.cpp @@ -44,7 +44,7 @@ static void CoinSelection(benchmark::Bench& bench) { NodeContext node; auto chain = interfaces::MakeChain(node); - CWallet wallet(chain.get(), /*coinjoin_loader=*/nullptr, "", gArgs, CreateDummyWalletDatabase()); + CWallet wallet(chain.get(), "", CreateDummyWalletDatabase()); std::vector> wtxs; LOCK(wallet.cs_wallet); diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp index ed45c6646ce3..578dae5137dd 100644 --- a/src/bench/wallet_balance.cpp +++ b/src/bench/wallet_balance.cpp @@ -31,7 +31,7 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b // Set clock to genesis block, so the descriptors/keys creation time don't interfere with the blocks scanning process. // The reason is 'generatetoaddress', which creates a chain with deterministic timestamps in the past. SetMockTime(test_setup->m_node.chainman->GetParams().GenesisBlock().nTime); - CWallet wallet{test_setup->m_node.chain.get(), test_setup->m_node.coinjoin_loader.get(), "", gArgs, CreateMockWalletDatabase()}; + CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockWalletDatabase()}; { LOCK(wallet.cs_wallet); wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS); diff --git a/src/bench/wallet_create_tx.cpp b/src/bench/wallet_create_tx.cpp index c528c16be754..022234c40298 100644 --- a/src/bench/wallet_create_tx.cpp +++ b/src/bench/wallet_create_tx.cpp @@ -84,7 +84,7 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type { const auto test_setup = MakeNoLogFileContext(); - CWallet wallet{test_setup->m_node.chain.get(), test_setup->m_node.coinjoin_loader.get(), "", gArgs, CreateMockWalletDatabase()}; + CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockWalletDatabase()}; { LOCK(wallet.cs_wallet); wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS); @@ -137,7 +137,7 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type static void AvailableCoins(benchmark::Bench& bench, const std::vector& output_type) { const auto test_setup = MakeNoLogFileContext(); - CWallet wallet{test_setup->m_node.chain.get(), test_setup->m_node.coinjoin_loader.get(), "", gArgs, CreateMockWalletDatabase()}; + CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockWalletDatabase()}; { LOCK(wallet.cs_wallet); wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS); diff --git a/src/dummywallet.cpp b/src/dummywallet.cpp index 804e16cf2263..e8a572ce692c 100644 --- a/src/dummywallet.cpp +++ b/src/dummywallet.cpp @@ -96,8 +96,7 @@ std::unique_ptr MakeWallet(const std::shared_ptr& walle throw std::logic_error("Wallet function called in non-wallet build."); } -std::unique_ptr MakeWalletLoader(Chain& chain, ArgsManager& args, node::NodeContext& node_context, - interfaces::CoinJoin::Loader& coinjoin_loader) +std::unique_ptr MakeWalletLoader(Chain& chain, ArgsManager& args, node::NodeContext& node_context) { throw std::logic_error("Wallet function called in non-wallet build."); } diff --git a/src/init/bitcoin-gui.cpp b/src/init/bitcoin-gui.cpp index ba2ec494b6db..e4deb06e490f 100644 --- a/src/init/bitcoin-gui.cpp +++ b/src/init/bitcoin-gui.cpp @@ -32,9 +32,9 @@ class BitcoinGuiInit : public interfaces::Init { return interfaces::MakeCoinJoinLoader(m_node); } - std::unique_ptr makeWalletLoader(interfaces::Chain& chain, interfaces::CoinJoin::Loader& coinjoin_loader) override + std::unique_ptr makeWalletLoader(interfaces::Chain& chain) override { - return MakeWalletLoader(chain, *Assert(m_node.args), m_node, coinjoin_loader); + return MakeWalletLoader(chain, *Assert(m_node.args), m_node); } std::unique_ptr makeEcho() override { return interfaces::MakeEcho(); } interfaces::Ipc* ipc() override { return m_ipc.get(); } diff --git a/src/init/bitcoin-node.cpp b/src/init/bitcoin-node.cpp index ab981d030715..01ee2fa8a262 100644 --- a/src/init/bitcoin-node.cpp +++ b/src/init/bitcoin-node.cpp @@ -35,9 +35,9 @@ class BitcoinNodeInit : public interfaces::Init { return interfaces::MakeCoinJoinLoader(m_node); } - std::unique_ptr makeWalletLoader(interfaces::Chain& chain, interfaces::CoinJoin::Loader& coinjoin_loader) override + std::unique_ptr makeWalletLoader(interfaces::Chain& chain) override { - return MakeWalletLoader(chain, *Assert(m_node.args), m_node, coinjoin_loader); + return MakeWalletLoader(chain, *Assert(m_node.args), m_node); } std::unique_ptr makeEcho() override { return interfaces::MakeEcho(); } interfaces::Ipc* ipc() override { return m_ipc.get(); } diff --git a/src/init/bitcoin-qt.cpp b/src/init/bitcoin-qt.cpp index 20127c526e70..1b75221b1e4f 100644 --- a/src/init/bitcoin-qt.cpp +++ b/src/init/bitcoin-qt.cpp @@ -29,9 +29,9 @@ class BitcoinQtInit : public interfaces::Init { return interfaces::MakeCoinJoinLoader(m_node); } - std::unique_ptr makeWalletLoader(interfaces::Chain& chain, interfaces::CoinJoin::Loader& coinjoin_loader) override + std::unique_ptr makeWalletLoader(interfaces::Chain& chain) override { - return MakeWalletLoader(chain, *Assert(m_node.args), m_node, coinjoin_loader); + return MakeWalletLoader(chain, *Assert(m_node.args), m_node); } std::unique_ptr makeEcho() override { return interfaces::MakeEcho(); } node::NodeContext m_node; diff --git a/src/init/bitcoind.cpp b/src/init/bitcoind.cpp index 17127d6bd673..9eedba161e6c 100644 --- a/src/init/bitcoind.cpp +++ b/src/init/bitcoind.cpp @@ -32,9 +32,9 @@ class BitcoindInit : public interfaces::Init { return interfaces::MakeCoinJoinLoader(m_node); } - std::unique_ptr makeWalletLoader(interfaces::Chain& chain, interfaces::CoinJoin::Loader& coinjoin_loader) override + std::unique_ptr makeWalletLoader(interfaces::Chain& chain) override { - return MakeWalletLoader(chain, *Assert(m_node.args), m_node, coinjoin_loader); + return MakeWalletLoader(chain, *Assert(m_node.args), m_node); } std::unique_ptr makeEcho() override { return interfaces::MakeEcho(); } NodeContext& m_node; diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index 10486d0cdcab..75fa104be59c 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -48,6 +48,9 @@ namespace interfaces { class Wallet; class Handler; +namespace CoinJoin { +class Loader; +} // namespace CoinJoin //! Hash/height pair to help track and identify blocks. struct BlockKey { @@ -181,6 +184,10 @@ class Chain //! Return list of MN Collateral from outputs virtual std::vector listMNCollaterials(const std::vector>& outputs) = 0; + //! Return the loader that registers wallets with the node's CoinJoin + //! client manager, or nullptr when the node runs without one. + virtual CoinJoin::Loader* coinJoinLoader() = 0; + //! Return whether node has the block and optionally return block metadata //! or contents. virtual bool findBlock(const uint256& hash, const FoundBlock& block={}) = 0; diff --git a/src/interfaces/init.h b/src/interfaces/init.h index 6f664abdc43b..aab8ed663a2f 100644 --- a/src/interfaces/init.h +++ b/src/interfaces/init.h @@ -34,7 +34,7 @@ class Init virtual std::unique_ptr makeNode() { return nullptr; } virtual std::unique_ptr makeChain() { return nullptr; } virtual std::unique_ptr makeCoinJoinLoader() { return nullptr; } - virtual std::unique_ptr makeWalletLoader(interfaces::Chain&, CoinJoin::Loader&) { return nullptr; } + virtual std::unique_ptr makeWalletLoader(interfaces::Chain&) { return nullptr; } virtual std::unique_ptr makeEcho() { return nullptr; } virtual Ipc* ipc() { return nullptr; } }; diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h index e42bfe09d29d..78c71ffbdf41 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -64,9 +64,6 @@ struct WalletTx; struct WalletTxOut; struct WalletTxStatus; struct WalletMigrationResult; -namespace CoinJoin { -class Loader; -} using WalletOrderForm = std::vector>; using WalletValueMap = std::map; @@ -589,8 +586,7 @@ std::unique_ptr MakeWallet(wallet::WalletContext& context, const std::sh //! Return implementation of ChainClient interface for a wallet loader. This //! function will be undefined in builds where ENABLE_WALLET is false. -std::unique_ptr MakeWalletLoader(Chain& chain, ArgsManager& args, node::NodeContext& node_context, - CoinJoin::Loader& coinjoin_loader); +std::unique_ptr MakeWalletLoader(Chain& chain, ArgsManager& args, node::NodeContext& node_context); } // namespace interfaces diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index fce39a312367..43a662f632ba 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -1463,6 +1463,7 @@ class ChainImpl : public Chain } return listRet; } + interfaces::CoinJoin::Loader* coinJoinLoader() override { return m_node.coinjoin_loader.get(); } bool findBlock(const uint256& hash, const FoundBlock& block) override { WAIT_LOCK(cs_main, lock); diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 12e077381cb7..8ada0fb71e46 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -18,8 +18,9 @@ #include #include #include // for -dbcache defaults -#include // For DEFAULT_SCRIPTCHECK_THREADS #include +#include +#include // For DEFAULT_SCRIPTCHECK_THREADS #ifdef ENABLE_WALLET #include @@ -1128,6 +1129,11 @@ bool OptionsModel::isRestartRequired() const return settings.value("fRestartRequired", false).toBool(); } +bool OptionsModel::hasSigner() +{ + return gArgs.GetArg("-signer", "") != ""; +} + void OptionsModel::checkAndMigrate() { // Migration of default values diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 77ae75a38edd..a232cf6f45b5 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -149,6 +149,9 @@ class OptionsModel : public QAbstractListModel const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; } bool isOptionOverridden(const QString& option) const { return strOverriddenByCommandLine.contains(option); } + /** Whether -signer was set or not */ + bool hasSigner(); + /* Explicit setters */ void SetPruneTargetGB(int prune_target_gb); diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 693478d33ca5..9e71f3f46743 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -223,7 +223,7 @@ void SendCoinsDialog::setModel(WalletModel *_model) if (model->wallet().hasExternalSigner()) { //: "device" usually means a hardware wallet. ui->sendButton->setText(tr("Sign on device")); - if (gArgs.GetArg("-signer", "") != "") { + if (model->getOptionsModel()->hasSigner()) { ui->sendButton->setEnabled(true); ui->sendButton->setToolTip(tr("Connect your hardware wallet first.")); } else { diff --git a/src/qt/test/addressbooktests.cpp b/src/qt/test/addressbooktests.cpp index 1173ceae4ede..698863fe3219 100644 --- a/src/qt/test/addressbooktests.cpp +++ b/src/qt/test/addressbooktests.cpp @@ -72,7 +72,7 @@ void TestAddAddressesToSendBook(interfaces::Node& node) { TestChain100Setup test; node.setContext(&test.m_node); - const std::shared_ptr wallet = std::make_shared(node.context()->chain.get(), node.context()->coinjoin_loader.get(), "", gArgs, CreateMockWalletDatabase()); + const std::shared_ptr wallet = std::make_shared(node.context()->chain.get(), "", CreateMockWalletDatabase()); wallet->LoadWallet(); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); { diff --git a/src/qt/test/masternodetestutil.cpp b/src/qt/test/masternodetestutil.cpp index 1d6a15ee4b98..594b94fcfc1e 100644 --- a/src/qt/test/masternodetestutil.cpp +++ b/src/qt/test/masternodetestutil.cpp @@ -74,8 +74,7 @@ struct WalletOptions { std::shared_ptr MakeWallet(interfaces::Node& node, WalletContext& context, const std::string& name, const WalletOptions& options) { - auto wallet{std::make_shared(node.context()->chain.get(), node.context()->coinjoin_loader.get(), name, - gArgs, CreateMockWalletDatabase())}; + auto wallet{std::make_shared(node.context()->chain.get(), name, CreateMockWalletDatabase())}; wallet->LoadWallet(); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); const CBlockIndex* const tip{options.setup == nullptr diff --git a/src/qt/test/masternodewidgettests.cpp b/src/qt/test/masternodewidgettests.cpp index 979ff8bbb0fd..9dac30676fc7 100644 --- a/src/qt/test/masternodewidgettests.cpp +++ b/src/qt/test/masternodewidgettests.cpp @@ -407,8 +407,7 @@ void MasternodeWidgetTests::operationRunnerThreading() TestChain100Setup test; m_node.setContext(&test.m_node); WalletContext& context{*m_node.walletLoader().context()}; - const auto wallet{std::make_shared(m_node.context()->chain.get(), m_node.context()->coinjoin_loader.get(), - "", gArgs, CreateMockWalletDatabase())}; + const auto wallet{std::make_shared(m_node.context()->chain.get(), "", CreateMockWalletDatabase())}; wallet->LoadWallet(); auto wallet_interface{interfaces::MakeWallet(context, wallet)}; QVERIFY(wallet_interface != nullptr); @@ -456,8 +455,7 @@ void MasternodeWidgetTests::operationRunnerExceptions() TestChain100Setup test; m_node.setContext(&test.m_node); WalletContext& context{*m_node.walletLoader().context()}; - const auto wallet{std::make_shared(m_node.context()->chain.get(), m_node.context()->coinjoin_loader.get(), - "", gArgs, CreateMockWalletDatabase())}; + const auto wallet{std::make_shared(m_node.context()->chain.get(), "", CreateMockWalletDatabase())}; wallet->LoadWallet(); auto wallet_interface{interfaces::MakeWallet(context, wallet)}; QVERIFY(wallet_interface != nullptr); @@ -494,8 +492,7 @@ void MasternodeWidgetTests::operationRunnerShutdownDelivery() TestChain100Setup test; m_node.setContext(&test.m_node); WalletContext& context{*m_node.walletLoader().context()}; - const auto wallet{std::make_shared(m_node.context()->chain.get(), m_node.context()->coinjoin_loader.get(), - "", gArgs, CreateMockWalletDatabase())}; + const auto wallet{std::make_shared(m_node.context()->chain.get(), "", CreateMockWalletDatabase())}; wallet->LoadWallet(); auto wallet_interface{interfaces::MakeWallet(context, wallet)}; QVERIFY(wallet_interface != nullptr); @@ -551,8 +548,7 @@ void MasternodeWidgetTests::feeSourcePickerEligibility() TestChain100Setup test; m_node.setContext(&test.m_node); WalletContext& context{*m_node.walletLoader().context()}; - const auto wallet{std::make_shared(m_node.context()->chain.get(), m_node.context()->coinjoin_loader.get(), - "", gArgs, CreateMockWalletDatabase())}; + const auto wallet{std::make_shared(m_node.context()->chain.get(), "", CreateMockWalletDatabase())}; wallet->LoadWallet(); wallet->SetWalletFlag(wallet::WALLET_FLAG_DESCRIPTORS); @@ -617,8 +613,7 @@ void MasternodeWidgetTests::registeredCollateralExclusion() TestChain100Setup test; m_node.setContext(&test.m_node); WalletContext& context{*m_node.walletLoader().context()}; - const auto wallet{std::make_shared(m_node.context()->chain.get(), m_node.context()->coinjoin_loader.get(), - "", gArgs, CreateMockWalletDatabase())}; + const auto wallet{std::make_shared(m_node.context()->chain.get(), "", CreateMockWalletDatabase())}; wallet->LoadWallet(); wallet->SetWalletFlag(wallet::WALLET_FLAG_DESCRIPTORS); @@ -921,8 +916,7 @@ void MasternodeWidgetTests::masternodeListRegistrationAvailability() TestChain100Setup test; m_node.setContext(&test.m_node); WalletContext& context{*m_node.walletLoader().context()}; - const auto wallet{std::make_shared(m_node.context()->chain.get(), m_node.context()->coinjoin_loader.get(), - "", gArgs, CreateMockWalletDatabase())}; + const auto wallet{std::make_shared(m_node.context()->chain.get(), "", CreateMockWalletDatabase())}; wallet->LoadWallet(); MasternodeTestUtil::GuiModels models{m_node}; QVERIFY2(models.ok, qPrintable(QString::fromStdString(models.error.translated))); @@ -1005,8 +999,7 @@ void MasternodeWidgetTests::sharedMasternodeOwnedFilter() TestChain100Setup test; m_node.setContext(&test.m_node); WalletContext& context{*m_node.walletLoader().context()}; - const auto wallet{std::make_shared(m_node.context()->chain.get(), m_node.context()->coinjoin_loader.get(), - "", gArgs, CreateMockWalletDatabase())}; + const auto wallet{std::make_shared(m_node.context()->chain.get(), "", CreateMockWalletDatabase())}; wallet->LoadWallet(); wallet->SetWalletFlag(wallet::WALLET_FLAG_DESCRIPTORS); @@ -1043,8 +1036,7 @@ void MasternodeWidgetTests::sharedMasternodeContextMenu() TestChain100Setup test; m_node.setContext(&test.m_node); WalletContext& context{*m_node.walletLoader().context()}; - const auto wallet{std::make_shared(m_node.context()->chain.get(), m_node.context()->coinjoin_loader.get(), - "", gArgs, CreateMockWalletDatabase())}; + const auto wallet{std::make_shared(m_node.context()->chain.get(), "", CreateMockWalletDatabase())}; wallet->LoadWallet(); wallet->SetWalletFlag(wallet::WALLET_FLAG_DESCRIPTORS); @@ -1228,8 +1220,7 @@ void MasternodeWidgetTests::wizardInteractionLifecycle() TestChain100Setup test; m_node.setContext(&test.m_node); WalletContext& context{*m_node.walletLoader().context()}; - const auto wallet{std::make_shared(m_node.context()->chain.get(), m_node.context()->coinjoin_loader.get(), - "", gArgs, CreateMockWalletDatabase())}; + const auto wallet{std::make_shared(m_node.context()->chain.get(), "", CreateMockWalletDatabase())}; wallet->LoadWallet(); MasternodeTestUtil::GuiModels models{m_node}; QVERIFY2(models.ok, qPrintable(QString::fromStdString(models.error.translated))); @@ -1312,8 +1303,7 @@ void MasternodeWidgetTests::registrationResultStates() TestChain100Setup test; m_node.setContext(&test.m_node); WalletContext& context{*m_node.walletLoader().context()}; - const auto wallet{std::make_shared(m_node.context()->chain.get(), m_node.context()->coinjoin_loader.get(), - "", gArgs, CreateMockWalletDatabase())}; + const auto wallet{std::make_shared(m_node.context()->chain.get(), "", CreateMockWalletDatabase())}; wallet->LoadWallet(); MasternodeTestUtil::GuiModels models{m_node}; QVERIFY2(models.ok, qPrintable(QString::fromStdString(models.error.translated))); diff --git a/src/qt/test/providertransactiontests.cpp b/src/qt/test/providertransactiontests.cpp index 2c5cf694f413..c1698c8da128 100644 --- a/src/qt/test/providertransactiontests.cpp +++ b/src/qt/test/providertransactiontests.cpp @@ -220,8 +220,8 @@ void ProviderTransactionTests::providerTransactionHistory() m_node.setContext(&test.m_node); WalletContext& context{*m_node.walletLoader().context()}; - std::shared_ptr wallet{std::make_shared(test.m_node.chain.get(), test.m_node.coinjoin_loader.get(), - "", test.m_args, CreateMockWalletDatabase())}; + std::shared_ptr wallet{ + std::make_shared(test.m_node.chain.get(), "", CreateMockWalletDatabase())}; wallet->LoadWallet(); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); { diff --git a/src/qt/test/wallettests.cpp b/src/qt/test/wallettests.cpp index 229ccda349a8..c7f2690b1aa9 100644 --- a/src/qt/test/wallettests.cpp +++ b/src/qt/test/wallettests.cpp @@ -131,7 +131,7 @@ void TestGUI(interfaces::Node& node) } node.setContext(&test.m_node); WalletContext& context = *node.walletLoader().context(); - const std::shared_ptr wallet = std::make_shared(node.context()->chain.get(), node.context()->coinjoin_loader.get(), "", gArgs, CreateMockWalletDatabase()); + const std::shared_ptr wallet = std::make_shared(node.context()->chain.get(), "", CreateMockWalletDatabase()); AddWallet(context, wallet); wallet->LoadWallet(); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index 5fa799d2291e..de58860c7aea 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -395,7 +395,7 @@ TestingSetup::TestingSetup( // WalletTestingSetup m_node.coinjoin_loader = interfaces::MakeCoinJoinLoader(m_node); - auto wallet_loader = interfaces::MakeWalletLoader(*m_node.chain, *m_node.args, m_node, *m_node.coinjoin_loader); + auto wallet_loader = interfaces::MakeWalletLoader(*m_node.chain, *m_node.args, m_node); m_node.wallet_loader = wallet_loader.get(); m_node.chain_clients.emplace_back(std::move(wallet_loader)); #endif // ENABLE_WALLET diff --git a/src/wallet/context.h b/src/wallet/context.h index 0ba5076659a3..877301715bc0 100644 --- a/src/wallet/context.h +++ b/src/wallet/context.h @@ -15,9 +15,6 @@ class ArgsManager; namespace interfaces { class Chain; -namespace CoinJoin { -class Loader; -} // namspace CoinJoin class Wallet; } // namespace interfaces namespace node { @@ -48,7 +45,6 @@ struct WalletContext { std::vector> wallets GUARDED_BY(wallets_mutex); std::list wallet_loading_fns GUARDED_BY(wallets_mutex); std::list wallet_load_fns GUARDED_BY(wallets_mutex); - interfaces::CoinJoin::Loader* coinjoin_loader{nullptr}; // Some Dash RPCs rely on WalletContext yet access NodeContext members // even though wallet RPCs should refrain from accessing non-wallet // capabilities (even though it is a hard ask sometimes). We should get diff --git a/src/wallet/dump.cpp b/src/wallet/dump.cpp index 95b669f9382e..3344cfd0be7e 100644 --- a/src/wallet/dump.cpp +++ b/src/wallet/dump.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -199,7 +200,7 @@ bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs:: // dummy chain interface bool ret = true; - std::shared_ptr wallet(new CWallet(/*chain=*/nullptr, /*coinjoin_loader=*/nullptr, name, gArgs, std::move(database)), WalletToolReleaseWallet); + std::shared_ptr wallet(new CWallet(/*chain=*/nullptr, name, std::move(database)), WalletToolReleaseWallet); { LOCK(wallet->cs_wallet); DBErrors load_wallet_ret = wallet->LoadWallet(); diff --git a/src/wallet/external_signer_scriptpubkeyman.h b/src/wallet/external_signer_scriptpubkeyman.h index efb1b797f137..f2747ce7fd0c 100644 --- a/src/wallet/external_signer_scriptpubkeyman.h +++ b/src/wallet/external_signer_scriptpubkeyman.h @@ -13,11 +13,11 @@ namespace wallet { class ExternalSignerScriptPubKeyMan : public DescriptorScriptPubKeyMan { public: - ExternalSignerScriptPubKeyMan(WalletStorage& storage, WalletDescriptor& descriptor) - : DescriptorScriptPubKeyMan(storage, descriptor) + ExternalSignerScriptPubKeyMan(WalletStorage& storage, WalletDescriptor& descriptor, int64_t keypool_size) + : DescriptorScriptPubKeyMan(storage, descriptor, keypool_size) {} - ExternalSignerScriptPubKeyMan(WalletStorage& storage) - : DescriptorScriptPubKeyMan(storage) + ExternalSignerScriptPubKeyMan(WalletStorage& storage, int64_t keypool_size) + : DescriptorScriptPubKeyMan(storage, keypool_size) {} /** Provide a descriptor at setup time diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp index b4dfeed6ff46..f729d4ee7c4d 100644 --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -187,7 +187,7 @@ void WalletInit::Construct(NodeContext& node) const return; } node.coinjoin_loader = node.init->makeCoinJoinLoader(); - auto wallet_loader = node.init->makeWalletLoader(*node.chain, *node.coinjoin_loader); + auto wallet_loader = node.init->makeWalletLoader(*node.chain); node.wallet_loader = wallet_loader.get(); node.chain_clients.emplace_back(std::move(wallet_loader)); } diff --git a/src/wallet/interfaces.cpp b/src/wallet/interfaces.cpp index 83ddf3a38cb4..5b33cf44d599 100644 --- a/src/wallet/interfaces.cpp +++ b/src/wallet/interfaces.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -905,13 +904,11 @@ class WalletLoaderImpl : public WalletLoader } public: - WalletLoaderImpl(Chain& chain, ArgsManager& args, NodeContext& node_context, - interfaces::CoinJoin::Loader& coinjoin_loader) + WalletLoaderImpl(Chain& chain, ArgsManager& args, NodeContext& node_context) { m_context.chain = &chain; m_context.args = &args; m_context.node_context = &node_context; - m_context.coinjoin_loader = &coinjoin_loader; } ~WalletLoaderImpl() override { UnloadWallets(m_context); } @@ -1025,9 +1022,8 @@ class WalletLoaderImpl : public WalletLoader namespace interfaces { std::unique_ptr MakeWallet(wallet::WalletContext& context, const std::shared_ptr& wallet) { return wallet ? std::make_unique(context, wallet) : nullptr; } -std::unique_ptr MakeWalletLoader(Chain& chain, ArgsManager& args, NodeContext& node_context, - interfaces::CoinJoin::Loader& coinjoin_loader) +std::unique_ptr MakeWalletLoader(Chain& chain, ArgsManager& args, NodeContext& node_context) { - return std::make_unique(chain, args, node_context, coinjoin_loader); + return std::make_unique(chain, args, node_context); } } // namespace interfaces diff --git a/src/wallet/load.cpp b/src/wallet/load.cpp index 864b047e7712..b3cd26909bbf 100644 --- a/src/wallet/load.cpp +++ b/src/wallet/load.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -134,8 +135,8 @@ bool LoadWallets(WalletContext& context) return false; } - NotifyWalletLoaded(context, pwallet); AddWallet(context, pwallet); + NotifyWalletLoaded(context, pwallet); } return true; } catch (const std::runtime_error& e) { @@ -161,9 +162,8 @@ void FlushWallets(WalletContext& context) { for (const std::shared_ptr& pwallet : GetWallets(context)) { if (CCoinJoinClientOptions::IsEnabled()) { - assert(pwallet->coinjoin_available()); // Stop CoinJoin, release keys - pwallet->coinjoin_loader().FlushWallet(pwallet->GetName()); + Assert(pwallet->chain().coinJoinLoader())->FlushWallet(pwallet->GetName()); } pwallet->Flush(); } diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp index 12a75aca2b22..7020f752a9e9 100644 --- a/src/wallet/rpc/backup.cpp +++ b/src/wallet/rpc/backup.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -1713,7 +1712,7 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c } else { warnings.push_back("Range not given, using default keypool range"); range_start = 0; - range_end = gArgs.GetIntArg("-keypool", DEFAULT_KEYPOOL_SIZE); + range_end = wallet.m_keypool_size; } next_index = range_start; diff --git a/src/wallet/rpc/util.cpp b/src/wallet/rpc/util.cpp index e8069858861b..9da58289d09f 100644 --- a/src/wallet/rpc/util.cpp +++ b/src/wallet/rpc/util.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include diff --git a/src/wallet/salvage.cpp b/src/wallet/salvage.cpp index 52c17f0012ef..3bab0472e5cd 100644 --- a/src/wallet/salvage.cpp +++ b/src/wallet/salvage.cpp @@ -135,7 +135,7 @@ bool RecoverDatabaseFile(const ArgsManager& args, const fs::path& file_path, bil } DbTxn* ptxn = env->TxnBegin(); - CWallet dummyWallet(/*chain=*/nullptr, /*coinjoin_loader=*/nullptr, "", gArgs, CreateDummyWalletDatabase()); + CWallet dummyWallet(/*chain=*/nullptr, "", CreateDummyWalletDatabase()); dummyWallet.SetupLegacyScriptPubKeyMan(); for (KeyValPair& row : salvagedData) { diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index 5b96da6fffb0..94e56af4a09e 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -1472,7 +1471,7 @@ bool LegacyScriptPubKeyMan::TopUpInner(unsigned int kpSize) if (kpSize > 0) nTargetSize = kpSize; else - nTargetSize = std::max(gArgs.GetIntArg("-keypool", DEFAULT_KEYPOOL_SIZE), (int64_t) 0); + nTargetSize = m_keypool_size; // count amount of available keys (internal, external) // make sure the keypool of external and internal keys fits the user selected target (-keypool) @@ -1952,7 +1951,7 @@ std::optional LegacyScriptPubKeyMan::MigrateToDescriptor() WalletDescriptor w_desc(std::move(desc), creation_time, 0, 0, 0); // Make the DescriptorScriptPubKeyMan and get the scriptPubKeys - auto desc_spk_man = std::unique_ptr(new DescriptorScriptPubKeyMan(m_storage, w_desc)); + auto desc_spk_man = std::unique_ptr(new DescriptorScriptPubKeyMan(m_storage, w_desc, m_keypool_size)); desc_spk_man->AddDescriptorKey(key, key.GetPubKey()); desc_spk_man->TopUp(); auto desc_spks = desc_spk_man->GetScriptPubKeys(); @@ -2038,7 +2037,7 @@ std::optional LegacyScriptPubKeyMan::MigrateToDescriptor() } WalletDescriptor w_desc(std::move(desc), 0, 0, chain_counter, 0); - auto desc_spk_man = std::unique_ptr(new DescriptorScriptPubKeyMan(m_storage, w_desc)); + auto desc_spk_man = std::unique_ptr(new DescriptorScriptPubKeyMan(m_storage, w_desc, m_keypool_size)); desc_spk_man->AddDescriptorKey(master_key.key, master_key.key.GetPubKey(), out.mnemonic, out.mnemonic_passphrase); desc_spk_man->TopUp(); auto desc_spks = desc_spk_man->GetScriptPubKeys(); @@ -2092,7 +2091,7 @@ std::optional LegacyScriptPubKeyMan::MigrateToDescriptor() } else { // Make the DescriptorScriptPubKeyMan and get the scriptPubKeys WalletDescriptor w_desc(std::move(desc), creation_time, 0, 0, 0); - auto desc_spk_man = std::unique_ptr(new DescriptorScriptPubKeyMan(m_storage, w_desc)); + auto desc_spk_man = std::unique_ptr(new DescriptorScriptPubKeyMan(m_storage, w_desc, m_keypool_size)); for (const auto& keyid : privkeyids) { CKey key; if (!GetKey(keyid, key)) { @@ -2355,7 +2354,7 @@ bool DescriptorScriptPubKeyMan::TopUp(unsigned int size) if (size > 0) { target_size = size; } else { - target_size = std::max(gArgs.GetIntArg("-keypool", DEFAULT_KEYPOOL_SIZE), int64_t{1}); + target_size = m_keypool_size; } // Calculate the new range_end diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h index 4d335551b47e..b9c9567fb76c 100644 --- a/src/wallet/scriptpubkeyman.h +++ b/src/wallet/scriptpubkeyman.h @@ -293,6 +293,9 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv int64_t nTimeFirstKey GUARDED_BY(cs_KeyStore) = 0; + //! Number of pre-generated keys/scripts (part of the look-ahead process, used to detect payments) + int64_t m_keypool_size GUARDED_BY(cs_KeyStore){DEFAULT_KEYPOOL_SIZE}; + bool HaveKeyInner(const CKeyID &address) const; bool AddKeyPubKeyInner(const CKey& key, const CPubKey &pubkey); bool AddCryptedKeyInner(const CPubKey &vchPubKey, const std::vector &vchCryptedSecret); @@ -353,7 +356,7 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv bool ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool, bool fRequestedInternal); public: - using ScriptPubKeyMan::ScriptPubKeyMan; + LegacyScriptPubKeyMan(WalletStorage& storage, int64_t keypool_size) : ScriptPubKeyMan(storage), m_keypool_size(keypool_size) {} util::Result GetNewDestination() override; isminetype IsMine(const CScript& script) const override; @@ -578,6 +581,9 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan //! keeps track of whether Unlock has run a thorough check before bool m_decryption_thoroughly_checked = false; + //! Number of pre-generated keys/scripts (part of the look-ahead process, used to detect payments) + int64_t m_keypool_size GUARDED_BY(cs_desc_man){DEFAULT_KEYPOOL_SIZE}; + bool AddDescriptorKeyWithDB(WalletBatch& batch, const CKey& key, const CPubKey &pubkey, const SecureString& mnemonic, const SecureString& mnemonic_passphrase) EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man); KeyMap GetKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man); @@ -595,12 +601,14 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan WalletDescriptor m_wallet_descriptor GUARDED_BY(cs_desc_man); public: - DescriptorScriptPubKeyMan(WalletStorage& storage, WalletDescriptor& descriptor) + DescriptorScriptPubKeyMan(WalletStorage& storage, WalletDescriptor& descriptor, int64_t keypool_size) : ScriptPubKeyMan(storage), + m_keypool_size(keypool_size), m_wallet_descriptor(descriptor) {} - DescriptorScriptPubKeyMan(WalletStorage& storage) - : ScriptPubKeyMan(storage) + DescriptorScriptPubKeyMan(WalletStorage& storage, int64_t keypool_size) + : ScriptPubKeyMan(storage), + m_keypool_size(keypool_size) {} mutable RecursiveMutex cs_desc_man; diff --git a/src/wallet/test/coinjoin_tests.cpp b/src/wallet/test/coinjoin_tests.cpp index 7070a569e363..6d04f5fb5f57 100644 --- a/src/wallet/test/coinjoin_tests.cpp +++ b/src/wallet/test/coinjoin_tests.cpp @@ -142,11 +142,10 @@ class CTransactionBuilderTestSetup : public TestChain100Setup { public: CTransactionBuilderTestSetup() : - wallet{std::make_unique(m_node.chain.get(), m_node.coinjoin_loader.get(), "", m_args, CreateMockWalletDatabase())} + wallet{std::make_unique(m_node.chain.get(), "", CreateMockWalletDatabase())} { context.args = &m_args; context.chain = m_node.chain.get(); - context.coinjoin_loader = m_node.coinjoin_loader.get(); CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); wallet->SetupLegacyScriptPubKeyMan(); wallet->LoadWallet(); diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp index b330da82c9c5..38d3cfb8c3e7 100644 --- a/src/wallet/test/coinselector_tests.cpp +++ b/src/wallet/test/coinselector_tests.cpp @@ -315,7 +315,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test) coin_selection_params_bnb.m_cost_of_change = coin_selection_params_bnb.m_effective_feerate.GetFee(coin_selection_params_bnb.change_spend_size) + coin_selection_params_bnb.m_change_fee; coin_selection_params_bnb.min_viable_change = coin_selection_params_bnb.m_effective_feerate.GetFee(coin_selection_params_bnb.change_spend_size); { - std::unique_ptr wallet = std::make_unique(m_node.chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateMockWalletDatabase()); + std::unique_ptr wallet = std::make_unique(m_node.chain.get(), "", CreateMockWalletDatabase()); wallet->LoadWallet(); LOCK(wallet->cs_wallet); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); @@ -337,7 +337,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test) } { - std::unique_ptr wallet = std::make_unique(m_node.chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateMockWalletDatabase()); + std::unique_ptr wallet = std::make_unique(m_node.chain.get(), "", CreateMockWalletDatabase()); wallet->LoadWallet(); LOCK(wallet->cs_wallet); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); @@ -360,7 +360,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test) BOOST_CHECK(result10); } { - std::unique_ptr wallet = std::make_unique(m_node.chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateMockWalletDatabase()); + std::unique_ptr wallet = std::make_unique(m_node.chain.get(), "", CreateMockWalletDatabase()); wallet->LoadWallet(); LOCK(wallet->cs_wallet); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); @@ -426,7 +426,7 @@ BOOST_AUTO_TEST_CASE(knapsack_solver_test) FastRandomContext rand{}; const auto temp1{[&rand](std::vector& g, const CAmount& v, CAmount c) { return KnapsackSolver(g, v, c, rand); }}; const auto KnapsackSolver{temp1}; - std::unique_ptr wallet = std::make_unique(m_node.chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateMockWalletDatabase()); + std::unique_ptr wallet = std::make_unique(m_node.chain.get(), "", CreateMockWalletDatabase()); wallet->LoadWallet(); LOCK(wallet->cs_wallet); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); @@ -736,7 +736,7 @@ BOOST_AUTO_TEST_CASE(knapsack_solver_test) BOOST_AUTO_TEST_CASE(ApproximateBestSubset) { FastRandomContext rand{}; - std::unique_ptr wallet = std::make_unique(m_node.chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateMockWalletDatabase()); + std::unique_ptr wallet = std::make_unique(m_node.chain.get(), "", CreateMockWalletDatabase()); wallet->LoadWallet(); LOCK(wallet->cs_wallet); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); @@ -758,7 +758,7 @@ BOOST_AUTO_TEST_CASE(ApproximateBestSubset) // Tests that with the ideal conditions, the coin selector will always be able to find a solution that can pay the target value BOOST_AUTO_TEST_CASE(SelectCoins_test) { - std::unique_ptr wallet = std::make_unique(m_node.chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateMockWalletDatabase()); + std::unique_ptr wallet = std::make_unique(m_node.chain.get(), "", CreateMockWalletDatabase()); wallet->LoadWallet(); LOCK(wallet->cs_wallet); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); @@ -949,7 +949,7 @@ BOOST_AUTO_TEST_CASE(SelectCoins_effective_value_test) // This test creates a coin whose value is higher than the target but whose effective value is lower than the target. // The coin is selected using coin control, with m_allow_other_inputs = false. SelectCoins should fail due to insufficient funds. - std::unique_ptr wallet = std::make_unique(m_node.chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateMockWalletDatabase()); + std::unique_ptr wallet = std::make_unique(m_node.chain.get(), "", CreateMockWalletDatabase()); wallet->LoadWallet(); LOCK(wallet->cs_wallet); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); @@ -957,7 +957,7 @@ BOOST_AUTO_TEST_CASE(SelectCoins_effective_value_test) CoinsResult available_coins; { - std::unique_ptr dummyWallet = std::make_unique(m_node.chain.get(), /*coinjoin_loader=*/nullptr, "dummy", m_args, CreateMockWalletDatabase()); + std::unique_ptr dummyWallet = std::make_unique(m_node.chain.get(), "dummy", CreateMockWalletDatabase()); dummyWallet->LoadWallet(); LOCK(dummyWallet->cs_wallet); dummyWallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); @@ -998,7 +998,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_coinsresult_test, TestingSetup) // Test case to verify CoinsResult object sanity. CoinsResult available_coins; { - std::unique_ptr dummyWallet = std::make_unique(m_node.chain.get(), /*coinjoin_loader=*/nullptr, "dummy", m_args, CreateMockWalletDatabase()); + std::unique_ptr dummyWallet = std::make_unique(m_node.chain.get(), "dummy", CreateMockWalletDatabase()); BOOST_CHECK_EQUAL(dummyWallet->LoadWallet(), DBErrors::LOAD_OK); LOCK(dummyWallet->cs_wallet); dummyWallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); @@ -1039,7 +1039,7 @@ static util::Result SelectCoinsSRDResult(const CAmount& target, int max_weight, std::function coin_setup) { - std::unique_ptr wallet = std::make_unique(m_node.chain.get(), /*coinjoin_loader=*/nullptr, "", gArgs, CreateMockWalletDatabase()); + std::unique_ptr wallet = std::make_unique(m_node.chain.get(), "", CreateMockWalletDatabase()); wallet->LoadWallet(); LOCK(wallet->cs_wallet); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); @@ -1109,7 +1109,7 @@ BOOST_AUTO_TEST_CASE(srd_tests) static util::Result select_coins(const CAmount& target, const CoinSelectionParams& cs_params, const CCoinControl& cc, std::function coin_setup, const node::NodeContext& m_node) { - std::unique_ptr wallet = std::make_unique(m_node.chain.get(), /*coinjoin_loader=*/nullptr, "", gArgs, CreateMockWalletDatabase()); + std::unique_ptr wallet = std::make_unique(m_node.chain.get(), "", CreateMockWalletDatabase()); wallet->LoadWallet(); LOCK(wallet->cs_wallet); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); diff --git a/src/wallet/test/init_test_fixture.cpp b/src/wallet/test/init_test_fixture.cpp index cd854e271831..7c33dbcfce3b 100644 --- a/src/wallet/test/init_test_fixture.cpp +++ b/src/wallet/test/init_test_fixture.cpp @@ -3,7 +3,6 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include -#include #include #include @@ -15,8 +14,7 @@ namespace wallet { InitWalletDirTestingSetup::InitWalletDirTestingSetup(const std::string& chainName) : BasicTestingSetup(chainName) { - m_coinjoin_loader = interfaces::MakeCoinJoinLoader(m_node); - m_wallet_loader = MakeWalletLoader(*m_node.chain, m_args, m_node, *Assert(m_coinjoin_loader)); + m_wallet_loader = MakeWalletLoader(*m_node.chain, m_args, m_node); const auto sep = fs::path::preferred_separator; diff --git a/src/wallet/test/init_test_fixture.h b/src/wallet/test/init_test_fixture.h index 46363ccd29bf..d9f6f79d0043 100644 --- a/src/wallet/test/init_test_fixture.h +++ b/src/wallet/test/init_test_fixture.h @@ -6,7 +6,6 @@ #define BITCOIN_WALLET_TEST_INIT_TEST_FIXTURE_H #include -#include #include #include #include @@ -20,7 +19,6 @@ struct InitWalletDirTestingSetup: public BasicTestingSetup { fs::path m_datadir; fs::path m_cwd; std::map m_walletdir_path_cases; - std::unique_ptr m_coinjoin_loader; std::unique_ptr m_wallet_loader; }; } // namespace wallet diff --git a/src/wallet/test/ismine_tests.cpp b/src/wallet/test/ismine_tests.cpp index cf0f3cb4f3c8..357194481fa4 100644 --- a/src/wallet/test/ismine_tests.cpp +++ b/src/wallet/test/ismine_tests.cpp @@ -56,7 +56,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard) // P2PK compressed - Legacy { - CWallet keystore(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet keystore(chain.get(), "", CreateDummyWalletDatabase()); keystore.SetupLegacyScriptPubKeyMan(); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); scriptPubKey = GetScriptForRawPubKey(pubkeys[0]); @@ -75,7 +75,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard) // P2PK compressed - Descriptor { - CWallet keystore(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet keystore(chain.get(), "", CreateDummyWalletDatabase()); std::string desc_str = "pk(" + EncodeSecret(keys[0]) + ")"; auto spk_manager = CreateDescriptor(keystore, desc_str, true); @@ -87,7 +87,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard) // P2PK uncompressed - Legacy { - CWallet keystore(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet keystore(chain.get(), "", CreateDummyWalletDatabase()); keystore.SetupLegacyScriptPubKeyMan(); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); scriptPubKey = GetScriptForRawPubKey(uncompressedPubkey); @@ -106,7 +106,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard) // P2PK uncompressed - Descriptor { - CWallet keystore(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet keystore(chain.get(), "", CreateDummyWalletDatabase()); std::string desc_str = "pk(" + EncodeSecret(uncompressedKey) + ")"; auto spk_manager = CreateDescriptor(keystore, desc_str, true); @@ -118,7 +118,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard) // P2PKH compressed - Legacy { - CWallet keystore(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet keystore(chain.get(), "", CreateDummyWalletDatabase()); keystore.SetupLegacyScriptPubKeyMan(); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); scriptPubKey = GetScriptForDestination(PKHash(pubkeys[0])); @@ -137,7 +137,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard) // P2PKH compressed - Descriptor { - CWallet keystore(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet keystore(chain.get(), "", CreateDummyWalletDatabase()); std::string desc_str = "pkh(" + EncodeSecret(keys[0]) + ")"; auto spk_manager = CreateDescriptor(keystore, desc_str, true); @@ -149,7 +149,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard) // P2PKH uncompressed - Legacy { - CWallet keystore(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet keystore(chain.get(), "", CreateDummyWalletDatabase()); keystore.SetupLegacyScriptPubKeyMan(); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); scriptPubKey = GetScriptForDestination(PKHash(uncompressedPubkey)); @@ -168,7 +168,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard) // P2PKH uncompressed - Descriptor { - CWallet keystore(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet keystore(chain.get(), "", CreateDummyWalletDatabase()); std::string desc_str = "pkh(" + EncodeSecret(uncompressedKey) + ")"; auto spk_manager = CreateDescriptor(keystore, desc_str, true); @@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard) // P2SH - Legacy { - CWallet keystore(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet keystore(chain.get(), "", CreateDummyWalletDatabase()); keystore.SetupLegacyScriptPubKeyMan(); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); @@ -207,7 +207,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard) // P2SH - Descriptor { - CWallet keystore(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet keystore(chain.get(), "", CreateDummyWalletDatabase()); std::string desc_str = "sh(pkh(" + EncodeSecret(keys[0]) + "))"; auto spk_manager = CreateDescriptor(keystore, desc_str, true); @@ -220,7 +220,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard) // (P2PKH inside) P2SH inside P2SH (invalid) - Legacy { - CWallet keystore(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet keystore(chain.get(), "", CreateDummyWalletDatabase()); keystore.SetupLegacyScriptPubKeyMan(); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); @@ -239,7 +239,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard) // (P2PKH inside) P2SH inside P2SH (invalid) - Descriptor { - CWallet keystore(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet keystore(chain.get(), "", CreateDummyWalletDatabase()); std::string desc_str = "sh(sh(" + EncodeSecret(keys[0]) + "))"; auto spk_manager = CreateDescriptor(keystore, desc_str, false); @@ -251,7 +251,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard) // scriptPubKey multisig - Legacy { - CWallet keystore(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet keystore(chain.get(), "", CreateDummyWalletDatabase()); keystore.SetupLegacyScriptPubKeyMan(); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); @@ -286,7 +286,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard) // scriptPubKey multisig - Descriptor { - CWallet keystore(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet keystore(chain.get(), "", CreateDummyWalletDatabase()); std::string desc_str = "multi(2, " + EncodeSecret(uncompressedKey) + ", " + EncodeSecret(keys[1]) + ")"; auto spk_manager = CreateDescriptor(keystore, desc_str, true); @@ -298,7 +298,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard) // P2SH multisig - Legacy { - CWallet keystore(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet keystore(chain.get(), "", CreateDummyWalletDatabase()); keystore.SetupLegacyScriptPubKeyMan(); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey)); @@ -321,7 +321,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard) // P2SH multisig - Descriptor { - CWallet keystore(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet keystore(chain.get(), "", CreateDummyWalletDatabase()); std::string desc_str = "sh(multi(2, " + EncodeSecret(uncompressedKey) + ", " + EncodeSecret(keys[1]) + "))"; @@ -335,7 +335,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard) // Combo - Descriptor { - CWallet keystore(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet keystore(chain.get(), "", CreateDummyWalletDatabase()); std::string desc_str = "combo(" + EncodeSecret(keys[0]) + ")"; @@ -358,7 +358,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard) // OP_RETURN { - CWallet keystore(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet keystore(chain.get(), "", CreateDummyWalletDatabase()); keystore.SetupLegacyScriptPubKeyMan(); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); @@ -373,7 +373,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard) // Nonstandard { - CWallet keystore(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet keystore(chain.get(), "", CreateDummyWalletDatabase()); keystore.SetupLegacyScriptPubKeyMan(); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); diff --git a/src/wallet/test/platformkeys_tests.cpp b/src/wallet/test/platformkeys_tests.cpp index aa02aeb771a4..791b46c785f6 100644 --- a/src/wallet/test/platformkeys_tests.cpp +++ b/src/wallet/test/platformkeys_tests.cpp @@ -3,7 +3,6 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include -#include #include #include #include @@ -221,7 +220,6 @@ struct FriendshipWalletSetup : public TestChain100Setup { { m_context.args = &m_args; m_context.chain = m_node.chain.get(); - m_context.coinjoin_loader = m_node.coinjoin_loader.get(); std::tie(m_wallet, m_iface) = MakeSeededWallet(mnemonic); } @@ -230,8 +228,7 @@ struct FriendshipWalletSetup : public TestChain100Setup { std::pair, std::unique_ptr> MakeSeededWallet(const SecureString& mnemonic) { - auto wallet = std::make_shared(m_node.chain.get(), m_node.coinjoin_loader.get(), "", m_args, - CreateMockWalletDatabase()); + auto wallet = std::make_shared(m_node.chain.get(), "", CreateMockWalletDatabase()); wallet->LoadWallet(); { LOCK(wallet->cs_wallet); @@ -245,8 +242,7 @@ struct FriendshipWalletSetup : public TestChain100Setup { std::pair, std::unique_ptr> MakeXprvWallet(const CExtKey& root) { - auto wallet = std::make_shared(m_node.chain.get(), m_node.coinjoin_loader.get(), "", m_args, - CreateMockWalletDatabase()); + auto wallet = std::make_shared(m_node.chain.get(), "", CreateMockWalletDatabase()); wallet->LoadWallet(); FlatSigningProvider provider; @@ -455,8 +451,7 @@ BOOST_FIXTURE_TEST_CASE(invalid_mnemonic_does_not_change_platform_keys, Friendsh "birth kingdom trash renew flavor utility donkey gasp regular alert pave kingdom"}; BOOST_REQUIRE(!CMnemonic::Check(bad_mnemonic)); - auto wallet = std::make_shared(m_node.chain.get(), m_node.coinjoin_loader.get(), "", m_args, - CreateMockWalletDatabase()); + auto wallet = std::make_shared(m_node.chain.get(), "", CreateMockWalletDatabase()); wallet->LoadWallet(); // The master key a corrupt record would pair with: derived from the very @@ -496,8 +491,7 @@ BOOST_FIXTURE_TEST_CASE(invalid_mnemonic_does_not_change_platform_keys, Friendsh //! created that a later wallet migration would orphan. BOOST_FIXTURE_TEST_CASE(legacy_wallet_has_no_platform_keys, FriendshipWalletSetup) { - auto wallet = std::make_shared(m_node.chain.get(), m_node.coinjoin_loader.get(), "", m_args, - CreateMockWalletDatabase()); + auto wallet = std::make_shared(m_node.chain.get(), "", CreateMockWalletDatabase()); wallet->LoadWallet(); { LOCK(wallet->cs_wallet); diff --git a/src/wallet/test/scriptpubkeyman_tests.cpp b/src/wallet/test/scriptpubkeyman_tests.cpp index 6ce39aa0c8c3..6a2ea01c9acf 100644 --- a/src/wallet/test/scriptpubkeyman_tests.cpp +++ b/src/wallet/test/scriptpubkeyman_tests.cpp @@ -22,7 +22,7 @@ BOOST_AUTO_TEST_CASE(CanProvide) // Set up wallet and keyman variables. NodeContext node; std::unique_ptr chain = interfaces::MakeChain(node); - CWallet wallet(chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateDummyWalletDatabase()); + CWallet wallet(chain.get(), "", CreateDummyWalletDatabase()); LegacyScriptPubKeyMan& keyman = *wallet.GetOrCreateLegacyScriptPubKeyMan(); // Make a 1 of 2 multisig script diff --git a/src/wallet/test/spend_tests.cpp b/src/wallet/test/spend_tests.cpp index df8ac97eb705..68272199ded8 100644 --- a/src/wallet/test/spend_tests.cpp +++ b/src/wallet/test/spend_tests.cpp @@ -17,7 +17,7 @@ BOOST_FIXTURE_TEST_SUITE(spend_tests, WalletTestingSetup) BOOST_FIXTURE_TEST_CASE(SubtractFee, TestChain100Setup) { CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); - auto wallet = CreateSyncedWallet(*m_node.chain, *m_node.coinjoin_loader, *Assert(m_node.chainman), m_args, coinbaseKey); + auto wallet = CreateSyncedWallet(*m_node.chain, *Assert(m_node.chainman), coinbaseKey); // Check that a subtract-from-recipient transaction slightly less than the // coinbase input amount does not create a change output (because it would @@ -111,7 +111,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_duplicated_preset_inputs_test, TestChain100Setup) // Add 4 spendable UTXO, 500 DASH each, to the wallet (total balance 2000 DASH) for (int i = 0; i < 4; i++) CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); - auto wallet = CreateSyncedWallet(*m_node.chain, *m_node.coinjoin_loader, *Assert(m_node.chainman), m_args, coinbaseKey); + auto wallet = CreateSyncedWallet(*m_node.chain, *Assert(m_node.chainman), coinbaseKey); LOCK(wallet->cs_wallet); auto available_coins = AvailableCoins(*wallet); diff --git a/src/wallet/test/util.cpp b/src/wallet/test/util.cpp index 59e397f0a81b..84382cb59efa 100644 --- a/src/wallet/test/util.cpp +++ b/src/wallet/test/util.cpp @@ -17,7 +17,7 @@ #include namespace wallet { -std::unique_ptr CreateSyncedWallet(interfaces::Chain& chain, interfaces::CoinJoin::Loader& coinjoin_loader, ChainstateManager& chainman, ArgsManager& args, const CKey& key) +std::unique_ptr CreateSyncedWallet(interfaces::Chain& chain, ChainstateManager& chainman, const CKey& key) { struct ChainInfo { int height; @@ -29,7 +29,7 @@ std::unique_ptr CreateSyncedWallet(interfaces::Chain& chain, interfaces chainman.ActiveChain().Tip()->GetBlockHash(), chainman.ActiveChain().Genesis()->GetBlockHash()}))}; - auto wallet = std::make_unique(&chain, &coinjoin_loader, "", args, CreateMockWalletDatabase()); + auto wallet = std::make_unique(&chain, "", CreateMockWalletDatabase()); { LOCK(wallet->cs_wallet); wallet->SetLastBlockProcessed(chain_info.height, chain_info.tip_hash); diff --git a/src/wallet/test/util.h b/src/wallet/test/util.h index e278ec324fd7..9621d043485e 100644 --- a/src/wallet/test/util.h +++ b/src/wallet/test/util.h @@ -18,9 +18,6 @@ class CKey; enum class OutputType; namespace interfaces { class Chain; -namespace CoinJoin { -class Loader; -} // namespace CoinJoin } // namespace interfaces namespace wallet { @@ -28,7 +25,7 @@ class CWallet; struct DatabaseOptions; class WalletDatabase; -std::unique_ptr CreateSyncedWallet(interfaces::Chain& chain, interfaces::CoinJoin::Loader& coinjoin_loader, ChainstateManager& chainman, ArgsManager& args, const CKey& key); +std::unique_ptr CreateSyncedWallet(interfaces::Chain& chain, ChainstateManager& chainman, const CKey& key); // Creates a copy of the provided database std::unique_ptr DuplicateMockDatabase(WalletDatabase& database, DatabaseOptions& options); diff --git a/src/wallet/test/wallet_test_fixture.cpp b/src/wallet/test/wallet_test_fixture.cpp index 7429289a4603..95c48f61f7cb 100644 --- a/src/wallet/test/wallet_test_fixture.cpp +++ b/src/wallet/test/wallet_test_fixture.cpp @@ -9,9 +9,8 @@ namespace wallet { WalletTestingSetup::WalletTestingSetup(const std::string& chainName) : TestingSetup(chainName), - m_coinjoin_loader{interfaces::MakeCoinJoinLoader(m_node)}, - m_wallet_loader{interfaces::MakeWalletLoader(*m_node.chain, *Assert(m_node.args), m_node, *Assert(m_coinjoin_loader))}, - m_wallet(m_node.chain.get(), m_coinjoin_loader.get(), "", m_args, CreateMockWalletDatabase()) + m_wallet_loader{interfaces::MakeWalletLoader(*m_node.chain, *Assert(m_node.args), m_node)}, + m_wallet(m_node.chain.get(), "", CreateMockWalletDatabase()) { m_wallet.LoadWallet(); m_chain_notifications_handler = m_node.chain->handleNotifications({ &m_wallet, [](CWallet*) {} }); diff --git a/src/wallet/test/wallet_test_fixture.h b/src/wallet/test/wallet_test_fixture.h index 42e94f91f3b2..f1ef15a2824e 100644 --- a/src/wallet/test/wallet_test_fixture.h +++ b/src/wallet/test/wallet_test_fixture.h @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -23,7 +22,6 @@ struct WalletTestingSetup : public TestingSetup { explicit WalletTestingSetup(const std::string& chainName = CBaseChainParams::MAIN); ~WalletTestingSetup(); - std::unique_ptr m_coinjoin_loader; std::unique_ptr m_wallet_loader; CWallet m_wallet; std::unique_ptr m_chain_notifications_handler; diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp index cd7670ba22cb..5a042e6eb41d 100644 --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -134,8 +133,7 @@ BOOST_AUTO_TEST_CASE(interface_coin_lock_failed_persist) { auto database{std::make_unique()}; auto* database_ptr{database.get()}; - auto wallet{std::make_shared(m_node.chain.get(), m_coinjoin_loader.get(), "", m_args, - std::move(database))}; + auto wallet{std::make_shared(m_node.chain.get(), "", std::move(database))}; BOOST_REQUIRE(wallet->LoadWallet() == DBErrors::LOAD_OK); auto wallet_interface{interfaces::MakeWallet(*m_wallet_loader->context(), wallet)}; const COutPoint outpoint{uint256::ONE, 0}; @@ -162,10 +160,6 @@ static std::shared_ptr TestLoadWallet(WalletContext& context) std::vector warnings; auto database = MakeWalletDatabase("", options, status, error); auto wallet = CWallet::Create(context, "", std::move(database), options.create_flags, error, warnings); - if (context.coinjoin_loader) { - // TODO: see CreateWalletWithoutChain - AddWallet(context, wallet); - } NotifyWalletLoaded(context, wallet); return wallet; } @@ -214,7 +208,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup) // Verify ScanForWalletTransactions fails to read an unknown start block. { - CWallet wallet(m_node.chain.get(), m_node.coinjoin_loader.get(), "", m_args, CreateDummyWalletDatabase()); + CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase()); wallet.SetupLegacyScriptPubKeyMan(); { LOCK(wallet.cs_wallet); @@ -235,7 +229,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup) // Verify ScanForWalletTransactions picks up transactions in both the old // and new block files. { - CWallet wallet(m_node.chain.get(), m_node.coinjoin_loader.get(), "", m_args, CreateMockWalletDatabase()); + CWallet wallet(m_node.chain.get(), "", CreateMockWalletDatabase()); { LOCK(wallet.cs_wallet); wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS); @@ -279,7 +273,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup) // Verify ScanForWalletTransactions only picks transactions in the new block // file. { - CWallet wallet(m_node.chain.get(), m_node.coinjoin_loader.get(), "", m_args, CreateDummyWalletDatabase()); + CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase()); { LOCK(wallet.cs_wallet); wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS); @@ -306,7 +300,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup) // Verify ScanForWalletTransactions scans no blocks. { - CWallet wallet(m_node.chain.get(), m_node.coinjoin_loader.get(), "", m_args, CreateDummyWalletDatabase()); + CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase()); { LOCK(wallet.cs_wallet); wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS); @@ -345,7 +339,7 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup) // before the missing block, and success for a key whose creation time is // after. { - const std::shared_ptr wallet = std::make_shared(m_node.chain.get(), m_node.coinjoin_loader.get(), "", m_args, CreateDummyWalletDatabase()); + const std::shared_ptr wallet = std::make_shared(m_node.chain.get(), "", CreateDummyWalletDatabase()); wallet->SetupLegacyScriptPubKeyMan(); WITH_LOCK(wallet->cs_wallet, wallet->SetLastBlockProcessed(newTip->nHeight, newTip->GetBlockHash())); WalletContext context; @@ -411,7 +405,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup) const CBlockIndex* tip{WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return m_node.chainman->ActiveChain().Tip())}; WalletContext context; context.args = &m_args; - const std::shared_ptr wallet = std::make_shared(m_node.chain.get(), m_node.coinjoin_loader.get(), "", m_args, CreateDummyWalletDatabase()); + const std::shared_ptr wallet = std::make_shared(m_node.chain.get(), "", CreateDummyWalletDatabase()); { auto spk_man = wallet->GetOrCreateLegacyScriptPubKeyMan(); LOCK2(wallet->cs_wallet, spk_man->cs_KeyStore); @@ -434,7 +428,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup) // were scanned, and no prior blocks were scanned. { const CBlockIndex* tip{WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return m_node.chainman->ActiveChain().Tip())}; - const std::shared_ptr wallet = std::make_shared(m_node.chain.get(), m_node.coinjoin_loader.get(), "", m_args, CreateDummyWalletDatabase()); + const std::shared_ptr wallet = std::make_shared(m_node.chain.get(), "", CreateDummyWalletDatabase()); LOCK(wallet->cs_wallet); wallet->SetupLegacyScriptPubKeyMan(); @@ -467,7 +461,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup) // debit functions. BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup) { - CWallet wallet(m_node.chain.get(), m_node.coinjoin_loader.get(), "", m_args, CreateDummyWalletDatabase()); + CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase()); const CBlockIndex* tip{WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return m_node.chainman->ActiveChain().Tip())}; LOCK(wallet.cs_wallet); CWalletTx wtx{m_coinbase_txns.back(), TxStateConfirmed{tip->GetBlockHash(), tip->nHeight, /*index=*/0}}; @@ -547,7 +541,7 @@ static const DatabaseFormat DATABASE_FORMATS[] = { #endif }; -void TestLoadWallet(const std::string& name, DatabaseFormat format, const ArgsManager& args, std::function)> f) +void TestLoadWallet(const std::string& name, DatabaseFormat format, std::function)> f) { DatabaseOptions options; options.require_format = format; @@ -555,7 +549,7 @@ void TestLoadWallet(const std::string& name, DatabaseFormat format, const ArgsMa bilingual_str error; std::vector warnings; auto database{MakeWalletDatabase(name, options, status, error)}; - auto wallet{std::make_shared(/*chain=*/nullptr, /*coinjoin_loader=*/nullptr, "", args, std::move(database))}; + auto wallet{std::make_shared(/*chain=*/nullptr, "", std::move(database))}; BOOST_CHECK_EQUAL(wallet->LoadWallet(), DBErrors::LOAD_OK); WITH_LOCK(wallet->cs_wallet, f(wallet)); } @@ -564,7 +558,7 @@ BOOST_FIXTURE_TEST_CASE(LoadReceiveRequests, TestingSetup) { for (DatabaseFormat format : DATABASE_FORMATS) { const std::string name{strprintf("receive-requests-%i", format)}; - TestLoadWallet(name, format, m_args, [](std::shared_ptr wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet->cs_wallet) { + TestLoadWallet(name, format, [](std::shared_ptr wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet->cs_wallet) { BOOST_CHECK(!wallet->IsAddressPreviouslySpent(PKHash())); WalletBatch batch{wallet->GetDatabase()}; BOOST_CHECK(batch.WriteAddressPreviouslySpent(PKHash(), true)); @@ -575,7 +569,7 @@ BOOST_FIXTURE_TEST_CASE(LoadReceiveRequests, TestingSetup) BOOST_CHECK(wallet->SetAddressReceiveRequest(batch, PKHash(), "1", "val_rr11")); BOOST_CHECK(wallet->SetAddressReceiveRequest(batch, ScriptHash(), "2", "val_rr20")); }); - TestLoadWallet(name, format, m_args, [](std::shared_ptr wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet->cs_wallet) { + TestLoadWallet(name, format, [](std::shared_ptr wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet->cs_wallet) { BOOST_CHECK(wallet->IsAddressPreviouslySpent(PKHash())); BOOST_CHECK(wallet->IsAddressPreviouslySpent(ScriptHash())); auto requests = wallet->GetAddressReceiveRequests(); @@ -585,7 +579,7 @@ BOOST_FIXTURE_TEST_CASE(LoadReceiveRequests, TestingSetup) BOOST_CHECK(batch.WriteAddressPreviouslySpent(PKHash(), false)); BOOST_CHECK(batch.EraseAddressData(ScriptHash())); }); - TestLoadWallet(name, format, m_args, [](std::shared_ptr wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet->cs_wallet) { + TestLoadWallet(name, format, [](std::shared_ptr wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet->cs_wallet) { BOOST_CHECK(!wallet->IsAddressPreviouslySpent(PKHash())); BOOST_CHECK(!wallet->IsAddressPreviouslySpent(ScriptHash())); auto requests = wallet->GetAddressReceiveRequests(); @@ -682,7 +676,7 @@ class ListCoinsTestingSetup : public TestChain100Setup ListCoinsTestingSetup() { CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); - wallet = CreateSyncedWallet(*m_node.chain, *m_node.coinjoin_loader, *Assert(m_node.chainman), m_args, coinbaseKey); + wallet = CreateSyncedWallet(*m_node.chain, *Assert(m_node.chainman), coinbaseKey); } ~ListCoinsTestingSetup() @@ -819,7 +813,7 @@ BOOST_FIXTURE_TEST_CASE(BasicOutputTypesTest, ListCoinsTestingSetup) BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup) { { - const std::shared_ptr wallet = std::make_shared(m_node.chain.get(), m_node.coinjoin_loader.get(), "", m_args, CreateDummyWalletDatabase()); + const std::shared_ptr wallet = std::make_shared(m_node.chain.get(), "", CreateDummyWalletDatabase()); wallet->SetupLegacyScriptPubKeyMan(); wallet->SetMinVersion(FEATURE_LATEST); wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS); @@ -827,7 +821,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup) BOOST_CHECK(!wallet->GetNewDestination("")); } { - const std::shared_ptr wallet = std::make_shared(m_node.chain.get(), m_node.coinjoin_loader.get(), "", m_args, CreateDummyWalletDatabase()); + const std::shared_ptr wallet = std::make_shared(m_node.chain.get(), "", CreateDummyWalletDatabase()); LOCK(wallet->cs_wallet); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); wallet->SetMinVersion(FEATURE_LATEST); @@ -923,7 +917,6 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup) WalletContext context; context.args = &m_args; context.chain = m_node.chain.get(); - context.coinjoin_loader = m_node.coinjoin_loader.get(); auto wallet = TestLoadWallet(context); CKey key = GenerateRandomKey(); AddKey(*wallet, key); @@ -1016,7 +1009,6 @@ BOOST_FIXTURE_TEST_CASE(CreateWalletWithoutChain, BasicTestingSetup) { WalletContext context; context.args = &m_args; - context.coinjoin_loader = nullptr; // TODO: FIX FIX FIX auto wallet = TestLoadWallet(context); BOOST_CHECK(wallet); UnloadWallet(std::move(wallet)); @@ -1028,7 +1020,6 @@ BOOST_FIXTURE_TEST_CASE(ZapSelectTx, TestChain100Setup) WalletContext context; context.args = &m_args; context.chain = m_node.chain.get(); - context.coinjoin_loader = m_node.coinjoin_loader.get(); auto wallet = TestLoadWallet(context); CKey key = GenerateRandomKey(); AddKey(*wallet, key); @@ -1076,8 +1067,7 @@ BOOST_FIXTURE_TEST_CASE(rpc_getaddressinfo, TestChain100Setup) WalletContext context; context.args = &m_args; context.chain = m_node.chain.get(); - context.coinjoin_loader = m_node.coinjoin_loader.get(); - const std::shared_ptr wallet = std::make_shared(m_node.chain.get(), m_node.coinjoin_loader.get(), "", m_args, CreateMockWalletDatabase()); + const std::shared_ptr wallet = std::make_shared(m_node.chain.get(), "", CreateMockWalletDatabase()); wallet->SetupLegacyScriptPubKeyMan(); AddWallet(context, wallet); JSONRPCRequest request; @@ -1174,11 +1164,10 @@ class CreateTransactionTestSetup : public TestChain100Setup const std::string strMaxFeeExceeded = "Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)"; CreateTransactionTestSetup() - : wallet{std::make_unique(m_node.chain.get(), m_node.coinjoin_loader.get(), "", m_args, CreateMockWalletDatabase())} + : wallet{std::make_unique(m_node.chain.get(), "", CreateMockWalletDatabase())} { context.args = &m_args; context.chain = m_node.chain.get(); - context.coinjoin_loader = m_node.coinjoin_loader.get(); CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); wallet->LoadWallet(); AddWallet(context, wallet); @@ -1955,7 +1944,7 @@ BOOST_FIXTURE_TEST_CASE(AbandonedSpendRestoresActiveMasternodeCollateralLock, Li */ BOOST_FIXTURE_TEST_CASE(wallet_sync_tx_invalid_state_test, TestChain100Setup) { - CWallet wallet(m_node.chain.get(), m_node.coinjoin_loader.get(), "", m_args, std::make_unique()); + CWallet wallet(m_node.chain.get(), "", std::make_unique()); { LOCK(wallet.cs_wallet); wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS); diff --git a/src/wallet/test/walletdb_tests.cpp b/src/wallet/test/walletdb_tests.cpp index 5f7e4b8bdf12..9bf671daf125 100644 --- a/src/wallet/test/walletdb_tests.cpp +++ b/src/wallet/test/walletdb_tests.cpp @@ -114,11 +114,10 @@ BOOST_AUTO_TEST_CASE(walletdb_platform_data_records) //! `record_key` with a truncated value (claims five bytes, carries none), //! next to an intact record, and report the load result and the Platform //! data that made it into the wallet. -static DBErrors LoadWithCorruptPlatformRecord(const node::NodeContext& node, const ArgsManager& args, - const std::string& record_key, +static DBErrors LoadWithCorruptPlatformRecord(const node::NodeContext& node, const std::string& record_key, std::map>& platform_data_out) { - CWallet wallet(node.chain.get(), node.coinjoin_loader.get(), "", args, CreateMockWalletDatabase()); + CWallet wallet(node.chain.get(), "", CreateMockWalletDatabase()); const std::vector truncated{0x05}; const std::vector intact_value{0x01, 0x02}; { @@ -137,13 +136,13 @@ BOOST_AUTO_TEST_CASE(walletdb_platform_data_corruption_policy) // wallet still loads, and intact records survive. There is no reserved // Platform seed-selection record. std::map> platform_data; - BOOST_CHECK(LoadWithCorruptPlatformRecord(m_node, m_args, "platform/metadata", platform_data) == + BOOST_CHECK(LoadWithCorruptPlatformRecord(m_node, "platform/metadata", platform_data) == DBErrors::NONCRITICAL_ERROR); BOOST_CHECK_EQUAL(platform_data.count("platform/metadata"), 0U); BOOST_CHECK(platform_data.at("platform/intact") == std::vector({0x01, 0x02})); platform_data.clear(); - BOOST_CHECK(LoadWithCorruptPlatformRecord(m_node, m_args, "platform/identity/0", platform_data) == + BOOST_CHECK(LoadWithCorruptPlatformRecord(m_node, "platform/identity/0", platform_data) == DBErrors::NONCRITICAL_ERROR); BOOST_CHECK_EQUAL(platform_data.count("platform/identity/0"), 0U); BOOST_CHECK(platform_data.at("platform/intact") == std::vector({0x01, 0x02})); diff --git a/src/wallet/test/walletload_tests.cpp b/src/wallet/test/walletload_tests.cpp index 033470d12b99..df79dd24ce10 100644 --- a/src/wallet/test/walletload_tests.cpp +++ b/src/wallet/test/walletload_tests.cpp @@ -46,7 +46,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_load_unknown_descriptor, TestingSetup) { // Now try to load the wallet and verify the error. - const std::shared_ptr wallet(new CWallet(m_node.chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, std::move(database))); + const std::shared_ptr wallet(new CWallet(m_node.chain.get(), "", std::move(database))); BOOST_CHECK_EQUAL(wallet->LoadWallet(), DBErrors::UNKNOWN_DESCRIPTOR); } } @@ -84,7 +84,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_load_verif_crypted_key_checksum, TestingSetup) { // Context setup. // Create and encrypt legacy wallet - std::shared_ptr wallet(new CWallet(m_node.chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, CreateMockWalletDatabase())); + std::shared_ptr wallet(new CWallet(m_node.chain.get(), "", CreateMockWalletDatabase())); LOCK(wallet->cs_wallet); auto legacy_spkm = wallet->GetOrCreateLegacyScriptPubKeyMan(); BOOST_CHECK(legacy_spkm->CanGenerateKeys() && legacy_spkm->TopUp()); @@ -112,7 +112,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_load_verif_crypted_key_checksum, TestingSetup) // the records every time that 'CWallet::Unlock' gets called, which is not good. // Load the wallet and check that is encrypted - std::shared_ptr wallet(new CWallet(m_node.chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, get_db(dbs))); + std::shared_ptr wallet(new CWallet(m_node.chain.get(), "", get_db(dbs))); BOOST_CHECK_EQUAL(wallet->LoadWallet(), DBErrors::LOAD_OK); BOOST_CHECK(wallet->IsCrypted()); BOOST_CHECK(HasAnyRecordOfType(wallet->GetDatabase(), DBKeys::CRYPTED_KEY)); @@ -138,7 +138,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_load_verif_crypted_key_checksum, TestingSetup) } // Load the wallet and check that is encrypted - std::shared_ptr wallet(new CWallet(m_node.chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, std::move(db))); + std::shared_ptr wallet(new CWallet(m_node.chain.get(), "", std::move(db))); BOOST_CHECK_EQUAL(wallet->LoadWallet(), DBErrors::LOAD_OK); BOOST_CHECK(wallet->IsCrypted()); BOOST_CHECK(HasAnyRecordOfType(wallet->GetDatabase(), DBKeys::CRYPTED_KEY)); @@ -166,7 +166,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_load_verif_crypted_key_checksum, TestingSetup) BOOST_CHECK(batch->Write(key, value, /*fOverwrite=*/true)); } - std::shared_ptr wallet(new CWallet(m_node.chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, std::move(db))); + std::shared_ptr wallet(new CWallet(m_node.chain.get(), "", std::move(db))); BOOST_CHECK_EQUAL(wallet->LoadWallet(), DBErrors::CORRUPT); } @@ -182,7 +182,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_load_verif_crypted_key_checksum, TestingSetup) BOOST_CHECK(db->MakeBatch(false)->Write(key, value, /*fOverwrite=*/true)); } - std::shared_ptr wallet(new CWallet(m_node.chain.get(), /*coinjoin_loader=*/nullptr, "", m_args, std::move(db))); + std::shared_ptr wallet(new CWallet(m_node.chain.get(), "", std::move(db))); BOOST_CHECK_EQUAL(wallet->LoadWallet(), DBErrors::CORRUPT); } } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 3432f93f7d8a..d4fd87fb938c 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -34,8 +35,9 @@ #include #include #include -#include #include +#include +#include #include #include #ifdef USE_BDB @@ -130,11 +132,11 @@ bool AddWallet(WalletContext& context, const std::shared_ptr& wallet) if (i != context.wallets.end()) return false; context.wallets.push_back(wallet); } + if (auto* coinjoin_loader = wallet->chain().coinJoinLoader()) { + coinjoin_loader->AddWallet(wallet); + } wallet->ConnectScriptPubKeyManNotifiers(); wallet->AutoLockMasternodeCollaterals(); - if (wallet->coinjoin_available()) { - wallet->coinjoin_loader().AddWallet(wallet); - } wallet->NotifyCanGetAddressesChanged(); return true; } @@ -155,8 +157,8 @@ bool RemoveWallet(WalletContext& context, const std::shared_ptr& wallet context.wallets.erase(i); } - if (wallet->coinjoin_available()) { - wallet->coinjoin_loader().RemoveWallet(name); + if (auto* coinjoin_loader = chain.coinJoinLoader()) { + coinjoin_loader->RemoveWallet(name); } // Write the wallet setting @@ -289,8 +291,8 @@ std::shared_ptr LoadWalletInternal(WalletContext& context, const std::s return nullptr; } - NotifyWalletLoaded(context, wallet); AddWallet(context, wallet); + NotifyWalletLoaded(context, wallet); wallet->postInitProcess(); // Write the wallet setting @@ -483,8 +485,8 @@ std::shared_ptr CreateWallet(WalletContext& context, const std::string& } } - NotifyWalletLoaded(context, wallet); AddWallet(context, wallet); + NotifyWalletLoaded(context, wallet); wallet->postInitProcess(); // Write the wallet settings @@ -1136,7 +1138,7 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const TxState& state, const #if HAVE_SYSTEM // notify an external script when a wallet transaction comes in or is updated - std::string strCmd = m_args.GetArg("-walletnotify", ""); + std::string strCmd = m_notify_tx_changed_script; if (!strCmd.empty()) { @@ -3208,14 +3210,17 @@ std::unique_ptr MakeWalletDatabase(const std::string& name, cons 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) { interfaces::Chain* chain = context.chain; - interfaces::CoinJoin::Loader* coinjoin_loader = context.coinjoin_loader; ArgsManager& args = *Assert(context.args); const std::string& walletFile = database->Filename(); const auto start{SteadyClock::now()}; // 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, coinjoin_loader, name, args, std::move(database)), ReleaseWallet); + std::shared_ptr walletInstance(new CWallet(chain, name, std::move(database)), ReleaseWallet); + walletInstance->m_keypool_size = std::max(args.GetIntArg("-keypool", DEFAULT_KEYPOOL_SIZE), int64_t{1}); + walletInstance->m_mnemonic_bits = args.GetIntArg("-mnemonicbits", CHDChain::DEFAULT_MNEMONIC_BITS); + walletInstance->m_notify_tx_changed_script = args.GetArg("-walletnotify", ""); + walletInstance->m_notify_tx_locked_script = args.GetArg("-instantsendnotify", ""); // TODO: refactor this condition: validation of error looks like workaround if (!walletInstance->AutoBackupWallet(fs::PathFromString(walletFile), error, warnings) && !error.original.empty()) { return nullptr; @@ -3527,10 +3532,6 @@ std::shared_ptr CWallet::Create(WalletContext& context, const std::stri return nullptr; } - if (coinjoin_loader) { - coinjoin_loader->AddWallet(walletInstance); - } - { LOCK(walletInstance->cs_wallet); walletInstance->SetBroadcastTransactions(args.GetBoolArg("-walletbroadcast", DEFAULT_WALLETBROADCAST)); @@ -3888,7 +3889,7 @@ void CWallet::notifyTransactionLock(const CTransactionRef &tx, const std::shared NotifyISLockReceived(); #if HAVE_SYSTEM // notify an external script - std::string strCmd = m_args.GetArg("-instantsendnotify", ""); + std::string strCmd = m_notify_tx_locked_script; if (!strCmd.empty()) { ReplaceAll(strCmd, "%s", txHash.GetHex()); #ifndef WIN32 @@ -4230,7 +4231,7 @@ bool CWallet::Unlock(const SecureString& strWalletPassphrase, bool fForMixingOnl if(nWalletBackups == -2) { TopUpKeyPool(); WalletLogPrintf("Keypool replenished, re-initializing automatic backups.\n"); - nWalletBackups = m_args.GetIntArg("-createwalletbackups", 10); + nWalletBackups = gArgs.GetIntArg("-createwalletbackups", 10); } return true; } @@ -4364,7 +4365,7 @@ void CWallet::SetupLegacyScriptPubKeyMan() return; } - auto spk_manager = std::make_unique(*this); + auto spk_manager = std::make_unique(*this, m_keypool_size); m_internal_spk_managers = spk_manager.get(); m_external_spk_managers = spk_manager.get(); uint256 id = spk_manager->GetID(); @@ -4399,10 +4400,10 @@ void CWallet::UpdateProgress(const std::string& title, int nProgress) void CWallet::LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc) { if (IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) { - auto spk_manager = std::unique_ptr(new ExternalSignerScriptPubKeyMan(*this, desc)); + auto spk_manager = std::unique_ptr(new ExternalSignerScriptPubKeyMan(*this, desc, m_keypool_size)); AddScriptPubKeyMan(id, std::move(spk_manager)); } else { - auto spk_manager = std::unique_ptr(new DescriptorScriptPubKeyMan(*this, desc)); + auto spk_manager = std::unique_ptr(new DescriptorScriptPubKeyMan(*this, desc, m_keypool_size)); AddScriptPubKeyMan(id, std::move(spk_manager)); } } @@ -4413,7 +4414,7 @@ void CWallet::SetupDescriptorScriptPubKeyMans(const CExtKey& master_key, const S for (auto type : {PathDerivationType::BIP44_External, PathDerivationType::BIP44_Internal, PathDerivationType::DIP0009_CoinJoin}) { { // OUTPUT_TYPE is only one: LEGACY - auto spk_manager = std::unique_ptr(new DescriptorScriptPubKeyMan(*this)); + auto spk_manager = std::unique_ptr(new DescriptorScriptPubKeyMan(*this, m_keypool_size)); if (IsCrypted()) { if (IsLocked()) { throw std::runtime_error(std::string(__func__) + ": Wallet is locked, cannot setup new descriptors"); @@ -4439,7 +4440,7 @@ void CWallet::SetupDescriptorScriptPubKeyMans(const SecureString& mnemonic_arg, if (!IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) { // Make a seed // TODO: remove duplicated code with CHDChain::SetMnemonic - const SecureString mnemonic = mnemonic_arg.empty() ? CMnemonic::Generate(m_args.GetIntArg("-mnemonicbits", CHDChain::DEFAULT_MNEMONIC_BITS)) : mnemonic_arg; + const SecureString mnemonic = mnemonic_arg.empty() ? CMnemonic::Generate(m_mnemonic_bits) : mnemonic_arg; if (!CMnemonic::Check(mnemonic)) { throw std::runtime_error(std::string(__func__) + ": invalid mnemonic"); } @@ -4473,7 +4474,7 @@ void CWallet::SetupDescriptorScriptPubKeyMans(const SecureString& mnemonic_arg, if (!desc->GetOutputType()) { continue; } - auto spk_manager = std::unique_ptr(new ExternalSignerScriptPubKeyMan(*this)); + auto spk_manager = std::unique_ptr(new ExternalSignerScriptPubKeyMan(*this, m_keypool_size)); spk_manager->SetupDescriptor(std::move(desc)); uint256 id = spk_manager->GetID(); AddScriptPubKeyMan(id, std::move(spk_manager)); @@ -4594,7 +4595,7 @@ ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const Flat WalletLogPrintf("Update existing descriptor: %s\n", desc.descriptor->ToString()); spk_man->UpdateWalletDescriptor(desc); } else { - auto new_spk_man = std::unique_ptr(new DescriptorScriptPubKeyMan(*this, desc)); + auto new_spk_man = std::unique_ptr(new DescriptorScriptPubKeyMan(*this, desc, m_keypool_size)); spk_man = new_spk_man.get(); // Save the descriptor to memory diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 30e18341581e..87c57ac3a54a 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -10,9 +10,9 @@ #include #include #include -#include #include #include // IWYU pragma: export +#include #include #include #include @@ -22,8 +22,6 @@ #include #include #include -#include -#include #include #include #include @@ -414,15 +412,9 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati // Decreases amount of nKeysLeftSinceAutoBackup after KeepDestination void KeepDestinationCallback(bool erased) override; - /** Provider of aplication-wide arguments. */ - const ArgsManager& m_args; - /** Interface for accessing chain state. */ interfaces::Chain* m_chain; - /** Interface for accessing CoinJoin state. */ - interfaces::CoinJoin::Loader* m_coinjoin_loader; - /** Wallet name: relative directory name or "" for default wallet. */ std::string m_name; @@ -533,10 +525,8 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati unsigned int nMasterKeyMaxID = 0; /** Construct wallet with specified name and database implementation. */ - CWallet(interfaces::Chain* chain, interfaces::CoinJoin::Loader* coinjoin_loader, const std::string& name, const ArgsManager& args, std::unique_ptr database) - : m_args(args), - m_chain(chain), - m_coinjoin_loader(coinjoin_loader), + CWallet(interfaces::Chain* chain, const std::string& name, std::unique_ptr database) + : m_chain(chain), m_name(name), m_database(std::move(database)) { @@ -585,11 +575,6 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati /** Interface for accessing chain state. */ interfaces::Chain& chain() const { assert(m_chain); return *m_chain; } - /** Interface for accessing CoinJoin state. */ - interfaces::CoinJoin::Loader& coinjoin_loader() { assert(m_coinjoin_loader); return *m_coinjoin_loader; } - /** Interface for availability status of CoinJoin. */ - bool coinjoin_available() { return m_coinjoin_loader != nullptr; } - const CWalletTx* GetWalletTx(const uint256& hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); std::set GetTxConflicts(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); @@ -893,6 +878,18 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati * are automatically locked to prevent dust attacks. 0 = disabled. Override with -dustprotectionthreshold. */ CAmount m_dust_protection_threshold{DEFAULT_DUST_PROTECTION_THRESHOLD}; + /** Number of pre-generated keys/scripts by each spkm (part of the look-ahead process, used to detect payments) */ + int64_t m_keypool_size{DEFAULT_KEYPOOL_SIZE}; + + /** Entropy in bits of a generated mnemonic (handled by -mnemonicbits) */ + int m_mnemonic_bits{CHDChain::DEFAULT_MNEMONIC_BITS}; + + /** Notify external script when a wallet transaction comes in or is updated (handled by -walletnotify) */ + std::string m_notify_tx_changed_script; + + /** Notify external script when a wallet transaction is locked by InstantSend (handled by -instantsendnotify) */ + std::string m_notify_tx_locked_script; + size_t KeypoolCountExternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); bool TopUpKeyPool(unsigned int kpSize = 0); diff --git a/src/wallet/wallettool.cpp b/src/wallet/wallettool.cpp index 9fc3e7e4f5e2..c070d3aec8e7 100644 --- a/src/wallet/wallettool.cpp +++ b/src/wallet/wallettool.cpp @@ -57,7 +57,7 @@ static void WalletCreate(CWallet* wallet_instance, uint64_t wallet_creation_flag wallet_instance->TopUpKeyPool(); } -static std::shared_ptr MakeWallet(const std::string& name, const fs::path& path, const ArgsManager& args, DatabaseOptions options) +static std::shared_ptr MakeWallet(const std::string& name, const fs::path& path, DatabaseOptions options) { DatabaseStatus status; bilingual_str error; @@ -68,7 +68,7 @@ static std::shared_ptr MakeWallet(const std::string& name, const fs::pa } // dummy chain interface - std::shared_ptr wallet_instance{new CWallet(/*chain=*/nullptr, /*coinjoin_loader=*/nullptr, name, args, std::move(database)), WalletToolReleaseWallet}; + std::shared_ptr wallet_instance{new CWallet(/*chain=*/nullptr, name, std::move(database)), WalletToolReleaseWallet}; DBErrors load_wallet_ret; try { load_wallet_ret = wallet_instance->LoadWallet(); @@ -170,7 +170,7 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command) options.require_format = DatabaseFormat::SQLITE; } - const std::shared_ptr wallet_instance = MakeWallet(name, path, args, options); + const std::shared_ptr wallet_instance = MakeWallet(name, path, options); if (wallet_instance) { WalletShowInfo(wallet_instance.get()); wallet_instance->Close(); @@ -179,7 +179,7 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command) DatabaseOptions options; ReadDatabaseArgs(args, options); options.require_existing = true; - const std::shared_ptr wallet_instance = MakeWallet(name, path, args, options); + const std::shared_ptr wallet_instance = MakeWallet(name, path, options); if (!wallet_instance) return false; WalletShowInfo(wallet_instance.get()); wallet_instance->Close(); @@ -205,7 +205,7 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command) #ifdef USE_BDB DatabaseOptions options; options.require_existing = true; - const std::shared_ptr wallet_instance = MakeWallet(name, path, args, options); + const std::shared_ptr wallet_instance = MakeWallet(name, path, options); if (wallet_instance == nullptr) return false; std::vector vHash;