diff --git a/contrib/epee/include/misc_language.h b/contrib/epee/include/misc_language.h index 6e2e09f2..ecf6677e 100644 --- a/contrib/epee/include/misc_language.h +++ b/contrib/epee/include/misc_language.h @@ -82,6 +82,13 @@ namespace epee namespace misc_utils { + + template + void cast_assign_a_to_b(t_type_a& a, const t_type_b& b) + { + *static_cast(&a) = b; + } + template diff --git a/contrib/epee/include/net/http_base.h b/contrib/epee/include/net/http_base.h index cca1add3..afaadbf4 100644 --- a/contrib/epee/include/net/http_base.h +++ b/contrib/epee/include/net/http_base.h @@ -98,7 +98,7 @@ namespace net_utils std::string m_transfer_encoding;//"Transfer-Encoding:" std::string m_content_encoding; //"Content-Encoding:" std::string m_host; //"Host:" - std::string m_cookie; //"Cookie:" + std::string m_cookie; //"Cookie:" fields_list m_etc_fields; void clear() @@ -147,10 +147,10 @@ namespace net_utils std::string m_http_method_str; std::string m_full_request_str; std::string m_replace_html; - std::string m_request_head; + std::string m_request_head; int m_http_ver_hi; int m_http_ver_lo; - bool m_have_to_block; + bool m_have_to_block; http_header_info m_header_info; uri_content m_uri_content; size_t m_full_request_buf_size; @@ -166,11 +166,11 @@ namespace net_utils struct http_response_info { - int m_response_code; - std::string m_response_comment; + int m_response_code; + std::string m_response_comment; fields_list m_additional_fields; - std::string m_body; - std::string m_mime_tipe; + std::string m_body; + std::string m_mime_tipe; http_header_info m_header_info; int m_http_ver_hi;// OUT paramter only int m_http_ver_lo;// OUT paramter only diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 8f858303..9be85e20 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -534,6 +534,20 @@ namespace currency bool is_pos_coinbase(const transaction& tx); bool have_attachment_service_in_container(const std::vector& av, const std::string& service_id, const std::string& instruction); crypto::hash prepare_prefix_hash_for_sign(const transaction& tx, uint64_t in_index, const crypto::hash& tx_id); + + + //--------------------------------------------------------------- + template + void assets_map_to_assets_list(std::list& assets_list, const t_assets_map& assets_map) + { + for (const auto& pr : assets_map) + { + assets_list.push_back(currency::asset_descriptor_with_id()); + assets_list.back().asset_id = pr.first; + epee::misc_utils::cast_assign_a_to_b(assets_list.back(), static_cast(pr.second)); + //*static_cast(&assets_list.back()) = pr.second; + } + } //--------------------------------------------------------------- template diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index d2cc787c..0e3c974e 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -223,7 +223,7 @@ QString MainWindow::get_default_user_dir(const QString& param) } -bool MainWindow::toggle_mining() +bool MainWindow::toggle_mining(const QString& param) { TRY_ENTRY(); m_backend.toggle_pos_mining(); @@ -238,7 +238,7 @@ QString MainWindow::get_exchange_last_top(const QString& params) CATCH_ENTRY_FAIL_API_RESPONCE(); } -QString MainWindow::get_tx_pool_info() +QString MainWindow::get_tx_pool_info(const QString& param) { TRY_ENTRY(); LOG_API_TIMING(); @@ -248,7 +248,7 @@ QString MainWindow::get_tx_pool_info() CATCH_ENTRY_FAIL_API_RESPONCE(); } -QString MainWindow::request_dummy() +QString MainWindow::request_dummy(const QString& param) { static int code_ = 0; TRY_ENTRY(); @@ -284,7 +284,7 @@ QString MainWindow::call_rpc(const QString& params) epee::net_utils::http::http_request_info query_info = AUTO_VAL_INIT(query_info); epee::net_utils::http::http_response_info response_info = AUTO_VAL_INIT(response_info); - currency::core_rpc_server::connection_context dummy_context = AUTO_VAL_INIT(dummy_context); + currency::core_rpc_server::connection_context dummy_context(RPC_INTERNAL_UI_CONTEXT, 0, 0, true); query_info.m_URI = "/json_rpc"; query_info.m_body = params.toStdString(); @@ -301,14 +301,14 @@ QString MainWindow::call_rpc(const QString& params) return QString::fromStdString(response_info.m_body); CATCH_ENTRY_FAIL_API_RESPONCE(); } -QString MainWindow::get_default_fee() +QString MainWindow::get_default_fee(const QString& param) { TRY_ENTRY(); return QString(std::to_string(m_backend.get_default_fee()).c_str()); CATCH_ENTRY_FAIL_API_RESPONCE(); } -QString MainWindow::get_options() +QString MainWindow::get_options(const QString& param) { TRY_ENTRY(); LOG_API_TIMING(); @@ -319,7 +319,7 @@ QString MainWindow::get_options() CATCH_ENTRY_FAIL_API_RESPONCE(); } -void MainWindow::tray_quit_requested() +void MainWindow::tray_quit_requested(const QString& param) { TRY_ENTRY(); LOG_PRINT_MAGENTA("[GUI]->[HTML] tray_quit_requested", LOG_LEVEL_0); @@ -350,10 +350,10 @@ void MainWindow::closeEvent(QCloseEvent *event) } else { + event->ignore(); //m_quit_requested = true; LOG_PRINT_L0("[GUI]->[HTML] quit_requested"); emit quit_requested("{}"); - event->ignore(); } CATCH_ENTRY2(void()); } @@ -474,7 +474,7 @@ bool MainWindow::init(const std::string& html_path) CATCH_ENTRY2(false); } -void MainWindow::on_menu_show() +void MainWindow::on_menu_show(const QString& param) { TRY_ENTRY(); qDebug() << "Context menu: show()"; @@ -546,7 +546,7 @@ void MainWindow::bool_toggle_icon(const QString& param) CATCH_ENTRY2(void()); } -QString MainWindow::get_log_file() +QString MainWindow::get_log_file(const QString& param) { TRY_ENTRY(); std::string buff; @@ -662,7 +662,7 @@ QString MainWindow::set_clipboard(const QString& param) CATCH_ENTRY2(API_RETURN_CODE_INTERNAL_ERROR); } -QString MainWindow::get_clipboard() +QString MainWindow::get_clipboard(const QString& param) { TRY_ENTRY(); LOG_API_TIMING(); @@ -671,7 +671,7 @@ QString MainWindow::get_clipboard() CATCH_ENTRY2(API_RETURN_CODE_INTERNAL_ERROR); } -QString MainWindow::on_request_quit() +QString MainWindow::on_request_quit(const QString& param) { TRY_ENTRY(); LOG_PRINT_MAGENTA("[HTML]->[GUI] on_request_quit", LOG_LEVEL_0); @@ -933,7 +933,7 @@ bool MainWindow::init_backend(int argc, char* argv[]) CATCH_ENTRY2(false); } -QString MainWindow::is_remnotenode_mode_preconfigured() +QString MainWindow::is_remnotenode_mode_preconfigured(const QString& param) { TRY_ENTRY(); return API_RETURN_CODE_FALSE; @@ -1044,7 +1044,7 @@ bool MainWindow::nativeEventFilter(const QByteArray &eventType, void *message, l CATCH_ENTRY2(false); } -bool MainWindow::get_is_disabled_notifications() +bool MainWindow::get_is_disabled_notifications(const QString& param) { return m_config.disable_notifications; } @@ -1181,21 +1181,21 @@ bool MainWindow::pos_block_found(const currency::block& block_found) CATCH_ENTRY2(false); } -QString MainWindow::get_version() +QString MainWindow::get_version(const QString& param) { TRY_ENTRY(); return PROJECT_VERSION_LONG; CATCH_ENTRY_FAIL_API_RESPONCE(); } -QString MainWindow::get_os_version() +QString MainWindow::get_os_version(const QString& param) { TRY_ENTRY(); return tools::get_os_version_string().c_str(); CATCH_ENTRY2(API_RETURN_CODE_INTERNAL_ERROR); } -QString MainWindow::get_network_type() +QString MainWindow::get_network_type(const QString& param) { #if defined(TESTNET) return "testnet"; @@ -1626,7 +1626,7 @@ QString MainWindow::load_from_file(const QString& path) CATCH_ENTRY2(API_RETURN_CODE_INTERNAL_ERROR); } -QString MainWindow::get_app_data() +QString MainWindow::get_app_data(const QString& param) { TRY_ENTRY(); LOG_API_TIMING(); @@ -1637,7 +1637,7 @@ QString MainWindow::get_app_data() } -QString MainWindow::have_secure_app_data() +QString MainWindow::have_secure_app_data(const QString& param) { TRY_ENTRY(); LOG_API_TIMING(); @@ -1655,7 +1655,7 @@ QString MainWindow::have_secure_app_data() CATCH_ENTRY_FAIL_API_RESPONCE(); } -QString MainWindow::drop_secure_app_data() +QString MainWindow::drop_secure_app_data(const QString& param) { TRY_ENTRY(); LOG_API_TIMING(); @@ -1673,7 +1673,7 @@ QString MainWindow::drop_secure_app_data() CATCH_ENTRY_FAIL_API_RESPONCE(); } -QString MainWindow::get_all_aliases() +QString MainWindow::get_all_aliases(const QString& param) { TRY_ENTRY(); LOG_API_TIMING(); @@ -1779,7 +1779,7 @@ QString MainWindow::set_enable_tor(const QString& param) // return MAKE_RESPONSE(ar); // } -QString MainWindow::webkit_launched_script() +QString MainWindow::webkit_launched_script(const QString& param) { TRY_ENTRY(); m_last_update_daemon_status_json.clear(); @@ -1993,7 +1993,7 @@ QString MainWindow::get_fav_offers(const QString& param) return MAKE_RESPONSE(ar); CATCH_ENTRY_FAIL_API_RESPONCE(); } -QString MainWindow::is_pos_allowed() +QString MainWindow::is_pos_allowed(const QString& param) { TRY_ENTRY(); LOG_API_TIMING(); @@ -2265,7 +2265,7 @@ QString MainWindow::is_wallet_password_valid(const QString& param) CATCH_ENTRY_FAIL_API_RESPONCE(); } -QString MainWindow::is_autostart_enabled() +QString MainWindow::is_autostart_enabled(const QString& param) { TRY_ENTRY(); LOG_API_TIMING(); @@ -2319,6 +2319,16 @@ QString MainWindow::open_url_in_browser(const QString& param) CATCH_ENTRY2(API_RETURN_CODE_INTERNAL_ERROR); } +QString MainWindow::setup_jwt_wallet_rpc(const QString& param) +{ + TRY_ENTRY(); + + m_backend.setup_wallet_rpc(param.toStdString()); + + return API_RETURN_CODE_OK; + CATCH_ENTRY2(API_RETURN_CODE_INTERNAL_ERROR); +} + QString MainWindow::is_valid_restore_wallet_text(const QString& param) { TRY_ENTRY(); diff --git a/src/gui/qt-daemon/application/mainwindow.h b/src/gui/qt-daemon/application/mainwindow.h index ed980f7d..c2725682 100644 --- a/src/gui/qt-daemon/application/mainwindow.h +++ b/src/gui/qt-daemon/application/mainwindow.h @@ -106,17 +106,18 @@ public: QString accept_cancel_contract(const QString& param); - QString get_version(); - QString get_os_version(); - QString get_network_type(); + QString on_request_quit(const QString& param); + QString get_version(const QString& param); + QString get_os_version(const QString& param); + QString get_network_type(const QString& param); QString transfer(const QString& json_transfer_object); - QString have_secure_app_data(); - QString drop_secure_app_data(); + QString have_secure_app_data(const QString& param); + QString drop_secure_app_data(const QString& param); QString get_secure_app_data(const QString& param); QString store_secure_app_data(const QString& param); QString set_master_password(const QString& param); QString check_master_password(const QString& param); - QString get_app_data(); + QString get_app_data(const QString& param); QString store_app_data(const QString& param); QString get_default_user_dir(const QString& param); // QString get_all_offers(const QString& param); @@ -126,12 +127,11 @@ public: QString push_update_offer(const QString& param); QString get_alias_info_by_address(const QString& param); QString get_alias_info_by_name(const QString& param); - QString get_all_aliases(); + QString get_all_aliases(const QString& param); QString request_alias_registration(const QString& param); QString request_alias_update(const QString& param); QString get_alias_coast(const QString& param); QString validate_address(const QString& param); - QString on_request_quit(); QString resync_wallet(const QString& param); QString get_recent_transfers(const QString& param); QString get_mining_history(const QString& param); @@ -141,11 +141,11 @@ public: QString get_log_level(const QString& param); QString set_enable_tor(const QString& param); // QString dump_all_offers(); - QString webkit_launched_script(); + QString webkit_launched_script(const QString& param); QString get_smart_wallet_info(const QString& param); QString restore_wallet(const QString& param); QString use_whitelisting(const QString& param); - QString is_pos_allowed(); + QString is_pos_allowed(const QString& param); QString store_to_file(const QString& path, const QString& buff); QString load_from_file(const QString& path); QString is_file_exist(const QString& path); @@ -153,7 +153,7 @@ public: QString backup_wallet_keys(const QString& obj); QString reset_wallet_password(const QString& param); QString is_wallet_password_valid(const QString& param); - QString is_autostart_enabled(); + QString is_autostart_enabled(const QString& param); QString toggle_autostart(const QString& param); QString is_valid_restore_wallet_text(const QString& param); QString get_seed_phrase_info(const QString& param); @@ -161,13 +161,13 @@ public: QString print_log(const QString& param); QString set_clipboard(const QString& param); QString set_localization_strings(const QString str); - QString get_clipboard(); + QString get_clipboard(const QString& param); void message_box(const QString& msg); - bool toggle_mining(); + bool toggle_mining(const QString& param); QString get_exchange_last_top(const QString& params); - QString get_tx_pool_info(); - QString get_default_fee(); - QString get_options(); + QString get_tx_pool_info(const QString& param); + QString get_default_fee(const QString& param); + QString get_options(const QString& param); void bool_toggle_icon(const QString& param); QString add_custom_asset_id(const QString& param); QString remove_custom_asset_id(const QString& param); @@ -177,24 +177,25 @@ public: QString get_ionic_swap_proposal_info(const QString& param); QString accept_ionic_swap_proposal(const QString& param); - bool get_is_disabled_notifications(); + bool get_is_disabled_notifications(const QString& param); bool set_is_disabled_notifications(const bool& param); QString export_wallet_history(const QString& param); - QString get_log_file(); + QString get_log_file(const QString& param); //QString check_available_sources(const QString& param); QString open_url_in_browser(const QString& param); + QString setup_jwt_wallet_rpc(const QString& param); void trayIconActivated(QSystemTrayIcon::ActivationReason reason); - void tray_quit_requested(); - void on_menu_show(); - QString is_remnotenode_mode_preconfigured(); + void tray_quit_requested(const QString& param); + void on_menu_show(const QString& param); + QString is_remnotenode_mode_preconfigured(const QString& param); QString start_backend(const QString& params); QString async_call(const QString& func_name, const QString& params); QString sync_call(const QString& func_name, const QString& params); - //for test purposes onlys - QString request_dummy(); + //for test purposes only + QString request_dummy(const QString& param); QString call_rpc(const QString& params); diff --git a/src/wallet/core_default_rpc_proxy.cpp b/src/wallet/core_default_rpc_proxy.cpp index 92cf11bc..7035b57c 100644 --- a/src/wallet/core_default_rpc_proxy.cpp +++ b/src/wallet/core_default_rpc_proxy.cpp @@ -52,6 +52,27 @@ namespace tools return r; } //------------------------------------------------------------------------------------------------------------------------------ + bool default_http_core_proxy::call_COMMAND_RPC_INVOKE(const std::string& uri, const std::string& body, int& response_code, std::string& response_body) + { + return call_request([&]() { +#ifdef MOBILE_WALLET_BUILD + LOG_PRINT_L0("[INVOKE_PROXY] ---> " << method_name) +#endif + + const epee::net_utils::http::http_response_info* response = nullptr; + bool res = m_http_client.invoke(uri, "POST", body, &response); + if (response) + { + response_body = response->m_body; + response_code = response->m_response_code; + } +#ifdef MOBILE_WALLET_BUILD + LOG_PRINT_L0("[INVOKE_PROXY] <---" << method_name) +#endif + return res; + }); + } + //------------------------------------------------------------------------------------------------------------------------------ bool default_http_core_proxy::call_COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE(const currency::COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::request& rqt, currency::COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::response& rsp) { return invoke_http_json_rpc_update_is_disconnect("get_est_height_from_date", rqt, rsp); diff --git a/src/wallet/core_default_rpc_proxy.h b/src/wallet/core_default_rpc_proxy.h index 2d28c071..51a014a5 100644 --- a/src/wallet/core_default_rpc_proxy.h +++ b/src/wallet/core_default_rpc_proxy.h @@ -53,6 +53,7 @@ namespace tools bool call_COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN(const currency::COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN::request& req, currency::COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN::response& res) override; bool call_COMMAND_RPC_GET_POOL_INFO(const currency::COMMAND_RPC_GET_POOL_INFO::request& req, currency::COMMAND_RPC_GET_POOL_INFO::response& res) override; bool call_COMMAND_RPC_GET_ASSET_INFO(const currency::COMMAND_RPC_GET_ASSET_INFO::request& req, currency::COMMAND_RPC_GET_ASSET_INFO::response& res) override; + bool call_COMMAND_RPC_INVOKE(const std::string& uri, const std::string& body, int& response_code, std::string& response_body) override; bool check_connection() override; bool get_transfer_address(const std::string& adr_str, currency::account_public_address& addr, std::string& payment_id) override; diff --git a/src/wallet/core_fast_rpc_proxy.h b/src/wallet/core_fast_rpc_proxy.h index 3d212676..daac69eb 100644 --- a/src/wallet/core_fast_rpc_proxy.h +++ b/src/wallet/core_fast_rpc_proxy.h @@ -143,6 +143,22 @@ namespace tools return m_rpc.on_get_asset_info(req, res, m_cntxt_stub); } //------------------------------------------------------------------------------------------------------------------------------ + virtual bool call_COMMAND_RPC_INVOKE(const std::string& uri, const std::string& body, int& response_code, std::string& response_body) override + { + epee::net_utils::http::http_request_info query_info = AUTO_VAL_INIT(query_info); + query_info.m_URI = uri; + query_info.m_http_method = epee::net_utils::http::http_method_get; + query_info.m_body = body; + + epee::net_utils::http::http_response_info response = AUTO_VAL_INIT(response); + epee::net_utils::connection_context_base conn_context = AUTO_VAL_INIT(conn_context); + + bool res = m_rpc.handle_http_request(query_info, response, conn_context); + response_body = response.m_body; + response_code = response.m_response_code; + return res; + } + //------------------------------------------------------------------------------------------------------------------------------ virtual bool get_transfer_address(const std::string& adr_str, currency::account_public_address& addr, std::string& payment_id) override { return tools::get_transfer_address(adr_str, addr, payment_id, this); diff --git a/src/wallet/core_rpc_proxy.h b/src/wallet/core_rpc_proxy.h index effec340..407e4b49 100644 --- a/src/wallet/core_rpc_proxy.h +++ b/src/wallet/core_rpc_proxy.h @@ -53,6 +53,8 @@ namespace tools virtual bool call_COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN(const currency::COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN::request& req, currency::COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN::response& res){ return false; } virtual bool call_COMMAND_RPC_GET_POOL_INFO(const currency::COMMAND_RPC_GET_POOL_INFO::request& req, currency::COMMAND_RPC_GET_POOL_INFO::response& res) { return false; } virtual bool call_COMMAND_RPC_GET_ASSET_INFO(const currency::COMMAND_RPC_GET_ASSET_INFO::request& req, currency::COMMAND_RPC_GET_ASSET_INFO::response& res) { return false; } + + virtual bool call_COMMAND_RPC_INVOKE(const std::string& uri, const std::string& body, int& response_code, std::string& response_body) { return false; } i_core_proxy() { diff --git a/src/wallet/view_iface.h b/src/wallet/view_iface.h index d315a041..16faf90e 100644 --- a/src/wallet/view_iface.h +++ b/src/wallet/view_iface.h @@ -729,12 +729,14 @@ public: struct gui_options { - bool use_debug_mode; - bool disable_price_fetch; + bool use_debug_mode = false; + bool disable_price_fetch = false; + int32_t rpc_port = 0; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(use_debug_mode) KV_SERIALIZE(disable_price_fetch) + KV_SERIALIZE(rpc_port) END_KV_SERIALIZE_MAP() }; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 49c13987..67b48f2c 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -390,16 +390,17 @@ void wallet2::process_ado_in_new_transaction(const currency::asset_descriptor_op WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(m_own_asset_descriptors.count(asset_id) == 0, "asset with asset_id " << asset_id << " has already been registered in the wallet as own asset"); wallet_own_asset_context& asset_context = m_own_asset_descriptors[asset_id]; - asset_context.asset_descriptor = ado.descriptor; + epee::misc_utils::cast_assign_a_to_b(asset_context, ado.descriptor); + //*static_cast(&asset_context) = ado.descriptor; std::stringstream ss; ss << "New Asset Registered:" << ENDL << "asset id: " << asset_id - << ENDL << "Name: " << asset_context.asset_descriptor.full_name - << ENDL << "Ticker: " << asset_context.asset_descriptor.ticker - << ENDL << "Total Max Supply: " << print_asset_money(asset_context.asset_descriptor.total_max_supply, asset_context.asset_descriptor.decimal_point) - << ENDL << "Current Supply: " << print_asset_money(asset_context.asset_descriptor.current_supply, asset_context.asset_descriptor.decimal_point) - << ENDL << "Decimal Point: " << asset_context.asset_descriptor.decimal_point; + << ENDL << "Name: " << asset_context.full_name + << ENDL << "Ticker: " << asset_context.ticker + << ENDL << "Total Max Supply: " << print_asset_money(asset_context.total_max_supply, asset_context.decimal_point) + << ENDL << "Current Supply: " << print_asset_money(asset_context.current_supply, asset_context.decimal_point) + << ENDL << "Decimal Point: " << asset_context.decimal_point; add_rollback_event(ptc.height, asset_register_event{ asset_id }); @@ -414,7 +415,8 @@ void wallet2::process_ado_in_new_transaction(const currency::asset_descriptor_op break; //asset had been updated add_rollback_event(ptc.height, asset_update_event{ it->first, it->second }); - it->second.asset_descriptor = ado.descriptor; + epee::misc_utils::cast_assign_a_to_b(it->second, ado.descriptor); + } else if (ado.operation_type == ASSET_DESCRIPTOR_OPERATION_UPDATE ) { @@ -426,7 +428,7 @@ void wallet2::process_ado_in_new_transaction(const currency::asset_descriptor_op // ownership of the asset acquired wallet_own_asset_context& asset_context = m_own_asset_descriptors[asset_id]; - asset_context.asset_descriptor = ado.descriptor; + epee::misc_utils::cast_assign_a_to_b(asset_context, ado.descriptor); std::stringstream ss; ss << "Asset ownership acquired:" @@ -477,7 +479,8 @@ void wallet2::process_ado_in_new_transaction(const currency::asset_descriptor_op { //just an update of the asset add_rollback_event(ptc.height, asset_update_event{ it->first, it->second }); - it->second.asset_descriptor = ado.descriptor; + epee::misc_utils::cast_assign_a_to_b(it->second, ado.descriptor); + } } } @@ -3461,7 +3464,7 @@ bool wallet2::balance(std::list& balances, u { if (m_whitelisted_assets.find(own_asset.first) == m_whitelisted_assets.end()) { - custom_assets_local[own_asset.first] = own_asset.second.asset_descriptor; + custom_assets_local[own_asset.first] = own_asset.second; } } @@ -3585,17 +3588,21 @@ bool wallet2::delete_custom_asset_id(const crypto::public_key& asset_id) return true; } //---------------------------------------------------------------------------------------------------- -bool wallet2::get_custom_assets(std::list& assets) const +const std::unordered_map& wallet2::get_local_whitelist() const { - for(const auto& pr : m_custom_assets) - { - assets.push_back(currency::asset_descriptor_with_id()); - assets.back().asset_id = pr.first; - static_cast(assets.back()) = pr.second; - } - return true; + return m_custom_assets; } //---------------------------------------------------------------------------------------------------- +const std::unordered_map& wallet2::get_global_whitelist() const +{ + return m_whitelisted_assets; +} +//---------------------------------------------------------------------------------------------------- +const std::unordered_map& wallet2::get_own_assets() const +{ + return m_own_asset_descriptors; +} + //---------------------------------------------------------------------------------------------------- bool wallet2::load_whitelisted_tokens() const { if(!m_use_assets_whitelisting) @@ -3775,7 +3782,7 @@ std::string wallet2::get_balance_str_raw() const for(const auto& entry : m_own_asset_descriptors) { - ss << " " << std::left << entry.first << " " << entry.second.asset_descriptor.ticker << ENDL; + ss << " " << std::left << entry.first << " " << entry.second.ticker << ENDL; } return ss.str(); @@ -4252,6 +4259,11 @@ bool wallet2::is_in_hardfork_zone(uint64_t hardfork_index) const return m_core_runtime_config.is_hardfork_active_for_height(hardfork_index, get_blockchain_current_size()); } //---------------------------------------------------------------------------------------------------- +bool wallet2::proxy_to_daemon(const std::string& uri, const std::string& body, int& response_code, std::string& response_body) +{ + return m_core_proxy->call_COMMAND_RPC_INVOKE(uri, body, response_code, response_body); +} +//---------------------------------------------------------------------------------------------------- bool wallet2::prepare_and_sign_pos_block(const mining_context& cxt, uint64_t full_block_reward, const currency::pos_entry& pe, currency::tx_generation_context& miner_tx_tgc, currency::block& b) const { bool r = false; diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index da47141b..1b0c2892 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -397,7 +397,6 @@ namespace tools void transfer_asset_ownership(const crypto::public_key asset_id, const crypto::public_key& new_owner, currency::transaction& result_tx); bool daemon_get_asset_info(const crypto::public_key& asset_id, currency::asset_descriptor_base& adb); - const std::unordered_map& get_own_assets() const { return m_own_asset_descriptors; } bool set_core_proxy(const std::shared_ptr& proxy); void set_pos_utxo_count_limits_for_defragmentation_tx(uint64_t min_outs, uint64_t max_outs); // don't create UTXO defrag. tx if there are less than 'min_outs' outs; don't put more than 'max_outs' outs void set_pos_decoys_count_for_defragmentation_tx(size_t decoys_count); @@ -659,10 +658,14 @@ namespace tools bool add_custom_asset_id(const crypto::public_key& asset_id, currency::asset_descriptor_base& asset_descriptor); bool delete_custom_asset_id(const crypto::public_key& asset_id); - bool get_custom_assets(std::list& assets) const; + const std::unordered_map& get_local_whitelist() const; + const std::unordered_map& get_global_whitelist() const; + const std::unordered_map& get_own_assets() const; + bool load_whitelisted_tokens_if_not_loaded() const; bool load_whitelisted_tokens() const; + void set_connectivity_options(unsigned int timeout); /* @@ -696,6 +699,9 @@ namespace tools bool encrypt_buffer(const std::string& buff, std::string& res_buff); bool decrypt_buffer(const std::string& buff, std::string& res_buff); bool is_in_hardfork_zone(uint64_t hardfork_index) const; + + //performance inefficient call, suitable only for rare ocasions or super lazy developers + bool proxy_to_daemon(const std::string& uri, const std::string& body, int& response_code, std::string& response_body); construct_tx_param get_default_construct_tx_param(); diff --git a/src/wallet/wallet2_base.h b/src/wallet/wallet2_base.h index d9c9589c..c2ec860b 100644 --- a/src/wallet/wallet2_base.h +++ b/src/wallet/wallet2_base.h @@ -251,19 +251,18 @@ namespace tools crypto::public_key asset_id = currency::null_pkey; BEGIN_BOOST_SERIALIZATION() BOOST_SERIALIZE(asset_id) - END_BOOST_SERIALIZATION() + END_BOOST_SERIALIZATION() }; - struct wallet_own_asset_context + struct wallet_own_asset_context: public currency::asset_descriptor_base { - currency::asset_descriptor_base asset_descriptor; bool thirdparty_custody = false; BEGIN_BOOST_SERIALIZATION() - BOOST_SERIALIZE(asset_descriptor) + BOOST_SERIALIZE_BASE_CLASS(currency::asset_descriptor_base) BOOST_SERIALIZE(thirdparty_custody) - END_BOOST_SERIALIZATION() + END_BOOST_SERIALIZATION() }; struct asset_update_event diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 6db3db3b..59d3f110 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -14,8 +14,12 @@ #include "currency_core/bc_escrow_service.h" #include "rpc/core_rpc_server_commands_defs.h" + + const uint64_t WALLET_GLOBAL_OUTPUT_INDEX_UNDEFINED = std::numeric_limits::max(); +const boost::uuids::uuid RPC_INTERNAL_UI_CONTEXT = {0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 2, 1, 0, 0}; //Bender's nightmare + namespace tools { namespace wallet_public @@ -1697,6 +1701,31 @@ namespace wallet_public }; }; + struct COMMAND_PROXY_TO_DAEMON + { + struct request + { + + std::string uri; + std::string base64_body; //base64 encoded body + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(uri) + KV_SERIALIZE(base64_body) + END_KV_SERIALIZE_MAP() + }; + + struct response + { + std::string base64_body; //base64 encoded response body + int32_t response_code; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(base64_body) + KV_SERIALIZE(response_code) + END_KV_SERIALIZE_MAP() + }; + }; struct assets_whitelist { @@ -1749,10 +1778,15 @@ namespace wallet_public struct response { - std::list assets; + std::list local_whitelist; + std::list global_whitelist; + std::list own_assets; + BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(assets) + KV_SERIALIZE(local_whitelist) + KV_SERIALIZE(global_whitelist) + KV_SERIALIZE(own_assets) END_KV_SERIALIZE_MAP() }; }; diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 605ffed5..bd157d01 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -261,7 +261,7 @@ namespace tools //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::handle_http_request(const epee::net_utils::http::http_request_info& query_info, epee::net_utils::http::http_response_info& response, connection_context& m_conn_context) { - if (m_jwt_secret.size()) + if (m_jwt_secret.size() && m_conn_context.m_connection_id != RPC_INTERNAL_UI_CONTEXT) { if (!auth_http_request(query_info, response, m_conn_context)) { @@ -301,6 +301,11 @@ namespace tools m_jwt_secret = jwt; } //------------------------------------------------------------------------------------------------------------------------------ + const std::string& wallet_rpc_server::get_jwt_secret() + { + return m_jwt_secret; + } + //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_getbalance(const wallet_public::COMMAND_RPC_GET_BALANCE::request& req, wallet_public::COMMAND_RPC_GET_BALANCE::response& res, epee::json_rpc::error& er, connection_context& cntx) { WALLET_RPC_BEGIN_TRY_ENTRY(); @@ -1108,7 +1113,13 @@ namespace tools bool wallet_rpc_server::on_assets_whitelist_get(const wallet_public::COMMAND_ASSETS_WHITELIST_GET::request& req, wallet_public::COMMAND_ASSETS_WHITELIST_GET::response& res, epee::json_rpc::error& er, connection_context& cntx) { WALLET_RPC_BEGIN_TRY_ENTRY(); - w.get_wallet()->get_custom_assets(res.assets); + + currency::assets_map_to_assets_list(res.local_whitelist, w.get_wallet()->get_local_whitelist()); + currency::assets_map_to_assets_list(res.global_whitelist, w.get_wallet()->get_global_whitelist()); + currency::assets_map_to_assets_list(res.own_assets, w.get_wallet()->get_own_assets()); + + const auto global_whitelist = w.get_wallet()->get_global_whitelist(); + return true; WALLET_RPC_CATCH_TRY_ENTRY(); } @@ -1193,6 +1204,18 @@ namespace tools WALLET_RPC_CATCH_TRY_ENTRY(); } //------------------------------------------------------------------------------------------------------------------------------ + bool wallet_rpc_server::on_proxy_to_daemon(const wallet_public::COMMAND_PROXY_TO_DAEMON::request& req, wallet_public::COMMAND_PROXY_TO_DAEMON::response& res, epee::json_rpc::error& er, connection_context& cntx) + { + WALLET_RPC_BEGIN_TRY_ENTRY(); + std::string buff = epee::string_encoding::base64_decode(req.base64_body); + + w.get_wallet()->proxy_to_daemon(req.uri, buff, res.response_code, res.base64_body); + + res.base64_body = epee::string_encoding::base64_encode(res.base64_body); + return true; + WALLET_RPC_CATCH_TRY_ENTRY(); + } + //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_decrypt_data(const wallet_public::COMMAND_DECRYPT_DATA::request& req, wallet_public::COMMAND_DECRYPT_DATA::response& res, epee::json_rpc::error& er, connection_context& cntx) { WALLET_RPC_BEGIN_TRY_ENTRY(); diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h index fc0e60be..86faf178 100644 --- a/src/wallet/wallet_rpc_server.h +++ b/src/wallet/wallet_rpc_server.h @@ -90,6 +90,7 @@ namespace tools bool run(bool do_mint, bool offline_mode, const currency::account_public_address& miner_address); bool handle_http_request(const epee::net_utils::http::http_request_info& query_info, epee::net_utils::http::http_response_info& response, connection_context& m_conn_context); void set_jwt_secret(const std::string& jwt); + const std::string& get_jwt_secret(); BEGIN_URI_MAP2_VIRTUAL() BEGIN_JSON_RPC_MAP("/json_rpc") @@ -149,8 +150,11 @@ namespace tools MAP_JON_RPC_WE("sign_message", on_sign_message, wallet_public::COMMAND_SIGN_MESSAGE) MAP_JON_RPC_WE("encrypt_data", on_encrypt_data, wallet_public::COMMAND_ENCRYPT_DATA) MAP_JON_RPC_WE("decrypt_data", on_decrypt_data, wallet_public::COMMAND_DECRYPT_DATA) - END_JSON_RPC_MAP() - END_URI_MAP2() + + //utility call + MAP_JON_RPC_WE("proxy_to_daemon", on_proxy_to_daemon, wallet_public::COMMAND_PROXY_TO_DAEMON) + END_JSON_RPC_MAP() + END_URI_MAP2() bool auth_http_request(const epee::net_utils::http::http_request_info& query_info, epee::net_utils::http::http_response_info& response, connection_context& m_conn_context); //json_rpc @@ -209,6 +213,7 @@ namespace tools bool on_encrypt_data(const wallet_public::COMMAND_ENCRYPT_DATA::request& req, wallet_public::COMMAND_ENCRYPT_DATA::response& res, epee::json_rpc::error& er, connection_context& cntx); bool on_decrypt_data(const wallet_public::COMMAND_DECRYPT_DATA::request& req, wallet_public::COMMAND_DECRYPT_DATA::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_proxy_to_daemon(const wallet_public::COMMAND_PROXY_TO_DAEMON::request& req, wallet_public::COMMAND_PROXY_TO_DAEMON::response& res, epee::json_rpc::error& er, connection_context& cntx); //std::shared_ptr get_wallet(); diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index c1edabff..045ba196 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -546,13 +546,12 @@ bool wallets_manager::init_local_daemon() CHECK_AND_ASSERT_AND_SET_GUI(res, "Failed to initialize core rpc server."); LOG_PRINT_GREEN("Core rpc server initialized OK on port: " << m_rpc_server.get_binded_port(), LOG_LEVEL_0); + m_ui_opt.rpc_port = m_rpc_server.get_binded_port(); + + //chain calls to rpc server m_prpc_chain_handler = &m_wallet_rpc_server; //disable this for main net until we get full support of authentication with network -#ifdef TESTNET - m_rpc_server.set_rpc_chain_handler(this); -#endif - LOG_PRINT_L0("Starting core rpc server..."); //dsi.text_state = "Starting core rpc server"; @@ -572,6 +571,23 @@ bool wallets_manager::init_local_daemon() return true; } +std::string wallets_manager::setup_wallet_rpc(const std::string& jwt_secret) +{ + if (!jwt_secret.size()) + { + //disabling wallet RPC + m_rpc_server.set_rpc_chain_handler(nullptr); + return WALLET_RPC_STATUS_OK; + } + + //we don't override command line JWT secret + if(!m_wallet_rpc_server.get_jwt_secret().size() ) + m_wallet_rpc_server.set_jwt_secret(jwt_secret); + + m_rpc_server.set_rpc_chain_handler(this); + return WALLET_RPC_STATUS_OK; +} + bool wallets_manager::deinit_local_daemon() { #ifndef MOBILE_WALLET_BUILD @@ -2103,7 +2119,6 @@ bool wallets_manager::on_mw_select_wallet(const tools::wallet_public::COMMAND_MW return true; } - void wallets_manager::lock() { #ifndef MOBILE_WALLET_BUILD diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index a19e8138..d07c3000 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -146,6 +146,8 @@ public: std::string get_fav_offers(const std::list& hashes, const bc_services::core_offers_filter& filter, std::list& offers); std::string get_tx_pool_info(currency::COMMAND_RPC_GET_POOL_INFO::response& res); std::string export_wallet_history(const view::export_wallet_info& ewi); + std::string setup_wallet_rpc(const std::string& jwt_secret); + #ifndef MOBILE_WALLET_BUILD currency::core_rpc_server& get_rpc_server() { return m_rpc_server; } #endif