Skip to content

Commit 0964068

Browse files
knstPastaPastaPasta
authored andcommitted
refactor: working with raw pointer of coinjoin_loader instead reference to unique_ptr
1 parent 09207a4 commit 0964068

File tree

12 files changed

+37
-39
lines changed

12 files changed

+37
-39
lines changed

src/bench/wallet_balance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b
2424
};
2525
const auto& ADDRESS_WATCHONLY = ADDRESS_B58T_UNSPENDABLE;
2626

27-
CWallet wallet{test_setup.m_node.chain.get(), test_setup.m_node.coinjoin_loader, "", CreateMockWalletDatabase()};
27+
CWallet wallet{test_setup.m_node.chain.get(), test_setup.m_node.coinjoin_loader.get(), "", CreateMockWalletDatabase()};
2828
{
2929
wallet.SetupLegacyScriptPubKeyMan();
3030
bool first_run;

src/qt/test/addressbooktests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void TestAddAddressesToSendBook(interfaces::Node& node)
6060
{
6161
TestChain100Setup test;
6262
node.setContext(&test.m_node);
63-
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), node.context()->coinjoin_loader, "", CreateMockWalletDatabase());
63+
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), node.context()->coinjoin_loader.get(), "", CreateMockWalletDatabase());
6464
wallet->SetupLegacyScriptPubKeyMan();
6565
bool firstRun;
6666
wallet->LoadWallet(firstRun);

src/qt/test/wallettests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void TestGUI(interfaces::Node& node)
108108
test.CreateAndProcessBlock({}, GetScriptForRawPubKey(test.coinbaseKey.GetPubKey()));
109109
}
110110
node.setContext(&test.m_node);
111-
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), node.context()->coinjoin_loader, "", CreateMockWalletDatabase());
111+
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), node.context()->coinjoin_loader.get(), "", CreateMockWalletDatabase());
112112
AddWallet(wallet);
113113
bool firstRun;
114114
wallet->LoadWallet(firstRun);

src/wallet/interfaces.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ class WalletLoaderImpl : public WalletLoader
578578
}
579579
}
580580
bool verify() override { return VerifyWallets(*m_context.chain); }
581-
bool load() override { assert(m_context.m_coinjoin_loader); return LoadWallets(*m_context.chain, m_context.m_coinjoin_loader); }
581+
bool load() override { assert(m_context.m_coinjoin_loader); return LoadWallets(*m_context.chain, *m_context.m_coinjoin_loader); }
582582
void start(CScheduler& scheduler) override { return StartWallets(scheduler, *Assert(m_context.args)); }
583583
void flush() override { return FlushWallets(); }
584584
void stop() override { return StopWallets(); }
@@ -594,15 +594,15 @@ class WalletLoaderImpl : public WalletLoader
594594
options.create_flags = wallet_creation_flags;
595595
options.create_passphrase = passphrase;
596596
assert(m_context.m_coinjoin_loader);
597-
return MakeWallet(CreateWallet(*m_context.chain, m_context.m_coinjoin_loader, name, true /* load_on_start */, options, status, error, warnings));
597+
return MakeWallet(CreateWallet(*m_context.chain, *m_context.m_coinjoin_loader, name, true /* load_on_start */, options, status, error, warnings));
598598
}
599599
std::unique_ptr<Wallet> loadWallet(const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings) override
600600
{
601601
DatabaseOptions options;
602602
DatabaseStatus status;
603603
options.require_existing = true;
604604
assert(m_context.m_coinjoin_loader);
605-
return MakeWallet(LoadWallet(*m_context.chain, m_context.m_coinjoin_loader, name, true /* load_on_start */, options, status, error, warnings));
605+
return MakeWallet(LoadWallet(*m_context.chain, *m_context.m_coinjoin_loader, name, true /* load_on_start */, options, status, error, warnings));
606606
}
607607
std::string getWalletDir() override
608608
{

src/wallet/load.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ bool VerifyWallets(interfaces::Chain& chain)
9090
return true;
9191
}
9292

