Skip to content

Commit 25de4e7

Browse files
committed
Use context.args in CWallet::Create instead of gArgs.
1 parent aa5e7c9 commit 25de4e7

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

src/wallet/test/wallet_tests.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup)
200200
wallet->SetupLegacyScriptPubKeyMan();
201201
WITH_LOCK(wallet->cs_wallet, wallet->SetLastBlockProcessed(newTip->nHeight, newTip->GetBlockHash()));
202202
WalletContext context;
203+
context.args = &gArgs;
203204
AddWallet(context, wallet);
204205
UniValue keys;
205206
keys.setArray();
@@ -260,6 +261,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
260261
// Import key into wallet and call dumpwallet to create backup file.
261262
{
262263
WalletContext context;
264+
context.args = &gArgs;
263265
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", CreateDummyWalletDatabase());
264266
{
265267
auto spk_man = wallet->GetOrCreateLegacyScriptPubKeyMan();
@@ -287,6 +289,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
287289
wallet->SetupLegacyScriptPubKeyMan();
288290

289291
WalletContext context;
292+
context.args = &gArgs;
290293
JSONRPCRequest request;
291294
request.context = &context;
292295
request.params.setArray();
@@ -685,6 +688,7 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
685688
gArgs.ForceSetArg("-unsafesqlitesync", "1");
686689
// Create new wallet with known key and unload it.
687690
WalletContext context;
691+
context.args = &gArgs;
688692
context.chain = m_node.chain.get();
689693
auto wallet = TestLoadWallet(context);
690694
CKey key;
@@ -781,6 +785,7 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
781785
BOOST_FIXTURE_TEST_CASE(CreateWalletWithoutChain, BasicTestingSetup)
782786
{
783787
WalletContext context;
788+
context.args = &gArgs;
784789
auto wallet = TestLoadWallet(context);
785790
BOOST_CHECK(wallet);
786791
UnloadWallet(std::move(wallet));
@@ -790,6 +795,7 @@ BOOST_FIXTURE_TEST_CASE(ZapSelectTx, TestChain100Setup)
790795
{
791796
gArgs.ForceSetArg("-unsafesqlitesync", "1");
792797
WalletContext context;
798+
context.args = &gArgs;
793799
context.chain = m_node.chain.get();
794800
auto wallet = TestLoadWallet(context);
795801
CKey key;

src/wallet/wallet.cpp

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,6 +2509,7 @@ std::unique_ptr<WalletDatabase> MakeWalletDatabase(const std::string& name, cons
25092509
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)
25102510
{
25112511
interfaces::Chain* chain = context.chain;
2512+
ArgsManager& args = *Assert(context.args);
25122513
const std::string& walletFile = database->Filename();
25132514

25142515
int64_t nStart = GetTimeMillis();
@@ -2590,28 +2591,28 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
25902591
}
25912592
}
25922593

2593-
if (!gArgs.GetArg("-addresstype", "").empty()) {
2594-
std::optional<OutputType> parsed = ParseOutputType(gArgs.GetArg("-addresstype", ""));
2594+
if (!args.GetArg("-addresstype", "").empty()) {
2595+
std::optional<OutputType> parsed = ParseOutputType(args.GetArg("-addresstype", ""));
25952596
if (!parsed) {
2596-
error = strprintf(_("Unknown address type '%s'"), gArgs.GetArg("-addresstype", ""));
2597+
error = strprintf(_("Unknown address type '%s'"), args.GetArg("-addresstype", ""));
25972598
return nullptr;
25982599
}
25992600
walletInstance->m_default_address_type = parsed.value();
26002601
}
26012602

2602-
if (!gArgs.GetArg("-changetype", "").empty()) {
2603-
std::optional<OutputType> parsed = ParseOutputType(gArgs.GetArg("-changetype", ""));
2603+
if (!args.GetArg("-changetype", "").empty()) {
2604+
std::optional<OutputType> parsed = ParseOutputType(args.GetArg("-changetype", ""));
26042605
if (!parsed) {
2605-
error = strprintf(_("Unknown change type '%s'"), gArgs.GetArg("-changetype", ""));
2606+
error = strprintf(_("Unknown change type '%s'"), args.GetArg("-changetype", ""));
26062607
return nullptr;
26072608
}
26082609
walletInstance->m_default_change_type = parsed.value();
26092610
}
26102611

2611-
if (gArgs.IsArgSet("-mintxfee")) {
2612-
std::optional<CAmount> min_tx_fee = ParseMoney(gArgs.GetArg("-mintxfee", ""));
2612+
if (args.IsArgSet("-mintxfee")) {
2613+
std::optional<CAmount> min_tx_fee = ParseMoney(args.GetArg("-mintxfee", ""));
26132614
if (!min_tx_fee || min_tx_fee.value() == 0) {
2614-
error = AmountErrMsg("mintxfee", gArgs.GetArg("-mintxfee", ""));
2615+
error = AmountErrMsg("mintxfee", args.GetArg("-mintxfee", ""));
26152616
return nullptr;
26162617
} else if (min_tx_fee.value() > HIGH_TX_FEE_PER_KB) {
26172618
warnings.push_back(AmountHighWarn("-mintxfee") + Untranslated(" ") +
@@ -2621,8 +2622,8 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
26212622
walletInstance->m_min_fee = CFeeRate{min_tx_fee.value()};
26222623
}
26232624

2624-
if (gArgs.IsArgSet("-maxapsfee")) {
2625-
const std::string max_aps_fee{gArgs.GetArg("-maxapsfee", "")};
2625+
if (args.IsArgSet("-maxapsfee")) {
2626+
const std::string max_aps_fee{args.GetArg("-maxapsfee", "")};
26262627
if (max_aps_fee == "-1") {
26272628
walletInstance->m_max_aps_fee = -1;
26282629
} else if (std::optional<CAmount> max_fee = ParseMoney(max_aps_fee)) {
@@ -2637,10 +2638,10 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
26372638
}
26382639
}
26392640

2640-
if (gArgs.IsArgSet("-fallbackfee")) {
2641-
std::optional<CAmount> fallback_fee = ParseMoney(gArgs.GetArg("-fallbackfee", ""));
2641+
if (args.IsArgSet("-fallbackfee")) {
2642+
std::optional<CAmount> fallback_fee = ParseMoney(args.GetArg("-fallbackfee", ""));
26422643
if (!fallback_fee) {
2643-
error = strprintf(_("Invalid amount for -fallbackfee=<amount>: '%s'"), gArgs.GetArg("-fallbackfee", ""));
2644+
error = strprintf(_("Invalid amount for -fallbackfee=<amount>: '%s'"), args.GetArg("-fallbackfee", ""));
26442645
return nullptr;
26452646
} else if (fallback_fee.value() > HIGH_TX_FEE_PER_KB) {
26462647
warnings.push_back(AmountHighWarn("-fallbackfee") + Untranslated(" ") +
@@ -2652,10 +2653,10 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
26522653
// Disable fallback fee in case value was set to 0, enable if non-null value
26532654
walletInstance->m_allow_fallback_fee = walletInstance->m_fallback_fee.GetFeePerK() != 0;
26542655

2655-
if (gArgs.IsArgSet("-discardfee")) {
2656-
std::optional<CAmount> discard_fee = ParseMoney(gArgs.GetArg("-discardfee", ""));
2656+
if (args.IsArgSet("-discardfee")) {
2657+
std::optional<CAmount> discard_fee = ParseMoney(args.GetArg("-discardfee", ""));
26572658
if (!discard_fee) {
2658-
error = strprintf(_("Invalid amount for -discardfee=<amount>: '%s'"), gArgs.GetArg("-discardfee", ""));
2659+
error = strprintf(_("Invalid amount for -discardfee=<amount>: '%s'"), args.GetArg("-discardfee", ""));
26592660
return nullptr;
26602661
} else if (discard_fee.value() > HIGH_TX_FEE_PER_KB) {
26612662
warnings.push_back(AmountHighWarn("-discardfee") + Untranslated(" ") +
@@ -2664,10 +2665,10 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
26642665
walletInstance->m_discard_rate = CFeeRate{discard_fee.value()};
26652666
}
26662667

2667-
if (gArgs.IsArgSet("-paytxfee")) {
2668-
std::optional<CAmount> pay_tx_fee = ParseMoney(gArgs.GetArg("-paytxfee", ""));
2668+
if (args.IsArgSet("-paytxfee")) {
2669+
std::optional<CAmount> pay_tx_fee = ParseMoney(args.GetArg("-paytxfee", ""));
26692670
if (!pay_tx_fee) {
2670-
error = AmountErrMsg("paytxfee", gArgs.GetArg("-paytxfee", ""));
2671+
error = AmountErrMsg("paytxfee", args.GetArg("-paytxfee", ""));
26712672
return nullptr;
26722673
} else if (pay_tx_fee.value() > HIGH_TX_FEE_PER_KB) {
26732674
warnings.push_back(AmountHighWarn("-paytxfee") + Untranslated(" ") +
@@ -2678,23 +2679,23 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
26782679

26792680
if (chain && walletInstance->m_pay_tx_fee < chain->relayMinFee()) {
26802681
error = strprintf(_("Invalid amount for -paytxfee=<amount>: '%s' (must be at least %s)"),
2681-
gArgs.GetArg("-paytxfee", ""), chain->relayMinFee().ToString());
2682+
args.GetArg("-paytxfee", ""), chain->relayMinFee().ToString());
26822683
return nullptr;
26832684
}
26842685
}
26852686

2686-
if (gArgs.IsArgSet("-maxtxfee")) {
2687-
std::optional<CAmount> max_fee = ParseMoney(gArgs.GetArg("-maxtxfee", ""));
2687+
if (args.IsArgSet("-maxtxfee")) {
2688+
std::optional<CAmount> max_fee = ParseMoney(args.GetArg("-maxtxfee", ""));
26882689
if (!max_fee) {
2689-
error = AmountErrMsg("maxtxfee", gArgs.GetArg("-maxtxfee", ""));
2690+
error = AmountErrMsg("maxtxfee", args.GetArg("-maxtxfee", ""));
26902691
return nullptr;
26912692
} else if (max_fee.value() > HIGH_MAX_TX_FEE) {
26922693
warnings.push_back(_("-maxtxfee is set very high! Fees this large could be paid on a single transaction."));
26932694
}
26942695

26952696
if (chain && CFeeRate{max_fee.value(), 1000} < chain->relayMinFee()) {
26962697
error = strprintf(_("Invalid amount for -maxtxfee=<amount>: '%s' (must be at least the minrelay fee of %s to prevent stuck transactions)"),
2697-
gArgs.GetArg("-maxtxfee", ""), chain->relayMinFee().ToString());
2698+
args.GetArg("-maxtxfee", ""), chain->relayMinFee().ToString());
26982699
return nullptr;
26992700
}
27002701

@@ -2706,9 +2707,9 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
27062707
_("The wallet will avoid paying less than the minimum relay fee."));
27072708
}
27082709

2709-
walletInstance->m_confirm_target = gArgs.GetArg("-txconfirmtarget", DEFAULT_TX_CONFIRM_TARGET);
2710-
walletInstance->m_spend_zero_conf_change = gArgs.GetBoolArg("-spendzeroconfchange", DEFAULT_SPEND_ZEROCONF_CHANGE);
2711-
walletInstance->m_signal_rbf = gArgs.GetBoolArg("-walletrbf", DEFAULT_WALLET_RBF);
2710+
walletInstance->m_confirm_target = args.GetArg("-txconfirmtarget", DEFAULT_TX_CONFIRM_TARGET);
2711+
walletInstance->m_spend_zero_conf_change = args.GetBoolArg("-spendzeroconfchange", DEFAULT_SPEND_ZEROCONF_CHANGE);
2712+
walletInstance->m_signal_rbf = args.GetBoolArg("-walletrbf", DEFAULT_WALLET_RBF);
27122713

27132714
walletInstance->WalletLogPrintf("Wallet completed loading in %15dms\n", GetTimeMillis() - nStart);
27142715

@@ -2728,7 +2729,7 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
27282729
}
27292730
}
27302731

2731-
walletInstance->SetBroadcastTransactions(gArgs.GetBoolArg("-walletbroadcast", DEFAULT_WALLETBROADCAST));
2732+
walletInstance->SetBroadcastTransactions(args.GetBoolArg("-walletbroadcast", DEFAULT_WALLETBROADCAST));
27322733

27332734
{
27342735
walletInstance->WalletLogPrintf("setKeyPool.size() = %u\n", walletInstance->GetKeyPoolSize());

0 commit comments

Comments
 (0)