0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-09 10:43:19 -05:00

refactor: wallet, remove global 'ArgsManager' access

we are not using it anymore
This commit is contained in:
furszy 2023-01-18 10:27:16 -03:00
parent d8f5fc4462
commit 6c9b342c30
No known key found for this signature in database
GPG key ID: 5DD23CCC686AA623
19 changed files with 89 additions and 93 deletions

View file

@ -45,7 +45,7 @@ static void CoinSelection(benchmark::Bench& bench)
{ {
NodeContext node; NodeContext node;
auto chain = interfaces::MakeChain(node); auto chain = interfaces::MakeChain(node);
CWallet wallet(chain.get(), "", gArgs, CreateDummyWalletDatabase()); CWallet wallet(chain.get(), "", CreateDummyWalletDatabase());
std::vector<std::unique_ptr<CWalletTx>> wtxs; std::vector<std::unique_ptr<CWalletTx>> wtxs;
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);

View file

@ -28,7 +28,7 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b
const auto& ADDRESS_WATCHONLY = ADDRESS_BCRT1_UNSPENDABLE; const auto& ADDRESS_WATCHONLY = ADDRESS_BCRT1_UNSPENDABLE;
CWallet wallet{test_setup->m_node.chain.get(), "", gArgs, CreateMockWalletDatabase()}; CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockWalletDatabase()};
{ {
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS); wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);

View file

