mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-06 14:19:59 -05:00
Use context.args
in CWallet::Create
instead of gArgs
.
This commit is contained in:
parent
aa5e7c9471
commit
25de4e77fe
2 changed files with 36 additions and 29 deletions
|
@ -200,6 +200,7 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup)
|
||||||
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;
|
||||||
|
context.args = &gArgs;
|
||||||
AddWallet(context, wallet);
|
AddWallet(context, wallet);
|
||||||
UniValue keys;
|
UniValue keys;
|
||||||
keys.setArray();
|
keys.setArray();
|
||||||
|
@ -260,6 +261,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
|
||||||
// Import key into wallet and call dumpwallet to create backup file.
|
// Import key into wallet and call dumpwallet to create backup file.
|
||||||
{
|
{
|
||||||
WalletContext context;
|
WalletContext context;
|
||||||
|
context.args = &gArgs;
|
||||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", CreateDummyWalletDatabase());
|
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", CreateDummyWalletDatabase());
|
||||||
{
|
{
|
||||||
auto spk_man = wallet->GetOrCreateLegacyScriptPubKeyMan();
|
auto spk_man = wallet->GetOrCreateLegacyScriptPubKeyMan();
|
||||||
|
@ -287,6 +289,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
|
||||||
wallet->SetupLegacyScriptPubKeyMan();
|
wallet->SetupLegacyScriptPubKeyMan();
|
||||||
|
|
||||||
WalletContext context;
|
WalletContext context;
|
||||||
|
context.args = &gArgs;
|
||||||
JSONRPCRequest request;
|
JSONRPCRequest request;
|
||||||
request.context = &context;
|
request.context = &context;
|
||||||
request.params.setArray();
|
request.params.setArray();
|
||||||
|
@ -685,6 +688,7 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
|
||||||
gArgs.ForceSetArg("-unsafesqlitesync", "1");
|
gArgs.ForceSetArg("-unsafesqlitesync", "1");
|
||||||
// Create new wallet with known key and unload it.
|
// Create new wallet with known key and unload it.
|
||||||
WalletContext context;
|
WalletContext context;
|
||||||
|
context.args = &gArgs;
|
||||||
context.chain = m_node.chain.get();
|
context.chain = m_node.chain.get();
|
||||||
auto wallet = TestLoadWallet(context);
|
auto wallet = TestLoadWallet(context);
|
||||||
CKey key;
|
CKey key;
|
||||||
|
@ -781,6 +785,7 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
|
||||||
BOOST_FIXTURE_TEST_CASE(CreateWalletWithoutChain, BasicTestingSetup)
|
BOOST_FIXTURE_TEST_CASE(CreateWalletWithoutChain, BasicTestingSetup)
|
||||||
{
|
{
|
||||||
WalletContext context;
|
WalletContext context;
|
||||||
|
context.args = &gArgs;
|
||||||
auto wallet = TestLoadWallet(context);
|
auto wallet = TestLoadWallet(context);
|
||||||
BOOST_CHECK(wallet);
|
BOOST_CHECK(wallet);
|
||||||
UnloadWallet(std::move(wallet));
|
UnloadWallet(std::move(wallet));
|
||||||
|
@ -790,6 +795,7 @@ BOOST_FIXTURE_TEST_CASE(ZapSelectTx, TestChain100Setup)
|
||||||
{
|
{
|
||||||
gArgs.ForceSetArg("-unsafesqlitesync", "1");
|
gArgs.ForceSetArg("-unsafesqlitesync", "1");
|
||||||
WalletContext context;
|
WalletContext context;
|
||||||
|
context.args = &gArgs;
|
||||||
context.chain = m_node.chain.get();
|
context.chain = m_node.chain.get();
|
||||||
auto wallet = TestLoadWallet(context);
|
auto wallet = TestLoadWallet(context);
|
||||||
CKey key;
|
CKey key;
|
||||||
|
|
|
@ -2509,6 +2509,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)
|
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;
|
interfaces::Chain* chain = context.chain;
|
||||||
|
ArgsManager& args = *Assert(context.args);
|
||||||
const std::string& walletFile = database->Filename();
|
const std::string& walletFile = database->Filename();
|
||||||
|
|
||||||
int64_t nStart = GetTimeMillis();
|
int64_t nStart = GetTimeMillis();
|
||||||
|
@ -2590,28 +2591,28 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gArgs.GetArg("-addresstype", "").empty()) {
|
if (!args.GetArg("-addresstype", "").empty()) {
|
||||||
std::optional<OutputType> parsed = ParseOutputType(gArgs.GetArg("-addresstype", ""));
|
std::optional<OutputType> parsed = ParseOutputType(args.GetArg("-addresstype", ""));
|
||||||
if (!parsed) {
|
if (!parsed) {
|
||||||
error = strprintf(_("Unknown address type '%s'"), gArgs.GetArg("-addresstype", ""));
|
error = strprintf(_("Unknown address type '%s'"), args.GetArg("-addresstype", ""));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
walletInstance->m_default_address_type = parsed.value();
|
walletInstance->m_default_address_type = parsed.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gArgs.GetArg("-changetype", "").empty()) {
|
if (!args.GetArg("-changetype", "").empty()) {
|
||||||
std::optional<OutputType> parsed = ParseOutputType(gArgs.GetArg("-changetype", ""));
|
std::optional<OutputType> parsed = ParseOutputType(args.GetArg("-changetype", ""));
|
||||||
if (!parsed) {
|
if (!parsed) {
|
||||||
error = strprintf(_("Unknown change type '%s'"), gArgs.GetArg("-changetype", ""));
|
error = strprintf(_("Unknown change type '%s'"), args.GetArg("-changetype", ""));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
walletInstance->m_default_change_type = parsed.value();
|
walletInstance->m_default_change_type = parsed.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gArgs.IsArgSet("-mintxfee")) {
|
if (args.IsArgSet("-mintxfee")) {
|
||||||
std::optional<CAmount> min_tx_fee = ParseMoney(gArgs.GetArg("-mintxfee", ""));
|
std::optional<CAmount> min_tx_fee = ParseMoney(args.GetArg("-mintxfee", ""));
|
||||||
if (!min_tx_fee || min_tx_fee.value() == 0) {
|
if (!min_tx_fee || min_tx_fee.value() == 0) {
|
||||||
error = AmountErrMsg("mintxfee", gArgs.GetArg("-mintxfee", ""));
|
error = AmountErrMsg("mintxfee", args.GetArg("-mintxfee", ""));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
} else if (min_tx_fee.value() > HIGH_TX_FEE_PER_KB) {
|
} else if (min_tx_fee.value() > HIGH_TX_FEE_PER_KB) {
|
||||||
warnings.push_back(AmountHighWarn("-mintxfee") + Untranslated(" ") +
|
warnings.push_back(AmountHighWarn("-mintxfee") + Untranslated(" ") +
|
||||||
|
@ -2621,8 +2622,8 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
|
||||||
walletInstance->m_min_fee = CFeeRate{min_tx_fee.value()};
|
walletInstance->m_min_fee = CFeeRate{min_tx_fee.value()};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gArgs.IsArgSet("-maxapsfee")) {
|
if (args.IsArgSet("-maxapsfee")) {
|
||||||
const std::string max_aps_fee{gArgs.GetArg("-maxapsfee", "")};
|
const std::string max_aps_fee{args.GetArg("-maxapsfee", "")};
|
||||||
if (max_aps_fee == "-1") {
|
if (max_aps_fee == "-1") {
|
||||||
walletInstance->m_max_aps_fee = -1;
|
walletInstance->m_max_aps_fee = -1;
|
||||||
} else if (std::optional<CAmount> max_fee = ParseMoney(max_aps_fee)) {
|
} 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gArgs.IsArgSet("-fallbackfee")) {
|
if (args.IsArgSet("-fallbackfee")) {
|
||||||
std::optional<CAmount> fallback_fee = ParseMoney(gArgs.GetArg("-fallbackfee", ""));
|
std::optional<CAmount> fallback_fee = ParseMoney(args.GetArg("-fallbackfee", ""));
|
||||||
if (!fallback_fee) {
|
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;
|
return nullptr;
|
||||||
} else if (fallback_fee.value() > HIGH_TX_FEE_PER_KB) {
|
} else if (fallback_fee.value() > HIGH_TX_FEE_PER_KB) {
|
||||||
warnings.push_back(AmountHighWarn("-fallbackfee") + Untranslated(" ") +
|
warnings.push_back(AmountHighWarn("-fallbackfee") + Untranslated(" ") +
|
||||||
|
@ -2652,10 +2653,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
|
// 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;
|
walletInstance->m_allow_fallback_fee = walletInstance->m_fallback_fee.GetFeePerK() != 0;
|
||||||
|
|
||||||
if (gArgs.IsArgSet("-discardfee")) {
|
if (args.IsArgSet("-discardfee")) {
|
||||||
std::optional<CAmount> discard_fee = ParseMoney(gArgs.GetArg("-discardfee", ""));
|
std::optional<CAmount> discard_fee = ParseMoney(args.GetArg("-discardfee", ""));
|
||||||
if (!discard_fee) {
|
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;
|
return nullptr;
|
||||||
} else if (discard_fee.value() > HIGH_TX_FEE_PER_KB) {
|
} else if (discard_fee.value() > HIGH_TX_FEE_PER_KB) {
|
||||||
warnings.push_back(AmountHighWarn("-discardfee") + Untranslated(" ") +
|
warnings.push_back(AmountHighWarn("-discardfee") + Untranslated(" ") +
|
||||||
|
@ -2664,10 +2665,10 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
|
||||||
walletInstance->m_discard_rate = CFeeRate{discard_fee.value()};
|
walletInstance->m_discard_rate = CFeeRate{discard_fee.value()};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gArgs.IsArgSet("-paytxfee")) {
|
if (args.IsArgSet("-paytxfee")) {
|
||||||
std::optional<CAmount> pay_tx_fee = ParseMoney(gArgs.GetArg("-paytxfee", ""));
|
std::optional<CAmount> pay_tx_fee = ParseMoney(args.GetArg("-paytxfee", ""));
|
||||||
if (!pay_tx_fee) {
|
if (!pay_tx_fee) {
|
||||||
error = AmountErrMsg("paytxfee", gArgs.GetArg("-paytxfee", ""));
|
error = AmountErrMsg("paytxfee", args.GetArg("-paytxfee", ""));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
} else if (pay_tx_fee.value() > HIGH_TX_FEE_PER_KB) {
|
} else if (pay_tx_fee.value() > HIGH_TX_FEE_PER_KB) {
|
||||||
warnings.push_back(AmountHighWarn("-paytxfee") + Untranslated(" ") +
|
warnings.push_back(AmountHighWarn("-paytxfee") + Untranslated(" ") +
|
||||||
|
@ -2678,15 +2679,15 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
|
||||||
|
|
||||||
if (chain && walletInstance->m_pay_tx_fee < chain->relayMinFee()) {
|
if (chain && walletInstance->m_pay_tx_fee < chain->relayMinFee()) {
|
||||||
error = strprintf(_("Invalid amount for -paytxfee=<amount>: '%s' (must be at least %s)"),
|
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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gArgs.IsArgSet("-maxtxfee")) {
|
if (args.IsArgSet("-maxtxfee")) {
|
||||||
std::optional<CAmount> max_fee = ParseMoney(gArgs.GetArg("-maxtxfee", ""));
|
std::optional<CAmount> max_fee = ParseMoney(args.GetArg("-maxtxfee", ""));
|
||||||
if (!max_fee) {
|
if (!max_fee) {
|
||||||
error = AmountErrMsg("maxtxfee", gArgs.GetArg("-maxtxfee", ""));
|
error = AmountErrMsg("maxtxfee", args.GetArg("-maxtxfee", ""));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
} else if (max_fee.value() > HIGH_MAX_TX_FEE) {
|
} 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."));
|
warnings.push_back(_("-maxtxfee is set very high! Fees this large could be paid on a single transaction."));
|
||||||
|
@ -2694,7 +2695,7 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
|
||||||
|
|
||||||
if (chain && CFeeRate{max_fee.value(), 1000} < chain->relayMinFee()) {
|
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)"),
|
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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2706,9 +2707,9 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
|
||||||
_("The wallet will avoid paying less than the minimum relay fee."));
|
_("The wallet will avoid paying less than the minimum relay fee."));
|
||||||
}
|
}
|
||||||
|
|
||||||
walletInstance->m_confirm_target = gArgs.GetArg("-txconfirmtarget", DEFAULT_TX_CONFIRM_TARGET);
|
walletInstance->m_confirm_target = args.GetArg("-txconfirmtarget", DEFAULT_TX_CONFIRM_TARGET);
|
||||||
walletInstance->m_spend_zero_conf_change = gArgs.GetBoolArg("-spendzeroconfchange", DEFAULT_SPEND_ZEROCONF_CHANGE);
|
walletInstance->m_spend_zero_conf_change = args.GetBoolArg("-spendzeroconfchange", DEFAULT_SPEND_ZEROCONF_CHANGE);
|
||||||
walletInstance->m_signal_rbf = gArgs.GetBoolArg("-walletrbf", DEFAULT_WALLET_RBF);
|
walletInstance->m_signal_rbf = args.GetBoolArg("-walletrbf", DEFAULT_WALLET_RBF);
|
||||||
|
|
||||||
walletInstance->WalletLogPrintf("Wallet completed loading in %15dms\n", GetTimeMillis() - nStart);
|
walletInstance->WalletLogPrintf("Wallet completed loading in %15dms\n", GetTimeMillis() - nStart);
|
||||||
|
|
||||||
|
@ -2728,7 +2729,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());
|
walletInstance->WalletLogPrintf("setKeyPool.size() = %u\n", walletInstance->GetKeyPoolSize());
|
||||||
|
|
Loading…
Add table
Reference in a new issue