wallet config uses monero_rpc_connection for server model (breaking)

construct monero_rpc_connection with strings instead of boost::optional
This commit is contained in:
woodser
2023-09-01 17:19:34 -04:00
parent f342ed9f5c
commit 6215ed5f1a
8 changed files with 27 additions and 47 deletions
+2 -6
View File
@@ -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();
+11
View File
@@ -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 {
+2 -1
View File
@@ -111,8 +111,9 @@ namespace monero {
boost::optional<std::string> m_username;
boost::optional<std::string> m_password;
monero_rpc_connection(const boost::optional<std::string>& uri = boost::none, const boost::optional<std::string>& username = boost::none, const boost::optional<std::string>& 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
+3 -3
View File
@@ -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<tools::wallet2>(new tools::wallet2(static_cast<cryptonote::network_type>(config.m_network_type.get()), 1, true));
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)));
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<tools::wallet2>(new tools::wallet2(static_cast<cryptonote::network_type>(config.m_network_type.get()), 1, true));
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)));
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());
+5 -22
View File
@@ -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 {
+1 -5
View File
@@ -68,9 +68,7 @@ namespace monero {
boost::optional<std::string> m_path;
boost::optional<std::string> m_password;
boost::optional<monero_network_type> m_network_type;
boost::optional<std::string> m_server_uri;
boost::optional<std::string> m_server_username;
boost::optional<std::string> m_server_password;
boost::optional<monero_rpc_connection> m_server;
boost::optional<std::string> m_seed;
boost::optional<std::string> m_seed_offset;
boost::optional<std::string> 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<monero_wallet_config> deserialize(const std::string& config_json);
void set_server(const monero_rpc_connection& server);
monero_rpc_connection get_server() const;
};
/**
+1 -4
View File
@@ -267,9 +267,6 @@ void test_multisig_stress(monero_wallet* funding_wallet, string wallet_name = ""
vector<monero_wallet*> 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++) {
+2 -6
View File
@@ -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();