@ -83,7 +83,7 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
{ {
const auto test_setup = MakeNoLogFileContext<const TestingSetup>(); const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
CWallet wallet{test_setup->m_node.chain.get(), "", gArgs, CreateMockWalletDatabase()}; CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockWalletDatabase()};
{ {
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS); wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
@ -136,7 +136,7 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
static void AvailableCoins(benchmark::Bench& bench, const std::vector<OutputType>& output_type) static void AvailableCoins(benchmark::Bench& bench, const std::vector<OutputType>& output_type)
{ {
const auto test_setup = MakeNoLogFileContext<const TestingSetup>(); const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
CWallet wallet{test_setup->m_node.chain.get(), "", gArgs, CreateMockWalletDatabase()}; CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockWalletDatabase()};
{ {
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS); wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);

View file

@ -75,7 +75,7 @@ void TestAddAddressesToSendBook(interfaces::Node& node)
auto wallet_loader = interfaces::MakeWalletLoader(*test.m_node.chain, *Assert(test.m_node.args)); auto wallet_loader = interfaces::MakeWalletLoader(*test.m_node.chain, *Assert(test.m_node.args));
test.m_node.wallet_loader = wallet_loader.get(); test.m_node.wallet_loader = wallet_loader.get();
node.setContext(&test.m_node); node.setContext(&test.m_node);
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", gArgs, CreateMockWalletDatabase()); const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockWalletDatabase());
wallet->LoadWallet(); wallet->LoadWallet();
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
{ {

View file

@ -159,7 +159,7 @@ void TestGUI(interfaces::Node& node)
auto wallet_loader = interfaces::MakeWalletLoader(*test.m_node.chain, *Assert(test.m_node.args)); auto wallet_loader = interfaces::MakeWalletLoader(*test.m_node.chain, *Assert(test.m_node.args));
test.m_node.wallet_loader = wallet_loader.get(); test.m_node.wallet_loader = wallet_loader.get();
node.setContext(&test.m_node); node.setContext(&test.m_node);
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", gArgs, CreateMockWalletDatabase()); const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockWalletDatabase());
wallet->LoadWallet(); wallet->LoadWallet();
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
{ {

View file

@ -202,7 +202,7 @@ bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs::
// dummy chain interface // dummy chain interface
bool ret = true; bool ret = true;
std::shared_ptr<CWallet> wallet(new CWallet(/*chain=*/nullptr, name, gArgs, std::move(database)), WalletToolReleaseWallet); std::shared_ptr<CWallet> wallet(new CWallet(/*chain=*/nullptr, name, std::move(database)), WalletToolReleaseWallet);
{ {
LOCK(wallet->cs_wallet); LOCK(wallet->cs_wallet);
DBErrors load_wallet_ret = wallet->LoadWallet(); DBErrors load_wallet_ret = wallet->LoadWallet();

View file

@ -135,7 +135,7 @@ bool RecoverDatabaseFile(const ArgsManager& args, const fs::path& file_path, bil
} }
DbTxn* ptxn = env->TxnBegin(); DbTxn* ptxn = env->TxnBegin();
CWallet dummyWallet(nullptr, "", gArgs, CreateDummyWalletDatabase()); CWallet dummyWallet(nullptr, "", CreateDummyWalletDatabase());
for (KeyValPair& row : salvagedData) for (KeyValPair& row : salvagedData)
{ {
/* Filter for only private key type KV pairs to be added to the salvaged wallet */ /* Filter for only private key type KV pairs to be added to the salvaged wallet */

View file

@ -305,7 +305,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
coin_selection_params_bnb.m_subtract_fee_outputs = true; coin_selection_params_bnb.m_subtract_fee_outputs = true;
{ {
std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain.get(), "", m_args, CreateMockWalletDatabase()); std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain.get(), "", CreateMockWalletDatabase());
wallet->LoadWallet(); wallet->LoadWallet();
LOCK(wallet->cs_wallet); LOCK(wallet->cs_wallet);
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
@ -327,7 +327,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
} }
{ {
std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain.get(), "", m_args, CreateMockWalletDatabase()); std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain.get(), "", CreateMockWalletDatabase());
wallet->LoadWallet(); wallet->LoadWallet();
LOCK(wallet->cs_wallet); LOCK(wallet->cs_wallet);
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
@ -350,7 +350,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
BOOST_CHECK(result10); BOOST_CHECK(result10);
} }
{ {
std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain.get(), "", m_args, CreateMockWalletDatabase()); std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain.get(), "", CreateMockWalletDatabase());
wallet->LoadWallet(); wallet->LoadWallet();
LOCK(wallet->cs_wallet); LOCK(wallet->cs_wallet);
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
@ -415,7 +415,7 @@ BOOST_AUTO_TEST_CASE(knapsack_solver_test)
FastRandomContext rand{}; FastRandomContext rand{};
const auto temp1{[&rand](std::vector<OutputGroup>& g, const CAmount& v, CAmount c) { return KnapsackSolver(g, v, c, rand); }}; const auto temp1{[&rand](std::vector<OutputGroup>& g, const CAmount& v, CAmount c) { return KnapsackSolver(g, v, c, rand); }};
const auto KnapsackSolver{temp1}; const auto KnapsackSolver{temp1};
std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain.get(), "", m_args, CreateMockWalletDatabase()); std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain.get(), "", CreateMockWalletDatabase());
wallet->LoadWallet(); wallet->LoadWallet();
LOCK(wallet->cs_wallet); LOCK(wallet->cs_wallet);
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
@ -725,7 +725,7 @@ BOOST_AUTO_TEST_CASE(knapsack_solver_test)
BOOST_AUTO_TEST_CASE(ApproximateBestSubset) BOOST_AUTO_TEST_CASE(ApproximateBestSubset)
{ {
FastRandomContext rand{}; FastRandomContext rand{};
std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain.get(), "", m_args, CreateMockWalletDatabase()); std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain.get(), "", CreateMockWalletDatabase());
wallet->LoadWallet(); wallet->LoadWallet();
LOCK(wallet->cs_wallet); LOCK(wallet->cs_wallet);
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
@ -747,7 +747,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 // 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) BOOST_AUTO_TEST_CASE(SelectCoins_test)
{ {
std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain.get(), "", m_args, CreateMockWalletDatabase()); std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain.get(), "", CreateMockWalletDatabase());
wallet->LoadWallet(); wallet->LoadWallet();
LOCK(wallet->cs_wallet); LOCK(wallet->cs_wallet);
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
@ -934,7 +934,7 @@ BOOST_AUTO_TEST_CASE(effective_value_test)
static util::Result<SelectionResult> select_coins(const CAmount& target, const CoinSelectionParams& cs_params, const CCoinControl& cc, std::function<CoinsResult(CWallet&)> coin_setup, interfaces::Chain* chain) static util::Result<SelectionResult> select_coins(const CAmount& target, const CoinSelectionParams& cs_params, const CCoinControl& cc, std::function<CoinsResult(CWallet&)> coin_setup, interfaces::Chain* chain)
{ {
std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(chain, "", args, CreateMockWalletDatabase()); std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(chain, "", CreateMockWalletDatabase());
wallet->LoadWallet(); wallet->LoadWallet();
LOCK(wallet->cs_wallet); LOCK(wallet->cs_wallet);
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
@ -1056,7 +1056,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. // 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. // The coin is selected using coin control, with m_allow_other_inputs = false. SelectCoins should fail due to insufficient funds.
std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain.get(), "", m_args, CreateMockWalletDatabase()); std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain.get(), "", CreateMockWalletDatabase());
wallet->LoadWallet(); wallet->LoadWallet();
LOCK(wallet->cs_wallet); LOCK(wallet->cs_wallet);
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
@ -1064,7 +1064,7 @@ BOOST_AUTO_TEST_CASE(SelectCoins_effective_value_test)
CoinsResult available_coins; CoinsResult available_coins;
{ {
std::unique_ptr<CWallet> dummyWallet = std::make_unique<CWallet>(m_node.chain.get(), "dummy", m_args, CreateMockWalletDatabase()); std::unique_ptr<CWallet> dummyWallet = std::make_unique<CWallet>(m_node.chain.get(), "dummy", CreateMockWalletDatabase());
dummyWallet->LoadWallet(); dummyWallet->LoadWallet();
LOCK(dummyWallet->cs_wallet); LOCK(dummyWallet->cs_wallet);
dummyWallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); dummyWallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
@ -1105,7 +1105,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_coinsresult_test, BasicTestingSetup)
// Test case to verify CoinsResult object sanity. // Test case to verify CoinsResult object sanity.
CoinsResult available_coins; CoinsResult available_coins;
{ {
std::unique_ptr<CWallet> dummyWallet = std::make_unique<CWallet>(m_node.chain.get(), "dummy", m_args, CreateMockWalletDatabase()); std::unique_ptr<CWallet> dummyWallet = std::make_unique<CWallet>(m_node.chain.get(), "dummy", CreateMockWalletDatabase());
BOOST_CHECK_EQUAL(dummyWallet->LoadWallet(), DBErrors::LOAD_OK); BOOST_CHECK_EQUAL(dummyWallet->LoadWallet(), DBErrors::LOAD_OK);
LOCK(dummyWallet->cs_wallet); LOCK(dummyWallet->cs_wallet);
dummyWallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); dummyWallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);

View file

@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2PK compressed - Legacy // P2PK compressed - Legacy
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
scriptPubKey = GetScriptForRawPubKey(pubkeys[0]); scriptPubKey = GetScriptForRawPubKey(pubkeys[0]);
@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2PK compressed - Descriptor // P2PK compressed - Descriptor
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
std::string desc_str = "pk(" + EncodeSecret(keys[0]) + ")"; std::string desc_str = "pk(" + EncodeSecret(keys[0]) + ")";
auto spk_manager = CreateDescriptor(keystore, desc_str, true); auto spk_manager = CreateDescriptor(keystore, desc_str, true);
@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2PK uncompressed - Legacy // P2PK uncompressed - Legacy
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
scriptPubKey = GetScriptForRawPubKey(uncompressedPubkey); scriptPubKey = GetScriptForRawPubKey(uncompressedPubkey);
@ -105,7 +105,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2PK uncompressed - Descriptor // P2PK uncompressed - Descriptor
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
std::string desc_str = "pk(" + EncodeSecret(uncompressedKey) + ")"; std::string desc_str = "pk(" + EncodeSecret(uncompressedKey) + ")";
auto spk_manager = CreateDescriptor(keystore, desc_str, true); auto spk_manager = CreateDescriptor(keystore, desc_str, true);
@ -117,7 +117,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2PKH compressed - Legacy // P2PKH compressed - Legacy
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
scriptPubKey = GetScriptForDestination(PKHash(pubkeys[0])); scriptPubKey = GetScriptForDestination(PKHash(pubkeys[0]));
@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2PKH compressed - Descriptor // P2PKH compressed - Descriptor
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
std::string desc_str = "pkh(" + EncodeSecret(keys[0]) + ")"; std::string desc_str = "pkh(" + EncodeSecret(keys[0]) + ")";
auto spk_manager = CreateDescriptor(keystore, desc_str, true); auto spk_manager = CreateDescriptor(keystore, desc_str, true);
@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2PKH uncompressed - Legacy // P2PKH uncompressed - Legacy
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
scriptPubKey = GetScriptForDestination(PKHash(uncompressedPubkey)); scriptPubKey = GetScriptForDestination(PKHash(uncompressedPubkey));
@ -167,7 +167,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2PKH uncompressed - Descriptor // P2PKH uncompressed - Descriptor
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
std::string desc_str = "pkh(" + EncodeSecret(uncompressedKey) + ")"; std::string desc_str = "pkh(" + EncodeSecret(uncompressedKey) + ")";
auto spk_manager = CreateDescriptor(keystore, desc_str, true); auto spk_manager = CreateDescriptor(keystore, desc_str, true);
@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2SH - Legacy // P2SH - Legacy
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2SH - Descriptor // P2SH - Descriptor
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
std::string desc_str = "sh(pkh(" + EncodeSecret(keys[0]) + "))"; std::string desc_str = "sh(pkh(" + EncodeSecret(keys[0]) + "))";
auto spk_manager = CreateDescriptor(keystore, desc_str, true); auto spk_manager = CreateDescriptor(keystore, desc_str, true);
@ -219,7 +219,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// (P2PKH inside) P2SH inside P2SH (invalid) - Legacy // (P2PKH inside) P2SH inside P2SH (invalid) - Legacy
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
@ -238,7 +238,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// (P2PKH inside) P2SH inside P2SH (invalid) - Descriptor // (P2PKH inside) P2SH inside P2SH (invalid) - Descriptor
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
std::string desc_str = "sh(sh(" + EncodeSecret(keys[0]) + "))"; std::string desc_str = "sh(sh(" + EncodeSecret(keys[0]) + "))";
auto spk_manager = CreateDescriptor(keystore, desc_str, false); auto spk_manager = CreateDescriptor(keystore, desc_str, false);
@ -247,7 +247,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// (P2PKH inside) P2SH inside P2WSH (invalid) - Legacy // (P2PKH inside) P2SH inside P2WSH (invalid) - Legacy
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
@ -266,7 +266,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// (P2PKH inside) P2SH inside P2WSH (invalid) - Descriptor // (P2PKH inside) P2SH inside P2WSH (invalid) - Descriptor
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
std::string desc_str = "wsh(sh(" + EncodeSecret(keys[0]) + "))"; std::string desc_str = "wsh(sh(" + EncodeSecret(keys[0]) + "))";
auto spk_manager = CreateDescriptor(keystore, desc_str, false); auto spk_manager = CreateDescriptor(keystore, desc_str, false);
@ -275,7 +275,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2WPKH inside P2WSH (invalid) - Legacy // P2WPKH inside P2WSH (invalid) - Legacy
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
@ -292,7 +292,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2WPKH inside P2WSH (invalid) - Descriptor // P2WPKH inside P2WSH (invalid) - Descriptor
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
std::string desc_str = "wsh(wpkh(" + EncodeSecret(keys[0]) + "))"; std::string desc_str = "wsh(wpkh(" + EncodeSecret(keys[0]) + "))";
auto spk_manager = CreateDescriptor(keystore, desc_str, false); auto spk_manager = CreateDescriptor(keystore, desc_str, false);
@ -301,7 +301,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// (P2PKH inside) P2WSH inside P2WSH (invalid) - Legacy // (P2PKH inside) P2WSH inside P2WSH (invalid) - Legacy
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
@ -320,7 +320,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// (P2PKH inside) P2WSH inside P2WSH (invalid) - Descriptor // (P2PKH inside) P2WSH inside P2WSH (invalid) - Descriptor
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
std::string desc_str = "wsh(wsh(" + EncodeSecret(keys[0]) + "))"; std::string desc_str = "wsh(wsh(" + EncodeSecret(keys[0]) + "))";
auto spk_manager = CreateDescriptor(keystore, desc_str, false); auto spk_manager = CreateDescriptor(keystore, desc_str, false);
@ -329,7 +329,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2WPKH compressed - Legacy // P2WPKH compressed - Legacy
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
@ -345,7 +345,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2WPKH compressed - Descriptor // P2WPKH compressed - Descriptor
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
std::string desc_str = "wpkh(" + EncodeSecret(keys[0]) + ")"; std::string desc_str = "wpkh(" + EncodeSecret(keys[0]) + ")";
auto spk_manager = CreateDescriptor(keystore, desc_str, true); auto spk_manager = CreateDescriptor(keystore, desc_str, true);
@ -357,7 +357,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2WPKH uncompressed - Legacy // P2WPKH uncompressed - Legacy
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey)); BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
@ -378,7 +378,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2WPKH uncompressed (invalid) - Descriptor // P2WPKH uncompressed (invalid) - Descriptor
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
std::string desc_str = "wpkh(" + EncodeSecret(uncompressedKey) + ")"; std::string desc_str = "wpkh(" + EncodeSecret(uncompressedKey) + ")";
auto spk_manager = CreateDescriptor(keystore, desc_str, false); auto spk_manager = CreateDescriptor(keystore, desc_str, false);
@ -387,7 +387,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// scriptPubKey multisig - Legacy // scriptPubKey multisig - Legacy
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
@ -422,7 +422,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// scriptPubKey multisig - Descriptor // scriptPubKey multisig - Descriptor
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
std::string desc_str = "multi(2, " + EncodeSecret(uncompressedKey) + ", " + EncodeSecret(keys[1]) + ")"; std::string desc_str = "multi(2, " + EncodeSecret(uncompressedKey) + ", " + EncodeSecret(keys[1]) + ")";
auto spk_manager = CreateDescriptor(keystore, desc_str, true); auto spk_manager = CreateDescriptor(keystore, desc_str, true);
@ -434,7 +434,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2SH multisig - Legacy // P2SH multisig - Legacy
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey)); BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
@ -457,7 +457,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2SH multisig - Descriptor // P2SH multisig - Descriptor
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
std::string desc_str = "sh(multi(2, " + EncodeSecret(uncompressedKey) + ", " + EncodeSecret(keys[1]) + "))"; std::string desc_str = "sh(multi(2, " + EncodeSecret(uncompressedKey) + ", " + EncodeSecret(keys[1]) + "))";
@ -471,7 +471,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2WSH multisig with compressed keys - Legacy // P2WSH multisig with compressed keys - Legacy
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
@ -500,7 +500,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2WSH multisig with compressed keys - Descriptor // P2WSH multisig with compressed keys - Descriptor
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
std::string desc_str = "wsh(multi(2, " + EncodeSecret(keys[0]) + ", " + EncodeSecret(keys[1]) + "))"; std::string desc_str = "wsh(multi(2, " + EncodeSecret(keys[0]) + ", " + EncodeSecret(keys[1]) + "))";
@ -514,7 +514,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2WSH multisig with uncompressed key - Legacy // P2WSH multisig with uncompressed key - Legacy
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey)); BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
@ -543,7 +543,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2WSH multisig with uncompressed key (invalid) - Descriptor // P2WSH multisig with uncompressed key (invalid) - Descriptor
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
std::string desc_str = "wsh(multi(2, " + EncodeSecret(uncompressedKey) + ", " + EncodeSecret(keys[1]) + "))"; std::string desc_str = "wsh(multi(2, " + EncodeSecret(uncompressedKey) + ", " + EncodeSecret(keys[1]) + "))";
@ -553,7 +553,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2WSH multisig wrapped in P2SH - Legacy // P2WSH multisig wrapped in P2SH - Legacy
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
@ -583,7 +583,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// P2WSH multisig wrapped in P2SH - Descriptor // P2WSH multisig wrapped in P2SH - Descriptor
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
std::string desc_str = "sh(wsh(multi(2, " + EncodeSecret(keys[0]) + ", " + EncodeSecret(keys[1]) + ")))"; std::string desc_str = "sh(wsh(multi(2, " + EncodeSecret(keys[0]) + ", " + EncodeSecret(keys[1]) + ")))";
@ -598,7 +598,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// Combo - Descriptor // Combo - Descriptor
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
std::string desc_str = "combo(" + EncodeSecret(keys[0]) + ")"; std::string desc_str = "combo(" + EncodeSecret(keys[0]) + ")";
@ -642,7 +642,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// Taproot - Descriptor // Taproot - Descriptor
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
std::string desc_str = "tr(" + EncodeSecret(keys[0]) + ")"; std::string desc_str = "tr(" + EncodeSecret(keys[0]) + ")";
@ -660,7 +660,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// OP_RETURN // OP_RETURN
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
@ -675,7 +675,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// witness unspendable // witness unspendable
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
@ -690,7 +690,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// witness unknown // witness unknown
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
@ -705,7 +705,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
// Nonstandard // Nonstandard
{ {
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet keystore(chain.get(), "", CreateDummyWalletDatabase());
keystore.SetupLegacyScriptPubKeyMan(); keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));

