diff --git a/README.md b/README.md index 17b60ff..439140a 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,7 @@ wallet_config.m_seed = "hefty value later extra artistic firm radar yodel talent wallet_config.m_path = "MyWalletRestored"; wallet_config.m_password = "supersecretpassword123"; wallet_config.m_network_type = monero_network_type::STAGENET; -wallet_config.m_server_uri = "http://localhost:38081"; -wallet_config.m_server_username = "superuser"; -wallet_config.m_server_password = "abctesting123"; +wallet_config.m_server = monero_rpc_connection("http://localhost:38081", "superuser", "abctesting123"); wallet_config.m_restore_height = 380104; wallet_config.m_seed_offset = ""; monero_wallet* wallet_restored = monero_wallet_full::create_wallet(wallet_config); @@ -81,9 +79,7 @@ wallet_config = monero_wallet_config(); wallet_config.m_path = "MyWalletRandom"; wallet_config.m_password = "supersecretpassword123"; wallet_config.m_network_type = monero_network_type::STAGENET; -wallet_config.m_server_uri = "http://localhost:38081"; -wallet_config.m_server_username = "superuser"; -wallet_config.m_server_password = "abctesting123"; +wallet_config.m_server = monero_rpc_connection("http://localhost:38081", "superuser", "abctesting123"); wallet_config.m_language = "English"; monero_wallet* wallet_random = monero_wallet_full::create_wallet(wallet_config); wallet_random->sync(); diff --git a/src/daemon/monero_daemon_model.cpp b/src/daemon/monero_daemon_model.cpp index f78595f..7c78f89 100644 --- a/src/daemon/monero_daemon_model.cpp +++ b/src/daemon/monero_daemon_model.cpp @@ -123,6 +123,17 @@ namespace monero { return root; } + monero_rpc_connection monero_rpc_connection::from_property_tree(const boost::property_tree::ptree& node) { + monero_rpc_connection connection; + for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { + std::string key = it->first; + if (key == std::string("uri")) connection.m_uri = it->second.data(); + else if (key == std::string("username")) connection.m_username = it->second.data(); + else if (key == std::string("password")) connection.m_password = it->second.data(); + } + return connection; + } + // ------------------------- MONERO BLOCK HEADER ---------------------------- rapidjson::Value monero_block_header::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const { diff --git a/src/daemon/monero_daemon_model.h b/src/daemon/monero_daemon_model.h index 5d542f7..3e7a82a 100644 --- a/src/daemon/monero_daemon_model.h +++ b/src/daemon/monero_daemon_model.h @@ -111,8 +111,9 @@ namespace monero { boost::optional m_username; boost::optional m_password; - monero_rpc_connection(const boost::optional& uri = boost::none, const boost::optional& username = boost::none, const boost::optional& password = boost::none) : m_uri(uri), m_username(username), m_password(password) {} + monero_rpc_connection(const std::string& uri = "", const std::string& username = "", const std::string& password = "") : m_uri(uri), m_username(username), m_password(password) {} rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; + static monero_rpc_connection from_property_tree(const boost::property_tree::ptree& node); }; // forward declarations diff --git a/src/wallet/monero_wallet_full.cpp b/src/wallet/monero_wallet_full.cpp index 93873a5..e369269 100644 --- a/src/wallet/monero_wallet_full.cpp +++ b/src/wallet/monero_wallet_full.cpp @@ -1130,7 +1130,7 @@ namespace monero { monero_wallet_full* wallet = new monero_wallet_full(); 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->set_daemon_connection(config.get_server()); + 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()); @@ -1224,7 +1224,7 @@ namespace monero { if (has_spend_key && has_view_key) wallet->m_w2->generate(config.m_path.get(), config.m_password.get(), address_info.address, spend_key_sk, view_key_sk); 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->set_daemon_connection(config.get_server()); + 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()); wallet->init_common(); @@ -1242,7 +1242,7 @@ namespace monero { monero_wallet_full* wallet = new monero_wallet_full(); 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->set_daemon_connection(config.get_server()); + wallet->set_daemon_connection(config.m_server); wallet->m_w2->set_seed_language(config.m_language.get()); crypto::secret_key secret_key; if (config.m_account_lookahead != boost::none) wallet->m_w2->set_subaddress_lookahead(config.m_account_lookahead.get(), config.m_subaddress_lookahead.get()); diff --git a/src/wallet/monero_wallet_model.cpp b/src/wallet/monero_wallet_model.cpp index 1ff364a..acfbd4b 100644 --- a/src/wallet/monero_wallet_model.cpp +++ b/src/wallet/monero_wallet_model.cpp @@ -96,9 +96,7 @@ namespace monero { m_path = config.m_path; m_password = config.m_password; m_network_type = config.m_network_type; - m_server_uri = config.m_server_uri; - m_server_username = config.m_server_username; - m_server_password = config.m_server_password; + m_server = config.m_server; m_seed = config.m_seed; m_seed_offset = config.m_seed_offset; m_primary_address = config.m_primary_address; @@ -121,6 +119,9 @@ namespace monero { // create root rapidjson::Value root(rapidjson::kObjectType); + // set sub-objects + if (m_server != boost::none) root.AddMember("server", m_server.get().to_rapidjson_val(allocator), allocator); + // set num values rapidjson::Value value_num(rapidjson::kNumberType); if (m_network_type != boost::none) monero_utils::add_json_member("networkType", m_network_type.get(), allocator, root, value_num); @@ -132,9 +133,6 @@ namespace monero { rapidjson::Value value_str(rapidjson::kStringType); if (m_path != boost::none) monero_utils::add_json_member("path", m_path.get(), allocator, root, value_str); if (m_password != boost::none) monero_utils::add_json_member("password", m_password.get(), allocator, root, value_str); - if (m_server_uri != boost::none) monero_utils::add_json_member("serverUri", m_server_uri.get(), allocator, root, value_str); - if (m_server_username != boost::none) monero_utils::add_json_member("serverUsername", m_server_username.get(), allocator, root, value_str); - if (m_server_password != boost::none) monero_utils::add_json_member("serverPassword", m_server_password.get(), allocator, root, value_str); if (m_seed != boost::none) monero_utils::add_json_member("seed", m_seed.get(), allocator, root, value_str); if (m_seed_offset != boost::none) monero_utils::add_json_member("seedOffset", m_seed_offset.get(), allocator, root, value_str); if (m_primary_address != boost::none) monero_utils::add_json_member("primaryAddress", m_primary_address.get(), allocator, root, value_str); @@ -172,9 +170,7 @@ namespace monero { else if (network_type_num == 2) config->m_network_type = monero_network_type::STAGENET; else throw std::runtime_error("Invalid network type number: " + std::to_string(network_type_num)); } - else if (key == std::string("serverUri")) config->m_server_uri = it->second.data(); - else if (key == std::string("serverUsername")) config->m_server_username = it->second.data(); - else if (key == std::string("serverPassword")) config->m_server_password = it->second.data(); + else if (key == std::string("server")) config->m_server = monero_rpc_connection::from_property_tree(it->second); else if (key == std::string("seed")) config->m_seed = it->second.data(); else if (key == std::string("seedOffset")) config->m_seed_offset = it->second.data(); else if (key == std::string("primaryAddress")) config->m_primary_address = it->second.data(); @@ -191,19 +187,6 @@ namespace monero { return config; } - void monero_wallet_config::set_server(const monero_rpc_connection& server) { - m_server_uri = server.m_uri; - m_server_username = server.m_username; - m_server_password = server.m_password; - } - - monero_rpc_connection monero_wallet_config::get_server() const { - return monero_rpc_connection( - std::string(m_server_uri == boost::none ? "" : m_server_uri.get()), - std::string(m_server_username == boost::none ? "" : m_server_username.get()), - std::string(m_server_password == boost::none ? "" : m_server_password.get())); - } - // -------------------------- MONERO SYNC RESULT ---------------------------- rapidjson::Value monero_sync_result::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const { diff --git a/src/wallet/monero_wallet_model.h b/src/wallet/monero_wallet_model.h index cde95d0..c6d83dd 100644 --- a/src/wallet/monero_wallet_model.h +++ b/src/wallet/monero_wallet_model.h @@ -68,9 +68,7 @@ namespace monero { boost::optional m_path; boost::optional m_password; boost::optional m_network_type; - boost::optional m_server_uri; - boost::optional m_server_username; - boost::optional m_server_password; + boost::optional m_server; boost::optional m_seed; boost::optional m_seed_offset; boost::optional m_primary_address; @@ -88,8 +86,6 @@ namespace monero { monero_wallet_config copy() const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; static std::shared_ptr deserialize(const std::string& config_json); - void set_server(const monero_rpc_connection& server); - monero_rpc_connection get_server() const; }; /** diff --git a/test/monero_tests.cpp b/test/monero_tests.cpp index 407cf1a..8fc83c6 100644 --- a/test/monero_tests.cpp +++ b/test/monero_tests.cpp @@ -267,9 +267,6 @@ void test_multisig_stress(monero_wallet* funding_wallet, string wallet_name = "" vector participants; try { for (int i = 0; i < N; i++) { - monero_wallet_config wallet_config; - wallet_config.m_path = wallet_path + string("_") + std::to_string(i); - wallet_config.m_server_uri = DAEMON_URI; participants.push_back(monero_wallet_full::open_wallet(wallet_path + string("_") + std::to_string(i), "", NETWORK_TYPE)); } for (int i = 0; i < participants.size(); i++) { @@ -282,7 +279,7 @@ void test_multisig_stress(monero_wallet* funding_wallet, string wallet_name = "" monero_wallet_config wallet_config; wallet_config.m_path = wallet_path + string("_") + std::to_string(i); wallet_config.m_network_type = monero_network_type::TESTNET; - wallet_config.m_server_uri = DAEMON_URI; + wallet_config.m_server = monero_rpc_connection(DAEMON_URI); participants.push_back(monero_wallet_full::create_wallet(wallet_config)); } for (int i = 0; i < participants.size(); i++) { diff --git a/test/sample_code.cpp b/test/sample_code.cpp index f2013d4..8b2be95 100644 --- a/test/sample_code.cpp +++ b/test/sample_code.cpp @@ -26,9 +26,7 @@ int main(int argc, const char* argv[]) { wallet_config.m_path = "MyWalletRestored"; wallet_config.m_password = "supersecretpassword123"; wallet_config.m_network_type = monero_network_type::STAGENET; - wallet_config.m_server_uri = "http://localhost:38081"; - wallet_config.m_server_username = "superuser"; - wallet_config.m_server_password = "abctesting123"; + wallet_config.m_server = monero_rpc_connection("http://localhost:38081", "superuser", "abctesting123"); wallet_config.m_restore_height = 380104; wallet_config.m_seed_offset = ""; monero_wallet* wallet_restored = monero_wallet_full::create_wallet(wallet_config); @@ -80,9 +78,7 @@ int main(int argc, const char* argv[]) { wallet_config.m_path = "MyWalletRandom"; wallet_config.m_password = "supersecretpassword123"; wallet_config.m_network_type = monero_network_type::STAGENET; - wallet_config.m_server_uri = "http://localhost:38081"; - wallet_config.m_server_username = "superuser"; - wallet_config.m_server_password = "abctesting123"; + wallet_config.m_server = monero_rpc_connection("http://localhost:38081", "superuser", "abctesting123"); wallet_config.m_language = "English"; monero_wallet* wallet_random = monero_wallet_full::create_wallet(wallet_config); wallet_random->sync();