aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-08-26 10:01:39 +0200
committerMarcoFalke <falke.marco@gmail.com>2021-08-26 10:01:43 +0200
commitcea38b491f6a2929097114b7b609a774f622d58a (patch)
treeee3de621bbc71c74aebc04ededa6c6578750fe83
parent84be9a89c1a49a7be5bc43d832b4cb9cbd09fce3 (diff)
parentc3c213215b25f3e6f36d46b1d49dfcc3040cee1c (diff)
Merge bitcoin/bitcoin#22183: Remove `gArgs` from `wallet.h` and `wallet.cpp`
c3c213215b25f3e6f36d46b1d49dfcc3040cee1c Use `context.args` in `src/wallet/load.cpp`. (Kiminuo) 25de4e77feddf9b2f4d134bab5faa26c3e5a764d Use `context.args` in `CWallet::Create` instead of `gArgs`. (Kiminuo) aa5e7c9471c50771bc77b0ec4e0e0929e4a32eae Fix typo in bitcoin-cli.cpp (Kiminuo) Pull request description: The PR attempts to move us an inch towards the [goal](https://github.com/bitcoin/bitcoin/pull/21244#discussion_r615307465) by using `WalletContext` in `wallet.{h|cpp}` code instead of relying on the global state (i.e. `gArgs`). Edit: The PR builds on #19101. ACKs for top commit: ryanofsky: Code review ACK c3c213215b25f3e6f36d46b1d49dfcc3040cee1c. Changes since last review: just rebasing and adding wallet load commit Tree-SHA512: 2b436f5a219e32c2d529f55a89edca086d949396cebf9e089a21aa7b1c180e3c0fb17468f415dfc834f8e1614f8b3914c7e9a0bd33b95e7e0199c0dfe5ca9490
-rw-r--r--src/bitcoin-cli.cpp2
-rw-r--r--src/wallet/load.cpp11
-rw-r--r--src/wallet/test/wallet_tests.cpp6
-rw-r--r--src/wallet/wallet.cpp59
4 files changed, 44 insertions, 34 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
index bc0af6398c..34785bf6a4 100644
--- a/src/bitcoin-cli.cpp
+++ b/src/bitcoin-cli.cpp
@@ -885,7 +885,7 @@ static void GetWalletBalances(UniValue& result)
}
/**
- * GetProgressBar contructs a progress bar with 5% intervals.
+ * GetProgressBar constructs a progress bar with 5% intervals.
*
* @param[in] progress The proportion of the progress bar to be filled between 0 and 1.
* @param[out] progress_bar String representation of the progress bar.
diff --git a/src/wallet/load.cpp b/src/wallet/load.cpp
index 88e9b9c78f..85cdbb67c9 100644
--- a/src/wallet/load.cpp
+++ b/src/wallet/load.cpp
@@ -8,6 +8,7 @@
#include <fs.h>
#include <interfaces/chain.h>
#include <scheduler.h>
+#include <util/check.h>
#include <util/string.h>
#include <util/system.h>
#include <util/translation.h>
@@ -20,8 +21,10 @@
bool VerifyWallets(WalletContext& context)
{
interfaces::Chain& chain = *context.chain;
- if (gArgs.IsArgSet("-walletdir")) {
- fs::path wallet_dir = gArgs.GetArg("-walletdir", "");
+ ArgsManager& args = *Assert(context.args);
+
+ if (args.IsArgSet("-walletdir")) {
+ fs::path wallet_dir = args.GetArg("-walletdir", "");
boost::system::error_code error;
// The canonical path cleans the path, preventing >1 Berkeley environment instances for the same directory
fs::path canonical_wallet_dir = fs::canonical(wallet_dir, error);
@@ -36,7 +39,7 @@ bool VerifyWallets(WalletContext& context)
chain.initError(strprintf(_("Specified -walletdir \"%s\" is a relative path"), wallet_dir.string()));
return false;
}
- gArgs.ForceSetArg("-walletdir", canonical_wallet_dir.string());
+ args.ForceSetArg("-walletdir", canonical_wallet_dir.string());
}
LogPrintf("Using wallet directory %s\n", GetWalletDir().string());
@@ -45,7 +48,7 @@ bool VerifyWallets(WalletContext& context)
// For backwards compatibility if an unnamed top level wallet exists in the
// wallets directory, include it in the default list of wallets to load.
- if (!gArgs.IsArgSet("wallet")) {
+ if (!args.IsArgSet("wallet")) {
DatabaseOptions options;
DatabaseStatus status;
bilingual_str error_string;
diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp
index 9fcea5826b..bc5498c88e 100644
--- a/src/wallet/test/wallet_tests.cpp
+++ b/src/wallet/test/wallet_tests.cpp
@@ -200,6 +200,7 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup)
wallet->SetupLegacyScriptPubKeyMan();
WITH_LOCK(wallet->cs_wallet, wallet->SetLastBlockProcessed(newTip->nHeight, newTip->GetBlockHash()));
WalletContext context;
+ context.args = &gArgs;
AddWallet(context, wallet);
UniValue keys;
keys.setArray();
@@ -260,6 +261,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
// Import key into wallet and call dumpwallet to create backup file.
{
WalletContext context;
+ context.args = &gArgs;
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", CreateDummyWalletDatabase());
{
auto spk_man = wallet->GetOrCreateLegacyScriptPubKeyMan();
@@ -287,6 +289,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
wallet->SetupLegacyScriptPubKeyMan();
WalletContext context;
+ context.args = &gArgs;
JSONRPCRequest request;
request.context = &context;
request.params.setArray();
@@ -685,6 +688,7 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
gArgs.ForceSetArg("-unsafesqlitesync", "1");
// Create new wallet with known key and unload it.
WalletContext context;
+ context.args = &gArgs;
context.chain = m_node.chain.get();
auto wallet = TestLoadWallet(context);
CKey key;
@@ -781,6 +785,7 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
BOOST_FIXTURE_TEST_CASE(CreateWalletWithoutChain, BasicTestingSetup)
{
WalletContext context;
+ context.args = &gArgs;
auto wallet = TestLoadWallet(context);
BOOST_CHECK(wallet);
UnloadWallet(std::move(wallet));
@@ -790,6 +795,7 @@ BOOST_FIXTURE_TEST_CASE(ZapSelectTx, TestChain100Setup)
{
gArgs.ForceSetArg("-unsafesqlitesync", "1");
WalletContext context;
+ context.args = &gArgs;
context.chain = m_node.chain.get();
auto wallet = TestLoadWallet(context);
CKey key;
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 6fcede07dc..59bdf0405a 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -2510,6 +2510,7 @@ std::unique_ptr<WalletDatabase> MakeWalletDatabase(const std::string& name, cons
std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::string& name, std::unique_ptr<WalletDatabase> database, uint64_t wallet_creation_flags, bilingual_str& error, std::vector<bilingual_str>& warnings)
{
interfaces::Chain* chain = context.chain;
+ ArgsManager& args = *Assert(context.args);
const std::string& walletFile = database->Filename();
int64_t nStart = GetTimeMillis();
@@ -2591,28 +2592,28 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
}
}
- if (!gArgs.GetArg("-addresstype", "").empty()) {
- std::optional<OutputType> parsed = ParseOutputType(gArgs.GetArg("-addresstype", ""));
+ if (!args.GetArg("-addresstype", "").empty()) {
+ std::optional<OutputType> parsed = ParseOutputType(args.GetArg("-addresstype", ""));
if (!parsed) {
- error = strprintf(_("Unknown address type '%s'"), gArgs.GetArg("-addresstype", ""));
+ error = strprintf(_("Unknown address type '%s'"), args.GetArg("-addresstype", ""));
return nullptr;
}
walletInstance->m_default_address_type = parsed.value();
}
- if (!gArgs.GetArg("-changetype", "").empty()) {
- std::optional<OutputType> parsed = ParseOutputType(gArgs.GetArg("-changetype", ""));
+ if (!args.GetArg("-changetype", "").empty()) {
+ std::optional<OutputType> parsed = ParseOutputType(args.GetArg("-changetype", ""));
if (!parsed) {
- error = strprintf(_("Unknown change type '%s'"), gArgs.GetArg("-changetype", ""));
+ error = strprintf(_("Unknown change type '%s'"), args.GetArg("-changetype", ""));
return nullptr;
}
walletInstance->m_default_change_type = parsed.value();
}
- if (gArgs.IsArgSet("-mintxfee")) {
- std::optional<CAmount> min_tx_fee = ParseMoney(gArgs.GetArg("-mintxfee", ""));
+ if (args.IsArgSet("-mintxfee")) {
+ std::optional<CAmount> min_tx_fee = ParseMoney(args.GetArg("-mintxfee", ""));
if (!min_tx_fee || min_tx_fee.value() == 0) {
- error = AmountErrMsg("mintxfee", gArgs.GetArg("-mintxfee", ""));
+ error = AmountErrMsg("mintxfee", args.GetArg("-mintxfee", ""));
return nullptr;
} else if (min_tx_fee.value() > HIGH_TX_FEE_PER_KB) {
warnings.push_back(AmountHighWarn("-mintxfee") + Untranslated(" ") +
@@ -2622,8 +2623,8 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
walletInstance->m_min_fee = CFeeRate{min_tx_fee.value()};
}
- if (gArgs.IsArgSet("-maxapsfee")) {
- const std::string max_aps_fee{gArgs.GetArg("-maxapsfee", "")};
+ if (args.IsArgSet("-maxapsfee")) {
+ const std::string max_aps_fee{args.GetArg("-maxapsfee", "")};
if (max_aps_fee == "-1") {
walletInstance->m_max_aps_fee = -1;
} else if (std::optional<CAmount> max_fee = ParseMoney(max_aps_fee)) {
@@ -2638,10 +2639,10 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
}
}
- if (gArgs.IsArgSet("-fallbackfee")) {
- std::optional<CAmount> fallback_fee = ParseMoney(gArgs.GetArg("-fallbackfee", ""));
+ if (args.IsArgSet("-fallbackfee")) {
+ std::optional<CAmount> fallback_fee = ParseMoney(args.GetArg("-fallbackfee", ""));
if (!fallback_fee) {
- error = strprintf(_("Invalid amount for -fallbackfee=<amount>: '%s'"), gArgs.GetArg("-fallbackfee", ""));
+ error = strprintf(_("Invalid amount for -fallbackfee=<amount>: '%s'"), args.GetArg("-fallbackfee", ""));
return nullptr;
} else if (fallback_fee.value() > HIGH_TX_FEE_PER_KB) {
warnings.push_back(AmountHighWarn("-fallbackfee") + Untranslated(" ") +
@@ -2653,10 +2654,10 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
// Disable fallback fee in case value was set to 0, enable if non-null value
walletInstance->m_allow_fallback_fee = walletInstance->m_fallback_fee.GetFeePerK() != 0;
- if (gArgs.IsArgSet("-discardfee")) {
- std::optional<CAmount> discard_fee = ParseMoney(gArgs.GetArg("-discardfee", ""));
+ if (args.IsArgSet("-discardfee")) {
+ std::optional<CAmount> discard_fee = ParseMoney(args.GetArg("-discardfee", ""));
if (!discard_fee) {
- error = strprintf(_("Invalid amount for -discardfee=<amount>: '%s'"), gArgs.GetArg("-discardfee", ""));
+ error = strprintf(_("Invalid amount for -discardfee=<amount>: '%s'"), args.GetArg("-discardfee", ""));
return nullptr;
} else if (discard_fee.value() > HIGH_TX_FEE_PER_KB) {
warnings.push_back(AmountHighWarn("-discardfee") + Untranslated(" ") +
@@ -2665,10 +2666,10 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
walletInstance->m_discard_rate = CFeeRate{discard_fee.value()};
}
- if (gArgs.IsArgSet("-paytxfee")) {
- std::optional<CAmount> pay_tx_fee = ParseMoney(gArgs.GetArg("-paytxfee", ""));
+ if (args.IsArgSet("-paytxfee")) {
+ std::optional<CAmount> pay_tx_fee = ParseMoney(args.GetArg("-paytxfee", ""));
if (!pay_tx_fee) {
- error = AmountErrMsg("paytxfee", gArgs.GetArg("-paytxfee", ""));
+ error = AmountErrMsg("paytxfee", args.GetArg("-paytxfee", ""));
return nullptr;
} else if (pay_tx_fee.value() > HIGH_TX_FEE_PER_KB) {
warnings.push_back(AmountHighWarn("-paytxfee") + Untranslated(" ") +
@@ -2679,15 +2680,15 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
if (chain && walletInstance->m_pay_tx_fee < chain->relayMinFee()) {
error = strprintf(_("Invalid amount for -paytxfee=<amount>: '%s' (must be at least %s)"),
- gArgs.GetArg("-paytxfee", ""), chain->relayMinFee().ToString());
+ args.GetArg("-paytxfee", ""), chain->relayMinFee().ToString());
return nullptr;
}
}
- if (gArgs.IsArgSet("-maxtxfee")) {
- std::optional<CAmount> max_fee = ParseMoney(gArgs.GetArg("-maxtxfee", ""));
+ if (args.IsArgSet("-maxtxfee")) {
+ std::optional<CAmount> max_fee = ParseMoney(args.GetArg("-maxtxfee", ""));
if (!max_fee) {
- error = AmountErrMsg("maxtxfee", gArgs.GetArg("-maxtxfee", ""));
+ error = AmountErrMsg("maxtxfee", args.GetArg("-maxtxfee", ""));
return nullptr;
} else if (max_fee.value() > HIGH_MAX_TX_FEE) {
warnings.push_back(_("-maxtxfee is set very high! Fees this large could be paid on a single transaction."));
@@ -2695,7 +2696,7 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
if (chain && CFeeRate{max_fee.value(), 1000} < chain->relayMinFee()) {
error = strprintf(_("Invalid amount for -maxtxfee=<amount>: '%s' (must be at least the minrelay fee of %s to prevent stuck transactions)"),
- gArgs.GetArg("-maxtxfee", ""), chain->relayMinFee().ToString());
+ args.GetArg("-maxtxfee", ""), chain->relayMinFee().ToString());
return nullptr;
}
@@ -2707,9 +2708,9 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
_("The wallet will avoid paying less than the minimum relay fee."));
}
- walletInstance->m_confirm_target = gArgs.GetArg("-txconfirmtarget", DEFAULT_TX_CONFIRM_TARGET);
- walletInstance->m_spend_zero_conf_change = gArgs.GetBoolArg("-spendzeroconfchange", DEFAULT_SPEND_ZEROCONF_CHANGE);
- walletInstance->m_signal_rbf = gArgs.GetBoolArg("-walletrbf", DEFAULT_WALLET_RBF);
+ walletInstance->m_confirm_target = args.GetArg("-txconfirmtarget", DEFAULT_TX_CONFIRM_TARGET);
+ walletInstance->m_spend_zero_conf_change = args.GetBoolArg("-spendzeroconfchange", DEFAULT_SPEND_ZEROCONF_CHANGE);
+ walletInstance->m_signal_rbf = args.GetBoolArg("-walletrbf", DEFAULT_WALLET_RBF);
walletInstance->WalletLogPrintf("Wallet completed loading in %15dms\n", GetTimeMillis() - nStart);
@@ -2729,7 +2730,7 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
}
}
- walletInstance->SetBroadcastTransactions(gArgs.GetBoolArg("-walletbroadcast", DEFAULT_WALLETBROADCAST));
+ walletInstance->SetBroadcastTransactions(args.GetBoolArg("-walletbroadcast", DEFAULT_WALLETBROADCAST));
{
walletInstance->WalletLogPrintf("setKeyPool.size() = %u\n", walletInstance->GetKeyPoolSize());