Skip to content

Commit faf8401

Browse files
author
MarcoFalke
committed
wallet: Pass unused args to StartWallets
This refactor does not change behavior
1 parent fa6c186 commit faf8401

File tree

9 files changed

+29
-18
lines changed

9 files changed

+29
-18
lines changed

src/interfaces/chain.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <string>
1616
#include <vector>
1717

18+
class ArgsManager;
1819
class CBlock;
1920
class CFeeRate;
2021
class CRPCCommand;
@@ -322,7 +323,7 @@ std::unique_ptr<Chain> MakeChain(NodeContext& node);
322323
//! analysis, or fee estimation. These clients need to expose their own
323324
//! MakeXXXClient functions returning their implementations of the ChainClient
324325
//! interface.
325-
std::unique_ptr<ChainClient> MakeWalletClient(Chain& chain, std::vector<std::string> wallet_filenames);
326+
std::unique_ptr<ChainClient> MakeWalletClient(Chain& chain, ArgsManager& args, std::vector<std::string> wallet_filenames);
326327

327328
} // namespace interfaces
328329

src/interfaces/wallet.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,11 @@ class WalletImpl : public Wallet
483483
class WalletClientImpl : public ChainClient
484484
{
485485
public:
486-
WalletClientImpl(Chain& chain, std::vector<std::string> wallet_filenames)
486+
WalletClientImpl(Chain& chain, ArgsManager& args, std::vector<std::string> wallet_filenames)
487487
: m_wallet_filenames(std::move(wallet_filenames))
488488
{
489489
m_context.chain = &chain;
490+
m_context.args = &args;
490491
}
491492
void registerRpcs() override
492493
{
@@ -499,7 +500,7 @@ class WalletClientImpl : public ChainClient
499500
}
500501
bool verify() override { return VerifyWallets(*m_context.chain, m_wallet_filenames); }
501502
bool load() override { return LoadWallets(*m_context.chain, m_wallet_filenames); }
502-
void start(CScheduler& scheduler) override { return StartWallets(scheduler); }
503+
void start(CScheduler& scheduler) override { return StartWallets(scheduler, *Assert(m_context.args)); }
503504
void flush() override { return FlushWallets(); }
504505
void stop() override { return StopWallets(); }
505506
void setMockTime(int64_t time) override { return SetMockTime(time); }
@@ -514,7 +515,7 @@ class WalletClientImpl : public ChainClient
514515
~WalletClientImpl() override { UnloadWallets(); }
515516

516517
WalletContext m_context;
517-
std::vector<std::string> m_wallet_filenames;
518+
const std::vector<std::string> m_wallet_filenames;
518519
std::vector<std::unique_ptr<Handler>> m_rpc_handlers;
519520
std::list<CRPCCommand> m_rpc_commands;
520521
};
@@ -523,9 +524,9 @@ class WalletClientImpl : public ChainClient
523524

524525
std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet) { return wallet ? MakeUnique<WalletImpl>(wallet) : nullptr; }
525526

526-
std::unique_ptr<ChainClient> MakeWalletClient(Chain& chain, std::vector<std::string> wallet_filenames)
527+
std::unique_ptr<ChainClient> MakeWalletClient(Chain& chain, ArgsManager& args, std::vector<std::string> wallet_filenames)
527528
{
528-
return MakeUnique<WalletClientImpl>(chain, std::move(wallet_filenames));
529+
return MakeUnique<WalletClientImpl>(chain, args, std::move(wallet_filenames));
529530
}
530531

531532
} // namespace interfaces

src/qt/test/test_main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
4040
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
4141

