From 2e1fa5786d0b28983abb9f2042da1d4783f548de Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Wed, 14 Jan 2026 17:40:07 +0100 Subject: [PATCH] Add regtest option * Add `regtest` option to `monero_wallet_config` * Allow mismatched daemon hard fork version for regtest `monero_wallet_full` * Setup block reorg tolerance for regtest `monero_wallet_full` --- src/wallet/monero_wallet_full.cpp | 13 +++++++++++++ src/wallet/monero_wallet_model.cpp | 3 +++ src/wallet/monero_wallet_model.h | 1 + 3 files changed, 17 insertions(+) diff --git a/src/wallet/monero_wallet_full.cpp b/src/wallet/monero_wallet_full.cpp index feeb055a..bd03b431 100644 --- a/src/wallet/monero_wallet_full.cpp +++ b/src/wallet/monero_wallet_full.cpp @@ -1100,6 +1100,7 @@ namespace monero { if (config_normalized.m_language.get().empty()) config_normalized.m_language = std::string("English"); if (!monero_utils::is_valid_language(config_normalized.m_language.get())) throw std::runtime_error("Unknown language: " + config_normalized.m_language.get()); if (config.m_network_type == boost::none) throw std::runtime_error("Must provide wallet network type"); + if (config.m_regtest != boost::none && *config.m_regtest == true && *config.m_network_type != monero_network_type::MAINNET) throw std::runtime_error("Network type must be mainnet when using regtest option"); // create wallet if (!config_normalized.m_seed.get().empty()) { @@ -1137,6 +1138,10 @@ namespace monero { if (http_client_factory == nullptr) wallet->m_w2 = std::unique_ptr(new tools::wallet2(static_cast(config.m_network_type.get()), 1, true)); else wallet->m_w2 = std::unique_ptr(new tools::wallet2(static_cast(config.m_network_type.get()), 1, true, std::move(http_client_factory))); wallet->m_w2->init(""); + if (config.m_regtest != boost::none && config.m_regtest.get() == true) { + wallet->m_w2->allow_mismatched_daemon_version(true); + wallet->m_w2->max_reorg_depth(100000); + } wallet->set_daemon_connection(config.m_server); wallet->m_w2->set_seed_language(language); if (config.m_account_lookahead != boost::none) wallet->m_w2->set_subaddress_lookahead(config.m_account_lookahead.get(), config.m_subaddress_lookahead.get()); @@ -1232,6 +1237,10 @@ namespace monero { else if (has_spend_key) wallet->m_w2->generate(config.m_path.get(), config.m_password.get(), spend_key_sk, true, false); else wallet->m_w2->generate(config.m_path.get(), config.m_password.get(), address_info.address, view_key_sk); wallet->m_w2->init(""); + if (config.m_regtest != boost::none && config.m_regtest.get() == true) { + wallet->m_w2->allow_mismatched_daemon_version(true); + wallet->m_w2->max_reorg_depth(100000); + } wallet->set_daemon_connection(config.m_server); wallet->m_w2->set_refresh_from_block_height(config.m_restore_height.get()); wallet->m_w2->set_seed_language(config.m_language.get()); @@ -1251,6 +1260,10 @@ namespace monero { if (http_client_factory == nullptr) wallet->m_w2 = std::unique_ptr(new tools::wallet2(static_cast(config.m_network_type.get()), 1, true)); else wallet->m_w2 = std::unique_ptr(new tools::wallet2(static_cast(config.m_network_type.get()), 1, true, std::move(http_client_factory))); wallet->m_w2->init(""); + if (config.m_regtest != boost::none && config.m_regtest.get() == true) { + wallet->m_w2->allow_mismatched_daemon_version(true); + wallet->m_w2->max_reorg_depth(100000); + } wallet->set_daemon_connection(config.m_server); wallet->m_w2->set_seed_language(config.m_language.get()); crypto::secret_key secret_key; diff --git a/src/wallet/monero_wallet_model.cpp b/src/wallet/monero_wallet_model.cpp index 6aadd378..2ffa4d85 100644 --- a/src/wallet/monero_wallet_model.cpp +++ b/src/wallet/monero_wallet_model.cpp @@ -108,6 +108,7 @@ namespace monero { m_account_lookahead = config.m_account_lookahead; m_subaddress_lookahead = config.m_subaddress_lookahead; m_is_multisig = config.m_is_multisig; + m_regtest = config.m_regtest; } monero_wallet_config monero_wallet_config::copy() const { @@ -145,6 +146,7 @@ namespace monero { // set bool values if (m_save_current != boost::none) monero_utils::add_json_member("saveCurrent", m_save_current.get(), allocator, root); if (m_is_multisig != boost::none) monero_utils::add_json_member("isMultisig", m_is_multisig.get(), allocator, root); + if (m_regtest != boost::none) monero_utils::add_json_member("regtest", m_regtest.get(), allocator, root); // return root return root; @@ -182,6 +184,7 @@ namespace monero { else if (key == std::string("accountLookahead")) config->m_account_lookahead = it->second.get_value(); else if (key == std::string("subaddressLookahead")) config->m_subaddress_lookahead = it->second.get_value(); else if (key == std::string("isMultisig")) config->m_is_multisig = it->second.get_value(); + else if (key == std::string("regtest")) config->m_regtest = it->second.get_value(); } return config; diff --git a/src/wallet/monero_wallet_model.h b/src/wallet/monero_wallet_model.h index c15aa0c2..5ee66e6e 100644 --- a/src/wallet/monero_wallet_model.h +++ b/src/wallet/monero_wallet_model.h @@ -80,6 +80,7 @@ namespace monero { boost::optional m_account_lookahead; boost::optional m_subaddress_lookahead; boost::optional m_is_multisig; + boost::optional m_regtest; monero_wallet_config() {} monero_wallet_config(const monero_wallet_config& config);