Skip to content

Commit 2e1fa57

Browse files
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`
1 parent 32c1b75 commit 2e1fa57

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/wallet/monero_wallet_full.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,7 @@ namespace monero {
11001100
if (config_normalized.m_language.get().empty()) config_normalized.m_language = std::string("English");
11011101
if (!monero_utils::is_valid_language(config_normalized.m_language.get())) throw std::runtime_error("Unknown language: " + config_normalized.m_language.get());
11021102
if (config.m_network_type == boost::none) throw std::runtime_error("Must provide wallet network type");
1103+
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");
11031104

11041105
// create wallet
11051106
if (!config_normalized.m_seed.get().empty()) {
@@ -1137,6 +1138,10 @@ namespace monero {
11371138
if (http_client_factory == nullptr) wallet->m_w2 = std::unique_ptr<tools::wallet2>(new tools::wallet2(static_cast<cryptonote::network_type>(config.m_network_type.get()), 1, true));
11381139
else wallet->m_w2 = std::unique_ptr<tools::wallet2>(new tools::wallet2(static_cast<cryptonote::network_type>(config.m_network_type.get()), 1, true, std::move(http_client_factory)));
11391140
wallet->m_w2->init("");
1141+
if (config.m_regtest != boost::none && config.m_regtest.get() == true) {
1142+
wallet->m_w2->allow_mismatched_daemon_version(true);
1143+
wallet->m_w2->max_reorg_depth(100000);
1144+
}
11401145
wallet->set_daemon_connection(config.m_server);
11411146
wallet->m_w2->set_seed_language(language);
11421147
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 {
12321237
else if (has_spend_key) wallet->m_w2->generate(config.m_path.get(), config.m_password.get(), spend_key_sk, true, false);
12331238
else wallet->m_w2->generate(config.m_path.get(), config.m_password.get(), address_info.address, view_key_sk);
12341239
wallet->m_w2->init("");
1240+
if (config.m_regtest != boost::none && config.m_regtest.get() == true) {
1241+
wallet->m_w2->allow_mismatched_daemon_version(true);
1242+
wallet->m_w2->max_reorg_depth(100000);
1243+
}
12351244
wallet->set_daemon_connection(config.m_server);
12361245
wallet->m_w2->set_refresh_from_block_height(config.m_restore_height.get());
12371246
wallet->m_w2->set_seed_language(config.m_language.get());
@@ -1251,6 +1260,10 @@ namespace monero {
12511260
if (http_client_factory == nullptr) wallet->m_w2 = std::unique_ptr<tools::wallet2>(new tools::wallet2(static_cast<cryptonote::network_type>(config.m_network_type.get()), 1, true));
12521261
else wallet->m_w2 = std::unique_ptr<tools::wallet2>(new tools::wallet2(static_cast<cryptonote::network_type>(config.m_network_type.get()), 1, true, std::move(http_client_factory)));
12531262
wallet->m_w2->init("");
1263+
if (config.m_regtest != boost::none && config.m_regtest.get() == true) {
1264+
wallet->m_w2->allow_mismatched_daemon_version(true);
1265+
wallet->m_w2->max_reorg_depth(100000);
1266+
}
12541267
wallet->set_daemon_connection(config.m_server);
12551268
wallet->m_w2->set_seed_language(config.m_language.get());
12561269
crypto::secret_key secret_key;

src/wallet/monero_wallet_model.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ namespace monero {
108108
m_account_lookahead = config.m_account_lookahead;
109109
m_subaddress_lookahead = config.m_subaddress_lookahead;
110110
m_is_multisig = config.m_is_multisig;
111+
m_regtest = config.m_regtest;
111112
}
112113

113114
monero_wallet_config monero_wallet_config::copy() const {
@@ -145,6 +146,7 @@ namespace monero {
145146
// set bool values
146147
if (m_save_current != boost::none) monero_utils::add_json_member("saveCurrent", m_save_current.get(), allocator, root);
147148
if (m_is_multisig != boost::none) monero_utils::add_json_member("isMultisig", m_is_multisig.get(), allocator, root);
149+
if (m_regtest != boost::none) monero_utils::add_json_member("regtest", m_regtest.get(), allocator, root);
148150

149151
// return root
150152
return root;
@@ -182,6 +184,7 @@ namespace monero {
182184
else if (key == std::string("accountLookahead")) config->m_account_lookahead = it->second.get_value<uint64_t>();
183185
else if (key == std::string("subaddressLookahead")) config->m_subaddress_lookahead = it->second.get_value<uint64_t>();
184186
else if (key == std::string("isMultisig")) config->m_is_multisig = it->second.get_value<bool>();
187+
else if (key == std::string("regtest")) config->m_regtest = it->second.get_value<bool>();
185188
}
186189

187190
return config;

src/wallet/monero_wallet_model.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ namespace monero {
8080
boost::optional<uint64_t> m_account_lookahead;
8181
boost::optional<uint64_t> m_subaddress_lookahead;
8282
boost::optional<bool> m_is_multisig;
83+
boost::optional<bool> m_regtest;
8384

8485
monero_wallet_config() {}
8586
monero_wallet_config(const monero_wallet_config& config);

0 commit comments

Comments
 (0)