4242
// This is all you need to run all the tests
43-
int main(int argc, char *argv[])
43+
int main(int argc, char* argv[])
4444
{
4545
// Initialize persistent globals with the testing setup state for sanity.
4646
// E.g. -datadir in gArgs is set to a temp directory dummy value (instead
@@ -70,6 +70,8 @@ int main(int argc, char *argv[])
7070
BitcoinApplication app(*node);
7171
app.setApplicationName("Bitcoin-Qt-test");
7272

73+
node->setupServerArgs(); // Make gArgs available in the NodeContext
74+
node->context()->args->ClearArgs(); // Clear added args again
7375
AppTests app_tests(app);
7476
if (QTest::qExec(&app_tests) != 0) {
7577
fInvalid = true;

src/wallet/context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef BITCOIN_WALLET_CONTEXT_H
66
#define BITCOIN_WALLET_CONTEXT_H
77

8+
class ArgsManager;
89
namespace interfaces {
910
class Chain;
1011
} // namespace interfaces
@@ -21,6 +22,7 @@ class Chain;
2122
//! behavior.
2223
struct WalletContext {
2324
interfaces::Chain* chain{nullptr};
25+
ArgsManager* args{nullptr};
2426

2527
//! Declare default constructor and destructor that are not inline, so code
2628
//! instantiating the WalletContext struct doesn't need to #include class

src/wallet/init.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@
99
#include <node/context.h>
1010
#include <node/ui_interface.h>
1111
#include <outputtype.h>
12+
#include <util/check.h>
1213
#include <util/moneystr.h>
1314
#include <util/system.h>
1415
#include <util/translation.h>
1516
#include <wallet/coincontrol.h>
1617
#include <wallet/wallet.h>
1718
#include <walletinitinterface.h>
1819

19-
class WalletInit : public WalletInitInterface {
20+
class WalletInit : public WalletInitInterface
21+
{
2022
public:
21-
2223
//! Was the wallet component compiled in.
2324
bool HasWalletSupport() const override {return true;}
2425

@@ -112,10 +113,11 @@ bool WalletInit::ParameterInteraction() const
112113

113114
void WalletInit::Construct(NodeContext& node) const
114115
{
115-
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
116+
ArgsManager& args = *Assert(node.args);
117+
if (args.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
116118
LogPrintf("Wallet disabled!\n");
117119
return;
118120
}
119-
gArgs.SoftSetArg("-wallet", "");
120-
node.chain_clients.emplace_back(interfaces::MakeWalletClient(*node.chain, gArgs.GetArgs("-wallet")));
121+
args.SoftSetArg("-wallet", "");
122+
node.chain_clients.emplace_back(interfaces::MakeWalletClient(*node.chain, args, args.GetArgs("-wallet")));
121123
}

src/wallet/load.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ bool LoadWallets(interfaces::Chain& chain, const std::vector<std::string>& walle
8282
}
8383
}
8484

85-
void StartWallets(CScheduler& scheduler)
85+
void StartWallets(CScheduler& scheduler, const ArgsManager& args)
8686
{
8787
for (const std::shared_ptr<CWallet>& pwallet : GetWallets()) {
8888
pwallet->postInitProcess();

src/wallet/load.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <string>
1010
#include <vector>
1111

12+
class ArgsManager;
1213
class CScheduler;
1314

1415
namespace interfaces {
@@ -22,7 +23,7 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
2223
bool LoadWallets(interfaces::Chain& chain, const std::vector<std::string>& wallet_files);
2324

2425
//! Complete startup of wallets.
25-
void StartWallets(CScheduler& scheduler);
26+
void StartWallets(CScheduler& scheduler, const ArgsManager& args);
2627

2728
//! Flush all wallets in preparation for shutdown.
2829
void FlushWallets();

src/wallet/test/init_test_fixture.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <fs.h>
6+
#include <util/check.h>
67
#include <util/system.h>
78

89
#include <wallet/test/init_test_fixture.h>
910

10-
InitWalletDirTestingSetup::InitWalletDirTestingSetup(const std::string& chainName): BasicTestingSetup(chainName)
11+
InitWalletDirTestingSetup::InitWalletDirTestingSetup(const std::string& chainName) : BasicTestingSetup(chainName)
1112
{
12-
m_chain_client = MakeWalletClient(*m_chain, {});
13+
m_chain_client = MakeWalletClient(*m_chain, *Assert(m_node.args), {});
1314

1415
std::string sep;
1516
sep += fs::path::preferred_separator;

src/wallet/test/wallet_test_fixture.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@
1010
#include <interfaces/chain.h>
1111
#include <interfaces/wallet.h>
1212
#include <node/context.h>
13+
#include <util/check.h>
1314
#include <wallet/wallet.h>
1415

1516
#include <memory>
1617

1718
/** Testing setup and teardown for wallet.
1819
*/
19-
struct WalletTestingSetup: public TestingSetup {
20+
struct WalletTestingSetup : public TestingSetup {
2021
explicit WalletTestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
2122

2223
std::unique_ptr<interfaces::Chain> m_chain = interfaces::MakeChain(m_node);
23-
std::unique_ptr<interfaces::ChainClient> m_chain_client = interfaces::MakeWalletClient(*m_chain, {});
24+
std::unique_ptr<interfaces::ChainClient> m_chain_client = interfaces::MakeWalletClient(*m_chain, *Assert(m_node.args), {});
2425
CWallet m_wallet;
2526
std::unique_ptr<interfaces::Handler> m_chain_notifications_handler;
2627
};

0 commit comments

Comments
 (0)