Skip to content

Commit 75b946f

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` * add `regtest` parameter for `monero_wallet_full::open_wallet*`
1 parent 32c1b75 commit 75b946f

4 files changed

Lines changed: 33 additions & 4 deletions

File tree

src/wallet/monero_wallet_full.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,23 +1059,33 @@ namespace monero {
10591059
return key_file_exists;
10601060
}
10611061

1062-
monero_wallet_full* monero_wallet_full::open_wallet(const std::string& path, const std::string& password, const monero_network_type network_type) {
1062+
monero_wallet_full* monero_wallet_full::open_wallet(const std::string& path, const std::string& password, const monero_network_type network_type, bool regtest) {
10631063
MTRACE("open_wallet(" << path << ", ***, " << network_type << ")");
10641064
monero_wallet_full* wallet = new monero_wallet_full();
10651065
wallet->m_w2 = std::unique_ptr<tools::wallet2>(new tools::wallet2(static_cast<cryptonote::network_type>(network_type), 1, true));
10661066
wallet->m_w2->load(path, password);
10671067
wallet->m_w2->init("");
1068+
if (regtest) {
1069+
if (network_type != monero_network_type::MAINNET) throw std::runtime_error("Network type must be mainnet when using regtest option");
1070+
wallet->m_w2->allow_mismatched_daemon_version(true);
1071+
wallet->m_w2->max_reorg_depth(100000);
1072+
}
10681073
wallet->init_common();
10691074
return wallet;
10701075
}
10711076

1072-
monero_wallet_full* monero_wallet_full::open_wallet_data(const std::string& password, const monero_network_type network_type, const std::string& keys_data, const std::string& cache_data, const monero_rpc_connection& daemon_connection, std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory) {
1077+
monero_wallet_full* monero_wallet_full::open_wallet_data(const std::string& password, const monero_network_type network_type, const std::string& keys_data, const std::string& cache_data, const monero_rpc_connection& daemon_connection, std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory, bool regtest) {
10731078
MTRACE("open_wallet_data(...)");
10741079
monero_wallet_full* wallet = new monero_wallet_full();
10751080
if (http_client_factory == nullptr) wallet->m_w2 = std::unique_ptr<tools::wallet2>(new tools::wallet2(static_cast<cryptonote::network_type>(network_type), 1, true));
10761081
else wallet->m_w2 = std::unique_ptr<tools::wallet2>(new tools::wallet2(static_cast<cryptonote::network_type>(network_type), 1, true, std::move(http_client_factory)));
10771082
wallet->m_w2->load("", password, keys_data, cache_data);
10781083
wallet->m_w2->init("");
1084+
if (regtest) {
1085+
if (network_type != monero_network_type::MAINNET) throw std::runtime_error("Network type must be mainnet when using regtest option");
1086+
wallet->m_w2->allow_mismatched_daemon_version(true);
1087+
wallet->m_w2->max_reorg_depth(100000);
1088+
}
10791089
wallet->set_daemon_connection(daemon_connection);
10801090
wallet->init_common();
10811091
return wallet;
@@ -1100,6 +1110,7 @@ namespace monero {
11001110
if (config_normalized.m_language.get().empty()) config_normalized.m_language = std::string("English");
11011111
if (!monero_utils::is_valid_language(config_normalized.m_language.get())) throw std::runtime_error("Unknown language: " + config_normalized.m_language.get());
11021112
if (config.m_network_type == boost::none) throw std::runtime_error("Must provide wallet network type");
1113+
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");
11031114

11041115
// create wallet
11051116
if (!config_normalized.m_seed.get().empty()) {
@@ -1137,6 +1148,10 @@ namespace monero {
11371148
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));
11381149
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)));
11391150
wallet->m_w2->init("");
1151+
if (config.m_regtest != boost::none && config.m_regtest.get() == true) {
1152+
wallet->m_w2->allow_mismatched_daemon_version(true);
1153+
wallet->m_w2->max_reorg_depth(100000);
1154+
}
11401155
wallet->set_daemon_connection(config.m_server);
11411156
wallet->m_w2->set_seed_language(language);
11421157
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 +1247,10 @@ namespace monero {
12321247
else if (has_spend_key) wallet->m_w2->generate(config.m_path.get(), config.m_password.get(), spend_key_sk, true, false);
12331248
else wallet->m_w2->generate(config.m_path.get(), config.m_password.get(), address_info.address, view_key_sk);
12341249
wallet->m_w2->init("");
1250+
if (config.m_regtest != boost::none && config.m_regtest.get() == true) {
1251+
wallet->m_w2->allow_mismatched_daemon_version(true);
1252+
wallet->m_w2->max_reorg_depth(100000);
1253+
}
12351254
wallet->set_daemon_connection(config.m_server);
12361255
wallet->m_w2->set_refresh_from_block_height(config.m_restore_height.get());
12371256
wallet->m_w2->set_seed_language(config.m_language.get());
@@ -1251,6 +1270,10 @@ namespace monero {
12511270
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));
12521271
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)));
12531272
wallet->m_w2->init("");
1273+
if (config.m_regtest != boost::none && config.m_regtest.get() == true) {
1274+
wallet->m_w2->allow_mismatched_daemon_version(true);
1275+
wallet->m_w2->max_reorg_depth(100000);
1276+
}
12541277
wallet->set_daemon_connection(config.m_server);
12551278
wallet->m_w2->set_seed_language(config.m_language.get());
12561279
crypto::secret_key secret_key;

src/wallet/monero_wallet_full.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ namespace monero {
9292
* @param path is the path to the wallet file to open
9393
* @param password is the password of the wallet file to open
9494
* @param network_type is the wallet's network type
95+
* @param regtest enable regtest
9596
* @return a pointer to the wallet instance
9697
*/
97-
static monero_wallet_full* open_wallet(const std::string& path, const std::string& password, const monero_network_type network_type);
98+
static monero_wallet_full* open_wallet(const std::string& path, const std::string& password, const monero_network_type network_type, bool regtest = false);
9899

99100
/**
100101
* Open an in-memory wallet from existing data buffers.
@@ -105,9 +106,10 @@ namespace monero {
105106
* @param cache_data contains the contents of the wallet cache file (no extension)
106107
* @param daemon_connection is connection information to a daemon (default = an unconnected wallet)
107108
* @param http_client_factory allows use of custom http clients
109+
* @param regtest enable regtest
108110
* @return a pointer to the wallet instance
109111
*/
110-
static monero_wallet_full* open_wallet_data(const std::string& password, const monero_network_type, const std::string& keys_data, const std::string& cache_data, const monero_rpc_connection& daemon_connection = monero_rpc_connection(), std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory = nullptr);
112+
static monero_wallet_full* open_wallet_data(const std::string& password, const monero_network_type, const std::string& keys_data, const std::string& cache_data, const monero_rpc_connection& daemon_connection = monero_rpc_connection(), std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory = nullptr, bool regtest = false);
111113

112114
/**
113115
* Create a new wallet with the given configuration.

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)