View file

@ -18,7 +18,7 @@ BOOST_FIXTURE_TEST_SUITE(scriptpubkeyman_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(CanProvide) BOOST_AUTO_TEST_CASE(CanProvide)
{ {
// Set up wallet and keyman variables. // Set up wallet and keyman variables.
CWallet wallet(m_node.chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
LegacyScriptPubKeyMan& keyman = *wallet.GetOrCreateLegacyScriptPubKeyMan(); LegacyScriptPubKeyMan& keyman = *wallet.GetOrCreateLegacyScriptPubKeyMan();
// Make a 1 of 2 multisig script // Make a 1 of 2 multisig script

View file

@ -18,7 +18,7 @@ BOOST_FIXTURE_TEST_SUITE(spend_tests, WalletTestingSetup)
BOOST_FIXTURE_TEST_CASE(SubtractFee, TestChain100Setup) BOOST_FIXTURE_TEST_CASE(SubtractFee, TestChain100Setup)
{ {
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
auto wallet = CreateSyncedWallet(*m_node.chain, WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return m_node.chainman->ActiveChain()), m_args, coinbaseKey); auto wallet = CreateSyncedWallet(*m_node.chain, WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return m_node.chainman->ActiveChain()), coinbaseKey);
// Check that a subtract-from-recipient transaction slightly less than the // Check that a subtract-from-recipient transaction slightly less than the
// coinbase input amount does not create a change output (because it would // coinbase input amount does not create a change output (because it would
@ -118,7 +118,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_duplicated_preset_inputs_test, TestChain100Setup)
// Add 4 spendable UTXO, 50 BTC each, to the wallet (total balance 200 BTC) // Add 4 spendable UTXO, 50 BTC each, to the wallet (total balance 200 BTC)
for (int i = 0; i < 4; i++) CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); for (int i = 0; i < 4; i++) CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
auto wallet = CreateSyncedWallet(*m_node.chain, WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return m_node.chainman->ActiveChain()), m_args, coinbaseKey); auto wallet = CreateSyncedWallet(*m_node.chain, WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return m_node.chainman->ActiveChain()), coinbaseKey);
LOCK(wallet->cs_wallet); LOCK(wallet->cs_wallet);
auto available_coins = AvailableCoins(*wallet); auto available_coins = AvailableCoins(*wallet);