93-
bool LoadWallets(interfaces::Chain& chain, const std::unique_ptr<interfaces::CoinJoin::Loader>& coinjoin_loader)
93+
bool LoadWallets(interfaces::Chain& chain, interfaces::CoinJoin::Loader& coinjoin_loader)
9494
{
9595
try {
9696
std::set<fs::path> wallet_paths;

src/wallet/load.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#ifndef BITCOIN_WALLET_LOAD_H
77
#define BITCOIN_WALLET_LOAD_H
88

9-
#include <memory>
109
#include <string>
1110
#include <vector>
1211

@@ -25,7 +24,7 @@ class Loader;
2524
bool VerifyWallets(interfaces::Chain& chain);
2625

2726
//! Load wallet databases.
28-
bool LoadWallets(interfaces::Chain& chain, const std::unique_ptr<interfaces::CoinJoin::Loader>& coinjoin_loader);
27+
bool LoadWallets(interfaces::Chain& chain, interfaces::CoinJoin::Loader& coinjoin_loader);
2928

3029
//! Complete startup of wallets.
3130
void StartWallets(CScheduler& scheduler, const ArgsManager& args);

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2805,7 +2805,7 @@ static UniValue loadwallet(const JSONRPCRequest& request)
28052805
bilingual_str error;
28062806
std::vector<bilingual_str> warnings;
28072807
std::optional<bool> load_on_start = request.params[1].isNull() ? std::nullopt : std::optional<bool>(request.params[1].get_bool());
2808-
std::shared_ptr<CWallet> const wallet = LoadWallet(*context.chain, context.m_coinjoin_loader, name, load_on_start, options, status, error, warnings);
2808+
std::shared_ptr<CWallet> const wallet = LoadWallet(*context.chain, *context.m_coinjoin_loader, name, load_on_start, options, status, error, warnings);
28092809
if (!wallet) {
28102810
// Map bad format to not found, since bad format is returned when the
28112811
// wallet directory exists, but doesn't contain a data file.
@@ -2954,7 +2954,7 @@ static UniValue createwallet(const JSONRPCRequest& request)
29542954
options.create_passphrase = passphrase;
29552955
bilingual_str error;
29562956
std::optional<bool> load_on_start = request.params[5].isNull() ? std::nullopt : std::optional<bool>(request.params[5].get_bool());
2957-
std::shared_ptr<CWallet> wallet = CreateWallet(*context.chain, context.m_coinjoin_loader, request.params[0].get_str(), load_on_start, options, status, error, warnings);
2957+
std::shared_ptr<CWallet> wallet = CreateWallet(*context.chain, *context.m_coinjoin_loader, request.params[0].get_str(), load_on_start, options, status, error, warnings);
29582958
if (!wallet) {
29592959
RPCErrorCode code = status == DatabaseStatus::FAILED_ENCRYPT ? RPC_WALLET_ENCRYPTION_FAILED : RPC_WALLET_ERROR;
29602960
throw JSONRPCError(code, error.original);

src/wallet/test/coinjoin_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class CTransactionBuilderTestSetup : public TestChain100Setup
130130
CTransactionBuilderTestSetup()
131131
{
132132
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
133-
wallet = std::make_unique<CWallet>(m_node.chain.get(), m_node.coinjoin_loader, "", CreateMockWalletDatabase());
133+
wallet = std::make_unique<CWallet>(m_node.chain.get(), m_node.coinjoin_loader.get(), "", CreateMockWalletDatabase());
134134
wallet->SetupLegacyScriptPubKeyMan();
135135
bool firstRun;
136136
wallet->LoadWallet(firstRun);

src/wallet/test/wallet_test_fixture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
WalletTestingSetup::WalletTestingSetup(const std::string& chainName)
99
: TestingSetup(chainName),
1010
m_wallet_loader{interfaces::MakeWalletLoader(*m_node.chain, m_node.coinjoin_loader, *Assert(m_node.args))},
11-
m_wallet(m_node.chain.get(), m_node.coinjoin_loader, "", CreateMockWalletDatabase())
11+
m_wallet(m_node.chain.get(), m_node.coinjoin_loader.get(), "", CreateMockWalletDatabase())
1212
{
1313
bool fFirstRun;
1414
m_wallet.LoadWallet(fFirstRun);

src/wallet/test/wallet_tests.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static std::shared_ptr<CWallet> TestLoadWallet(NodeContext& node)
5252
bilingual_str error;
5353
std::vector<bilingual_str> warnings;
5454
auto database = MakeWalletDatabase("", options, status, error);
55-
auto wallet = CWallet::Create(*node.chain, node.coinjoin_loader, "", std::move(database), options.create_flags, error, warnings);
55+
auto wallet = CWallet::Create(*node.chain, *node.coinjoin_loader, "", std::move(database), options.create_flags, error, warnings);
5656
wallet->postInitProcess();
5757
return wallet;
5858
}
@@ -97,7 +97,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
9797

9898
// Verify ScanForWalletTransactions fails to read an unknown start block.
9999
{
100-
CWallet wallet(m_node.chain.get(), m_node.coinjoin_loader, "", CreateDummyWalletDatabase());
100+
CWallet wallet(m_node.chain.get(), m_node.coinjoin_loader.get(), "", CreateDummyWalletDatabase());
101101
wallet.SetupLegacyScriptPubKeyMan();
102102
{
103103
LOCK(wallet.cs_wallet);
@@ -117,7 +117,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
117117
// Verify ScanForWalletTransactions picks up transactions in both the old
118118
// and new block files.
119119
{
120-
CWallet wallet(m_node.chain.get(), m_node.coinjoin_loader, "", CreateDummyWalletDatabase());
120+
CWallet wallet(m_node.chain.get(), m_node.coinjoin_loader.get(), "", CreateDummyWalletDatabase());
121121
{
122122
LOCK(wallet.cs_wallet);
123123
wallet.SetLastBlockProcessed(::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash());
@@ -143,7 +143,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
143143
// Verify ScanForWalletTransactions only picks transactions in the new block
144144
// file.
145145
{
146-
CWallet wallet(m_node.chain.get(), m_node.coinjoin_loader, "", CreateDummyWalletDatabase());
146+
CWallet wallet(m_node.chain.get(), m_node.coinjoin_loader.get(), "", CreateDummyWalletDatabase());
147147
{
148148
LOCK(wallet.cs_wallet);
149149
wallet.SetLastBlockProcessed(::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash());
@@ -168,7 +168,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
168168

169169
// Verify ScanForWalletTransactions scans no blocks.
170170
{
171-
CWallet wallet(m_node.chain.get(), m_node.coinjoin_loader, "", CreateDummyWalletDatabase());
171+
CWallet wallet(m_node.chain.get(), m_node.coinjoin_loader.get(), "", CreateDummyWalletDatabase());
172172
{
173173
LOCK(wallet.cs_wallet);
174174
wallet.SetLastBlockProcessed(::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash());
@@ -204,7 +204,7 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup)
204204
// before the missing block, and success for a key whose creation time is
205205
// after.
206206
{
207-
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), m_node.coinjoin_loader, "", CreateDummyWalletDatabase());
207+
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), m_node.coinjoin_loader.get(), "", CreateDummyWalletDatabase());
208208
wallet->SetupLegacyScriptPubKeyMan();
209209
WITH_LOCK(wallet->cs_wallet, wallet->SetLastBlockProcessed(newTip->nHeight, newTip->GetBlockHash()));
210210
AddWallet(wallet);
@@ -266,7 +266,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
266266

267267
// Import key into wallet and call dumpwallet to create backup file.
268268
{
269-
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), m_node.coinjoin_loader, "", CreateDummyWalletDatabase());
269+
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), m_node.coinjoin_loader.get(), "", CreateDummyWalletDatabase());
270270
{
271271
auto spk_man = wallet->GetOrCreateLegacyScriptPubKeyMan();
272272
LOCK2(wallet->cs_wallet, spk_man->cs_KeyStore);
@@ -289,7 +289,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
289289
// Call importwallet RPC and verify all blocks with timestamps >= BLOCK_TIME
290290
// were scanned, and no prior blocks were scanned.
291291
{
292-
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), m_node.coinjoin_loader, "", CreateDummyWalletDatabase());
292+
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), m_node.coinjoin_loader.get(), "", CreateDummyWalletDatabase());
293293
LOCK(wallet->cs_wallet);
294294
wallet->SetupLegacyScriptPubKeyMan();
295295

@@ -317,7 +317,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
317317
// Verify getaddressinfo RPC produces more or less expected results
318318
BOOST_FIXTURE_TEST_CASE(rpc_getaddressinfo, TestChain100Setup)
319319
{
320-
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), m_node.coinjoin_loader, "", CreateMockWalletDatabase());
320+
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), m_node.coinjoin_loader.get(), "", CreateMockWalletDatabase());
321321
wallet->SetupLegacyScriptPubKeyMan();
322322
AddWallet(wallet);
323323
CoreContext context{m_node};
@@ -398,7 +398,7 @@ BOOST_FIXTURE_TEST_CASE(rpc_getaddressinfo, TestChain100Setup)
398398
// debit functions.
399399
BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup)
400400
{
401-
CWallet wallet(m_node.chain.get(), m_node.coinjoin_loader, "", CreateDummyWalletDatabase());
401+
CWallet wallet(m_node.chain.get(), m_node.coinjoin_loader.get(), "", CreateDummyWalletDatabase());
402402
auto spk_man = wallet.GetOrCreateLegacyScriptPubKeyMan();
403403
CWalletTx wtx(&wallet, m_coinbase_txns.back());
404404

@@ -573,7 +573,7 @@ class ListCoinsTestingSetup : public TestChain100Setup
573573
ListCoinsTestingSetup()
574574
{
575575
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
576-
wallet = std::make_unique<CWallet>(m_node.chain.get(), m_node.coinjoin_loader, "", CreateMockWalletDatabase());
576+
wallet = std::make_unique<CWallet>(m_node.chain.get(), m_node.coinjoin_loader.get(), "", CreateMockWalletDatabase());
577577
{
578578
LOCK(wallet->cs_wallet);
579579
wallet->SetLastBlockProcessed(::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash());
@@ -710,7 +710,7 @@ class CreateTransactionTestSetup : public TestChain100Setup
710710
CreateTransactionTestSetup()
711711
{
712712
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
713-
wallet = std::make_unique<CWallet>(m_node.chain.get(), m_node.coinjoin_loader, "", CreateMockWalletDatabase());
713+
wallet = std::make_unique<CWallet>(m_node.chain.get(), m_node.coinjoin_loader.get(), "", CreateMockWalletDatabase());
714714
bool firstRun;
715715
wallet->LoadWallet(firstRun);
716716
AddWallet(wallet);
@@ -1191,7 +1191,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup)
11911191
node.fee_estimator = std::make_unique<CBlockPolicyEstimator>();
11921192
node.mempool = std::make_unique<CTxMemPool>(node.fee_estimator.get());
11931193
auto chain = interfaces::MakeChain(node);
1194-
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(chain.get(), m_node.coinjoin_loader, "", CreateDummyWalletDatabase());
1194+
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(chain.get(), m_node.coinjoin_loader.get(), "", CreateDummyWalletDatabase());
11951195
wallet->SetupLegacyScriptPubKeyMan();
11961196
wallet->SetMinVersion(FEATURE_LATEST);
11971197
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);

0 commit comments

Comments
 (0)