From c03438ba231cd9aa9185e4196f393f1a169e9434 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 19 Mar 2024 17:54:41 +0100 Subject: [PATCH] fixed mw_get_wallets for simplewallet, fail-resistant whitelisti loading --- src/simplewallet/simplewallet.cpp | 17 ++++++++ src/wallet/wallet2.cpp | 5 ++- src/wallet/wallet_rpc_server.cpp | 3 ++ src/wallet/wallets_manager.cpp | 2 +- tests/performance_tests/main.cpp | 70 ++++++++----------------------- 5 files changed, 42 insertions(+), 55 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 681d356f..0cd51835 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -2816,6 +2816,22 @@ int main(int argc, char* argv[]) break; } //try to sync it + struct wallet_rpc_local_callback : public tools::i_wallet2_callback + { + std::shared_ptr m_wlt_ptr; + wallet_rpc_local_callback(std::shared_ptr ptr): m_wlt_ptr(ptr) + {} + virtual void on_mw_get_wallets(std::vector& wallets) + { + wallets.push_back(tools::wallet_public::wallet_entry_info()); + wallets.back().wallet_id = 0; + tools::get_wallet_info(*m_wlt_ptr, wallets.back().wi); + } + + }; + + std::shared_ptr callback(new wallet_rpc_local_callback(wallet_ptr)); + while (true) { try @@ -2828,6 +2844,7 @@ int main(int argc, char* argv[]) return EXIT_FAILURE; wal.set_use_assets_whitelisting(true); + wal.callback(callback); if (!offline_mode) wal.refresh(); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 575a082f..200f5469 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3617,9 +3617,10 @@ bool wallet2::load_whitelisted_tokens() const for (auto it = aw.assets.begin(); it != aw.assets.end(); it++) { m_whitelisted_assets[it->asset_id] = static_cast(*it); - } + } + return true; } - return true; + return false; } //---------------------------------------------------------------------------------------------------- bool wallet2::load_whitelisted_tokens_if_not_loaded() const diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index bd157d01..ddd09634 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -17,7 +17,10 @@ using namespace epee; #include "wallet_rpc_server_error_codes.h" #include "wallet_helpers.h" #include "wrap_service.h" +PUSH_VS_WARNINGS +DISABLE_VS_WARNINGS(4244) #include "jwt-cpp/jwt.h" +POP_VS_WARNINGS #include "crypto/bitcoin/sha256_helper.h" #define JWT_TOKEN_EXPIRATION_MAXIMUM (60 * 60) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 33d1cb03..cce0066b 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1043,7 +1043,6 @@ std::string wallets_manager::open_wallet(const std::wstring& path, const std::st std::shared_ptr w(new tools::wallet2()); w->set_use_deffered_global_outputs(m_use_deffered_global_outputs); - w->set_use_assets_whitelisting(true); owr.wallet_id = m_wallet_id_counter++; w->callback(std::shared_ptr(new i_wallet_to_i_backend_adapter(this, owr.wallet_id))); @@ -1075,6 +1074,7 @@ std::string wallets_manager::open_wallet(const std::wstring& path, const std::st w->get_recent_transfers_history(owr.recent_history.history, 0, txs_to_return, owr.recent_history.total_history_items, owr.recent_history.last_item_index, exclude_mining_txs); //w->get_unconfirmed_transfers(owr.recent_history.unconfirmed); w->get_unconfirmed_transfers(owr.recent_history.history, exclude_mining_txs); + w->set_use_assets_whitelisting(true); owr.wallet_local_bc_size = w->get_blockchain_current_size(); //workaround for missed fee diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index ed6d991e..6d435955 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -26,61 +26,19 @@ #include "threads_pool_tests.h" #include "wallet/plain_wallet_api.h" #include "wallet/view_iface.h" -#include +PUSH_VS_WARNINGS +DISABLE_VS_WARNINGS(4244) +#include "jwt-cpp/jwt.h" +POP_VS_WARNINGS void test_plain_wallet() { - - std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoiemFub19leHRlbnNpb24iLCJzYWx0IjoiYTUyMTk5MzQyNmYxN2Y2MDQyMzkzYTI4YzJhMzk1NjFiYTgxYmVkZDkxODJlY2E5NTY3ZDBlNjQ3YjIwZTE2NSIsImV4cCI6MTcxMDM2MzA1MH0.CwqvPBtgE8ZUFZ4cYy1ZJLWdYCnhfEiCzEhqDYCK4CQ"; - auto decoded_token = jwt::decode(token); - - std::string sharedSecret = "DFDvfedceEDCECECecedcyhtyh"; - - try - { - auto decoded = jwt::decode(token); - - auto verifier = jwt::verify() - .allow_algorithm(jwt::algorithm::hs256 { sharedSecret }); - - verifier.verify(decoded); - - std::cout << "Token is valid. Claims:" << std::endl; - for(auto& e : decoded.get_payload_json()) - std::cout << e.first << " = " << e.second << std::endl; - } - catch(const std::exception& e) - { - std::cerr << "Invalid token: " << e.what() << std::endl; - } - - - /* - auto verifier = jwt::verify() - .with_issuer("auth0") - .with_claim("sample", jwt::claim(std::string("test"))) - .allow_algorithm(jwt::algorithm::hs256 { "secret" }); - - verifier.verify(decoded_token); - - auto token = jwt::create() - .set_type("JWS") - .set_issuer("auth0") - .set_payload_claim("sample", jwt::claim(std::string("test"))) - .sign(jwt::algorithm::hs256 { "secret" }); - -*/ - return; - - - - - std::string res = plain_wallet::init("195.201.107.230", "33336", "E:\\tmp\\", 0); + std::string res = plain_wallet::init("195.201.107.230", "33336", "C:\\Users\\roky\\home\\", 0); uint64_t instance_id = 0; - res = plain_wallet::open("test.zan", "111"); + res = plain_wallet::open("SEGA_2", "Test2"); while(true) { epee::misc_utils::sleep_no_w(2000); @@ -95,6 +53,14 @@ void test_plain_wallet() std::string invoke_body = "{\"method\":\"get_recent_txs_and_info\",\"params\":{\"offset\":0,\"count\":30,\"update_provision_info\":true}}"; res = plain_wallet::sync_call("invoke", instance_id, invoke_body); + + invoke_body = "{\"method\":\"assets_whitelist_get\",\"params\":{}}"; + + res = plain_wallet::sync_call("invoke", instance_id, invoke_body); + + + res = plain_wallet::close_wallet(instance_id); + LOG_PRINT_L0(res); } @@ -104,10 +70,10 @@ int main(int argc, char** argv) { epee::string_tools::set_module_name_and_folder(argv[0]); epee::log_space::get_set_log_detalisation_level(true, LOG_LEVEL_2); - epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2); - epee::log_space::log_singletone::add_logger(LOGGER_FILE, - epee::log_space::log_singletone::get_default_log_file().c_str(), - epee::log_space::log_singletone::get_default_log_folder().c_str()); + //epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2); + //epee::log_space::log_singletone::add_logger(LOGGER_FILE, + // epee::log_space::log_singletone::get_default_log_file().c_str(), + // epee::log_space::log_singletone::get_default_log_folder().c_str()); test_plain_wallet(); //parse_weird_tx();