View file

@ -14,9 +14,9 @@
#include <memory> #include <memory>
namespace wallet { namespace wallet {
std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, ArgsManager& args, const CKey& key) std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, const CKey& key)
{ {
auto wallet = std::make_unique<CWallet>(&chain, "", args, CreateMockWalletDatabase()); auto wallet = std::make_unique<CWallet>(&chain, "", CreateMockWalletDatabase());
{ {
LOCK2(wallet->cs_wallet, ::cs_main); LOCK2(wallet->cs_wallet, ::cs_main);
wallet->SetLastBlockProcessed(cchain.Height(), cchain.Tip()->GetBlockHash()); wallet->SetLastBlockProcessed(cchain.Height(), cchain.Tip()->GetBlockHash());

View file

@ -21,7 +21,7 @@ class CWallet;
struct DatabaseOptions; struct DatabaseOptions;
class WalletDatabase; class WalletDatabase;
std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, ArgsManager& args, const CKey& key); std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, const CKey& key);
// Creates a copy of the provided database // Creates a copy of the provided database
std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database, DatabaseOptions& options); std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database, DatabaseOptions& options);

View file

@ -10,7 +10,7 @@ namespace wallet {
WalletTestingSetup::WalletTestingSetup(const std::string& chainName) WalletTestingSetup::WalletTestingSetup(const std::string& chainName)
: TestingSetup(chainName), : TestingSetup(chainName),
m_wallet_loader{interfaces::MakeWalletLoader(*m_node.chain, *Assert(m_node.args))}, m_wallet_loader{interfaces::MakeWalletLoader(*m_node.chain, *Assert(m_node.args))},
m_wallet(m_node.chain.get(), "", m_args, CreateMockWalletDatabase()) m_wallet(m_node.chain.get(), "", CreateMockWalletDatabase())
{ {
m_wallet.LoadWallet(); m_wallet.LoadWallet();
m_chain_notifications_handler = m_node.chain->handleNotifications({ &m_wallet, [](CWallet*) {} }); m_chain_notifications_handler = m_node.chain->handleNotifications({ &m_wallet, [](CWallet*) {} });

View file

@ -98,7 +98,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
// Verify ScanForWalletTransactions fails to read an unknown start block. // Verify ScanForWalletTransactions fails to read an unknown start block.
{ {
CWallet wallet(m_node.chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
{ {
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);
LOCK(Assert(m_node.chainman)->GetMutex()); LOCK(Assert(m_node.chainman)->GetMutex());
@ -119,7 +119,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
// Verify ScanForWalletTransactions picks up transactions in both the old // Verify ScanForWalletTransactions picks up transactions in both the old
// and new block files. // and new block files.
{ {
CWallet wallet(m_node.chain.get(), "", m_args, CreateMockWalletDatabase()); CWallet wallet(m_node.chain.get(), "", CreateMockWalletDatabase());
{ {
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);
LOCK(Assert(m_node.chainman)->GetMutex()); LOCK(Assert(m_node.chainman)->GetMutex());
@ -164,7 +164,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
// Verify ScanForWalletTransactions only picks transactions in the new block // Verify ScanForWalletTransactions only picks transactions in the new block
// file. // file.
{ {
CWallet wallet(m_node.chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
{ {
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);
LOCK(Assert(m_node.chainman)->GetMutex()); LOCK(Assert(m_node.chainman)->GetMutex());
@ -192,7 +192,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
// Verify ScanForWalletTransactions scans no blocks. // Verify ScanForWalletTransactions scans no blocks.
{ {
CWallet wallet(m_node.chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
{ {
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);
LOCK(Assert(m_node.chainman)->GetMutex()); LOCK(Assert(m_node.chainman)->GetMutex());
@ -232,7 +232,7 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup)
// before the missing block, and success for a key whose creation time is // before the missing block, and success for a key whose creation time is
// after. // after.
{ {
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", m_args, CreateDummyWalletDatabase()); const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", CreateDummyWalletDatabase());
wallet->SetupLegacyScriptPubKeyMan(); wallet->SetupLegacyScriptPubKeyMan();
WITH_LOCK(wallet->cs_wallet, wallet->SetLastBlockProcessed(newTip->nHeight, newTip->GetBlockHash())); WITH_LOCK(wallet->cs_wallet, wallet->SetLastBlockProcessed(newTip->nHeight, newTip->GetBlockHash()));
WalletContext context; WalletContext context;
@ -298,7 +298,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
{ {
WalletContext context; WalletContext context;
context.args = &m_args; context.args = &m_args;
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", m_args, CreateDummyWalletDatabase()); const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", CreateDummyWalletDatabase());
{ {
auto spk_man = wallet->GetOrCreateLegacyScriptPubKeyMan(); auto spk_man = wallet->GetOrCreateLegacyScriptPubKeyMan();
LOCK2(wallet->cs_wallet, spk_man->cs_KeyStore); LOCK2(wallet->cs_wallet, spk_man->cs_KeyStore);
@ -321,7 +321,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
// Call importwallet RPC and verify all blocks with timestamps >= BLOCK_TIME // Call importwallet RPC and verify all blocks with timestamps >= BLOCK_TIME
// were scanned, and no prior blocks were scanned. // were scanned, and no prior blocks were scanned.
{ {
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", m_args, CreateDummyWalletDatabase()); const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", CreateDummyWalletDatabase());
LOCK(wallet->cs_wallet); LOCK(wallet->cs_wallet);
wallet->SetupLegacyScriptPubKeyMan(); wallet->SetupLegacyScriptPubKeyMan();
@ -355,7 +355,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
// debit functions. // debit functions.
BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup) BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup)
{ {
CWallet wallet(m_node.chain.get(), "", m_args, CreateDummyWalletDatabase()); CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);
LOCK(Assert(m_node.chainman)->GetMutex()); LOCK(Assert(m_node.chainman)->GetMutex());
@ -527,7 +527,7 @@ public:
ListCoinsTestingSetup() ListCoinsTestingSetup()
{ {
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
wallet = CreateSyncedWallet(*m_node.chain, WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return m_node.chainman->ActiveChain()), m_args, coinbaseKey); wallet = CreateSyncedWallet(*m_node.chain, WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return m_node.chainman->ActiveChain()), coinbaseKey);
} }
~ListCoinsTestingSetup() ~ListCoinsTestingSetup()
@ -665,7 +665,7 @@ BOOST_FIXTURE_TEST_CASE(BasicOutputTypesTest, ListCoinsTest)
BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup) BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup)
{ {
{ {
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", m_args, CreateDummyWalletDatabase()); const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", CreateDummyWalletDatabase());
wallet->SetupLegacyScriptPubKeyMan(); wallet->SetupLegacyScriptPubKeyMan();
wallet->SetMinVersion(FEATURE_LATEST); wallet->SetMinVersion(FEATURE_LATEST);
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS); wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
@ -673,7 +673,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup)
BOOST_CHECK(!wallet->GetNewDestination(OutputType::BECH32, "")); BOOST_CHECK(!wallet->GetNewDestination(OutputType::BECH32, ""));
} }
{ {
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", m_args, CreateDummyWalletDatabase()); const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", CreateDummyWalletDatabase());
LOCK(wallet->cs_wallet); LOCK(wallet->cs_wallet);
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
wallet->SetMinVersion(FEATURE_LATEST); wallet->SetMinVersion(FEATURE_LATEST);
@ -961,7 +961,7 @@ public:
*/ */
BOOST_FIXTURE_TEST_CASE(wallet_sync_tx_invalid_state_test, TestingSetup) BOOST_FIXTURE_TEST_CASE(wallet_sync_tx_invalid_state_test, TestingSetup)
{ {
CWallet wallet(m_node.chain.get(), "", m_args, std::make_unique<FailDatabase>()); CWallet wallet(m_node.chain.get(), "", std::make_unique<FailDatabase>());
{ {
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS); wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);

View file

@ -46,7 +46,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_load_unknown_descriptor, TestingSetup)
{ {
// Now try to load the wallet and verify the error. // Now try to load the wallet and verify the error.
const std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", m_args, std::move(database))); const std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", std::move(database)));
BOOST_CHECK_EQUAL(wallet->LoadWallet(), DBErrors::UNKNOWN_DESCRIPTOR); 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. { // Context setup.
// Create and encrypt legacy wallet // Create and encrypt legacy wallet
std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", m_args, CreateMockWalletDatabase())); std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", CreateMockWalletDatabase()));
LOCK(wallet->cs_wallet); LOCK(wallet->cs_wallet);
auto legacy_spkm = wallet->GetOrCreateLegacyScriptPubKeyMan(); auto legacy_spkm = wallet->GetOrCreateLegacyScriptPubKeyMan();
BOOST_CHECK(legacy_spkm->SetupGeneration(true)); BOOST_CHECK(legacy_spkm->SetupGeneration(true));
@ -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. // the records every time that 'CWallet::Unlock' gets called, which is not good.
// Load the wallet and check that is encrypted // Load the wallet and check that is encrypted
std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", m_args, get_db(dbs))); std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", get_db(dbs)));
BOOST_CHECK_EQUAL(wallet->LoadWallet(), DBErrors::LOAD_OK); BOOST_CHECK_EQUAL(wallet->LoadWallet(), DBErrors::LOAD_OK);
BOOST_CHECK(wallet->IsCrypted()); BOOST_CHECK(wallet->IsCrypted());
BOOST_CHECK(HasAnyRecordOfType(wallet->GetDatabase(), DBKeys::CRYPTED_KEY)); 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 // Load the wallet and check that is encrypted
std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", m_args, std::move(db))); std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", std::move(db)));
BOOST_CHECK_EQUAL(wallet->LoadWallet(), DBErrors::LOAD_OK); BOOST_CHECK_EQUAL(wallet->LoadWallet(), DBErrors::LOAD_OK);
BOOST_CHECK(wallet->IsCrypted()); BOOST_CHECK(wallet->IsCrypted());
BOOST_CHECK(HasAnyRecordOfType(wallet->GetDatabase(), DBKeys::CRYPTED_KEY)); 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)); BOOST_CHECK(batch->Write(key, value, /*fOverwrite=*/true));
} }
std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", m_args, std::move(db))); std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", std::move(db)));
BOOST_CHECK_EQUAL(wallet->LoadWallet(), DBErrors::CORRUPT); 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)); BOOST_CHECK(db->MakeBatch(false)->Write(key, value, /*fOverwrite=*/true));
} }
std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", m_args, std::move(db))); std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", std::move(db)));
BOOST_CHECK_EQUAL(wallet->LoadWallet(), DBErrors::CORRUPT); BOOST_CHECK_EQUAL(wallet->LoadWallet(), DBErrors::CORRUPT);
} }
} }

View file

@ -2913,7 +2913,7 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
const auto start{SteadyClock::now()}; const auto start{SteadyClock::now()};
// TODO: Can't use std::make_shared because we need a custom deleter but // TODO: Can't use std::make_shared because we need a custom deleter but
// should be possible to use std::allocate_shared. // should be possible to use std::allocate_shared.
std::shared_ptr<CWallet> walletInstance(new CWallet(chain, name, args, std::move(database)), ReleaseWallet); std::shared_ptr<CWallet> 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_keypool_size = std::max(args.GetIntArg("-keypool", DEFAULT_KEYPOOL_SIZE), int64_t{1});
walletInstance->m_notify_tx_changed_script = args.GetArg("-walletnotify", ""); walletInstance->m_notify_tx_changed_script = args.GetArg("-walletnotify", "");

View file

@ -307,9 +307,6 @@ private:
//! Unset the blank wallet flag and saves it to disk //! Unset the blank wallet flag and saves it to disk
void UnsetBlankWalletFlag(WalletBatch& batch) override; void UnsetBlankWalletFlag(WalletBatch& batch) override;
/** Provider of aplication-wide arguments. */
const ArgsManager& m_args;
/** Interface for accessing chain state. */ /** Interface for accessing chain state. */
interfaces::Chain* m_chain; interfaces::Chain* m_chain;
@ -373,9 +370,8 @@ public:
unsigned int nMasterKeyMaxID = 0; unsigned int nMasterKeyMaxID = 0;
/** Construct wallet with specified name and database implementation. */ /** Construct wallet with specified name and database implementation. */
CWallet(interfaces::Chain* chain, const std::string& name, const ArgsManager& args, std::unique_ptr<WalletDatabase> database) CWallet(interfaces::Chain* chain, const std::string& name, std::unique_ptr<WalletDatabase> database)
: m_args(args), : m_chain(chain),
m_chain(chain),
m_name(name), m_name(name),
m_database(std::move(database)) m_database(std::move(database))
{ {

View file

@ -47,7 +47,7 @@ static void WalletCreate(CWallet* wallet_instance, uint64_t wallet_creation_flag
wallet_instance->TopUpKeyPool(); wallet_instance->TopUpKeyPool();
} }
static std::shared_ptr<CWallet> MakeWallet(const std::string& name, const fs::path& path, const ArgsManager& args, DatabaseOptions options) static std::shared_ptr<CWallet> MakeWallet(const std::string& name, const fs::path& path, DatabaseOptions options)
{ {
DatabaseStatus status; DatabaseStatus status;
bilingual_str error; bilingual_str error;
@ -58,7 +58,7 @@ static std::shared_ptr<CWallet> MakeWallet(const std::string& name, const fs::pa
} }
// dummy chain interface // dummy chain interface
std::shared_ptr<CWallet> wallet_instance{new CWallet(/*chain=*/nullptr, name, args, std::move(database)), WalletToolReleaseWallet}; std::shared_ptr<CWallet> wallet_instance{new CWallet(/*chain=*/nullptr, name, std::move(database)), WalletToolReleaseWallet};
DBErrors load_wallet_ret; DBErrors load_wallet_ret;
try { try {
load_wallet_ret = wallet_instance->LoadWallet(); load_wallet_ret = wallet_instance->LoadWallet();
@ -159,7 +159,7 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command)
options.require_format = DatabaseFormat::SQLITE; options.require_format = DatabaseFormat::SQLITE;
} }
const std::shared_ptr<CWallet> wallet_instance = MakeWallet(name, path, args, options); const std::shared_ptr<CWallet> wallet_instance = MakeWallet(name, path, options);
if (wallet_instance) { if (wallet_instance) {
WalletShowInfo(wallet_instance.get()); WalletShowInfo(wallet_instance.get());
wallet_instance->Close(); wallet_instance->Close();
@ -168,7 +168,7 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command)
DatabaseOptions options; DatabaseOptions options;
ReadDatabaseArgs(args, options); ReadDatabaseArgs(args, options);
options.require_existing = true; options.require_existing = true;
const std::shared_ptr<CWallet> wallet_instance = MakeWallet(name, path, args, options); const std::shared_ptr<CWallet> wallet_instance = MakeWallet(name, path, options);
if (!wallet_instance) return false; if (!wallet_instance) return false;
WalletShowInfo(wallet_instance.get()); WalletShowInfo(wallet_instance.get());
wallet_instance->Close(); wallet_instance->Close();
@ -194,7 +194,7 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command)
DatabaseOptions options; DatabaseOptions options;
ReadDatabaseArgs(args, options); ReadDatabaseArgs(args, options);
options.require_existing = true; options.require_existing = true;
const std::shared_ptr<CWallet> wallet_instance = MakeWallet(name, path, args, options); const std::shared_ptr<CWallet> wallet_instance = MakeWallet(name, path, options);
if (!wallet_instance) return false; if (!wallet_instance) return false;
bilingual_str error; bilingual_str error;
bool ret = DumpWallet(args, *wallet_instance, error); bool ret = DumpWallet(args, *wallet_instance, error);