From 11e183609636cfc9a727f64efe6e2330ff9609ba Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 1 Dec 2022 19:05:17 +0100 Subject: [PATCH 01/21] fixed bug with inflating balances array --- src/wallet/wallet2.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 163fdb24..51cfb030 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3145,6 +3145,7 @@ bool wallet2::balance(std::unordered_map& balances, uint64_t& mined) const { load_whitelisted_tokens_if_not_loaded(); + balances.clear(); std::unordered_map balances_map; this->balance(balances_map, mined); for (const auto& item : balances_map) From a14dcb4e8a6ab7b87758231bef159e7d00f44928 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 2 Dec 2022 15:24:50 +0100 Subject: [PATCH 02/21] implemented add/remove custom assets --- src/simplewallet/simplewallet.cpp | 61 ++++++++++++++++++++++++++++++- src/simplewallet/simplewallet.h | 3 ++ src/wallet/wallet2.cpp | 43 +++++++++++++++------- src/wallet/wallet2.h | 2 +- 4 files changed, 94 insertions(+), 15 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index e2d5d605..e3d3019a 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -226,6 +226,8 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("tor_enable", boost::bind(&simple_wallet::tor_enable, this, _1), "Enable relaying transactions over TOR network(enabled by default)"); m_cmd_binder.set_handler("tor_disable", boost::bind(&simple_wallet::tor_disable, this, _1), "Enable relaying transactions over TOR network(enabled by default)"); m_cmd_binder.set_handler("deploy_new_asset", boost::bind(&simple_wallet::deploy_new_asset, this, _1), "Deploys new asset in the network, with current wallet as a maintainer"); + m_cmd_binder.set_handler("add_custom_asset_id", boost::bind(&simple_wallet::add_custom_asset_id, this, _1), "Approve asset id to be recognized in the wallet and returned in balances"); + m_cmd_binder.set_handler("remove_custom_asset_id", boost::bind(&simple_wallet::remove_custom_asset_id, this, _1), "Cancel previously made approval for asset id"); } //---------------------------------------------------------------------------------------------------- @@ -1790,7 +1792,7 @@ bool simple_wallet::deploy_new_asset(const std::vector &args) asset_descriptor_base adb = AUTO_VAL_INIT(adb); if (!args.size() || args.size() > 1) { - fail_msg_writer() << "invalid agruments count: " << args.size() << ", expected 1"; + fail_msg_writer() << "invalid arguments count: " << args.size() << ", expected 1"; } bool r = epee::serialization::load_t_from_json_file(adb, args[0]); if (!r) @@ -1818,6 +1820,63 @@ bool simple_wallet::deploy_new_asset(const std::vector &args) return true; } //---------------------------------------------------------------------------------------------------- +bool simple_wallet::add_custom_asset_id(const std::vector &args) +{ + if (!args.size() || args.size() > 1) + { + fail_msg_writer() << "invalid arguments count: " << args.size() << ", expected 1"; + } + crypto::hash asset_id = currency::null_hash; + if (!epee::string_tools::parse_tpod_from_hex_string(args[0], asset_id)) + { + fail_msg_writer() << "expected valid asset_id"; + return true; + } + asset_descriptor_base asset_descriptor = AUTO_VAL_INIT(asset_descriptor); + bool r = m_wallet->add_custom_asset_id(asset_id, asset_descriptor); + if(!r) + { + fail_msg_writer() << "Asset id " << asset_id << " not found as registered asset"; + return true; + } + else + { + success_msg_writer() << "Added custom asset:" << ENDL + << " Id: " << asset_id << ENDL + << " Title: " << asset_descriptor.full_name << ENDL + << " Ticker: " << asset_descriptor.ticker << ENDL + << " Ticker: " << print_fixed_decimal_point(asset_descriptor.current_supply, asset_descriptor.decimal_point) << ENDL + ; + } + return true; +} +//---------------------------------------------------------------------------------------------------- +bool simple_wallet::remove_custom_asset_id(const std::vector &args) +{ + if (!args.size() || args.size() > 1) + { + fail_msg_writer() << "invalid arguments count: " << args.size() << ", expected 1"; + } + crypto::hash asset_id = currency::null_hash; + if (!epee::string_tools::parse_tpod_from_hex_string(args[0], asset_id)) + { + fail_msg_writer() << "expected valid asset_id"; + return true; + } + + bool r = m_wallet->delete_custom_asset_id(asset_id); + if (!r) + { + fail_msg_writer() << "Asset id " << asset_id << " not present in this wallet"; + return true; + } + else + { + success_msg_writer() << "Asset id " << asset_id << " removed from wallet custom list" << ENDL; + } + return true; +} +//---------------------------------------------------------------------------------------------------- bool simple_wallet::sweep_below(const std::vector &args) { bool r = false; diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 6c92c634..47cc4bfd 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -89,6 +89,9 @@ namespace currency bool tor_enable(const std::vector &args); bool tor_disable(const std::vector &args); bool deploy_new_asset(const std::vector &args); + bool add_custom_asset_id(const std::vector &args); + bool remove_custom_asset_id(const std::vector &args); + bool validate_wrap_status(uint64_t amount); bool get_alias_from_daemon(const std::string& alias_name, currency::extra_alias_entry_base& ai); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 51cfb030..7c844b97 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3148,17 +3148,25 @@ bool wallet2::balance(std::list& balances, u balances.clear(); std::unordered_map balances_map; this->balance(balances_map, mined); + std::unordered_map custom_assets_local = m_custom_assets; + + for (auto& own_asset : m_own_asset_descriptors) + { + custom_assets_local[own_asset.first] = own_asset.second.asset_descriptor; + } + + asset_descriptor_base native_asset_info = AUTO_VAL_INIT(native_asset_info); + native_asset_info.full_name = CURRENCY_NAME_SHORT_BASE; + native_asset_info.ticker = CURRENCY_NAME_ABR; + native_asset_info.decimal_point = CURRENCY_DISPLAY_DECIMAL_POINT; + for (const auto& item : balances_map) { - asset_descriptor_base native_asset_info = AUTO_VAL_INIT(native_asset_info); - native_asset_info.full_name = CURRENCY_NAME_SHORT_BASE; - native_asset_info.ticker = CURRENCY_NAME_ABR; - native_asset_info.decimal_point = CURRENCY_DISPLAY_DECIMAL_POINT; - const asset_descriptor_base* asset_ptr = nullptr; + asset_descriptor_base asset_info = AUTO_VAL_INIT(asset_info); //check if asset is whitelisted or customly added if (item.first == currency::null_hash) { - asset_ptr = &native_asset_info; + asset_info = native_asset_info; } else { @@ -3166,27 +3174,35 @@ bool wallet2::balance(std::list& balances, u if (it == m_whitelisted_assets.end()) { //check if it custom asset - auto it_cust = m_custom_assets.find(item.first); - if (it_cust == m_custom_assets.end()) + auto it_cust = custom_assets_local.find(item.first); + if (it_cust == custom_assets_local.end()) { continue; } else { - asset_ptr = &it_cust->second; + asset_info = it_cust->second; + custom_assets_local.erase(it_cust); } } else { - asset_ptr = &it->second; + asset_info = it->second; } } balances.push_back(wallet_public::asset_balance_entry()); wallet_public::asset_balance_entry& new_item = balances.back(); static_cast(new_item) = item.second; new_item.asset_info.asset_id = item.first; - CHECK_AND_ASSERT_THROW_MES(asset_ptr, "Internal error: asset_ptr i nullptr"); - static_cast(new_item.asset_info) = *asset_ptr; + static_cast(new_item.asset_info) = asset_info; + } + //manually added assets should be always present, at least as zero balanced items + for (auto& asset : custom_assets_local) + { + balances.push_back(wallet_public::asset_balance_entry()); + wallet_public::asset_balance_entry& new_item = balances.back(); + new_item.asset_info.asset_id = asset.first; + static_cast(new_item.asset_info) = asset.second; } return true; @@ -3198,7 +3214,7 @@ uint64_t wallet2::balance() const return balance(stub, stub, stub, stub); } //---------------------------------------------------------------------------------------------------- -bool wallet2::add_custom_asset_id(const crypto::hash& asset_id) +bool wallet2::add_custom_asset_id(const crypto::hash& asset_id, asset_descriptor_base& asset_descriptor) { currency::COMMAND_RPC_GET_ASSET_INFO::request req = AUTO_VAL_INIT(req); currency::COMMAND_RPC_GET_ASSET_INFO::response resp = AUTO_VAL_INIT(resp); @@ -3207,6 +3223,7 @@ bool wallet2::add_custom_asset_id(const crypto::hash& asset_id) if (resp.status == API_RETURN_CODE_OK) { m_custom_assets[asset_id] = resp.asset_descriptor; + asset_descriptor = resp.asset_descriptor; return true; } return false; diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 8a458de4..529b78a1 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -899,7 +899,7 @@ namespace tools uint64_t get_default_fee() {return TX_DEFAULT_FEE;} void export_transaction_history(std::ostream& ss, const std::string& format, bool include_pos_transactions = true); - bool add_custom_asset_id(const crypto::hash& asset_id); + bool add_custom_asset_id(const crypto::hash& asset_id, currency::asset_descriptor_base& asset_descriptor); bool delete_custom_asset_id(const crypto::hash& asset_id); bool load_whitelisted_tokens_if_not_loaded() const; bool load_whitelisted_tokens()const; From 65e5ad4f9f0ad4d8575c88bacd0a68636b8a8dee Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 2 Dec 2022 15:28:03 +0100 Subject: [PATCH 03/21] moved to lates UI code --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 14def6ae..3471178c 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 14def6aef99d4f10e81990e2055a7cf490f2e797 +Subproject commit 3471178cf9a40a16933d7000d7b4f171e03b446a From 3a46bf3a444715d3558b2aafc9ec02158036dab3 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 2 Dec 2022 15:29:07 +0100 Subject: [PATCH 04/21] tor-connect moved to latest commits --- contrib/tor-connect | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/tor-connect b/contrib/tor-connect index 13f47143..4db19f54 160000 --- a/contrib/tor-connect +++ b/contrib/tor-connect @@ -1 +1 @@ -Subproject commit 13f47143c0dcb8c12cfa293efc9d6d57ad3d1e37 +Subproject commit 4db19f5422bd59264e4d274e4fdcbedb4a284bef From 464818fb7f136bfd413cf7327b9afbbc6d8b4a53 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 2 Dec 2022 22:29:23 +0100 Subject: [PATCH 05/21] added api for adding/removing assets via UI --- src/gui/qt-daemon/application/mainwindow.cpp | 21 ++++++++++++++++++++ src/gui/qt-daemon/application/mainwindow.h | 5 ++++- src/rpc/core_rpc_server_commands_defs.h | 19 ++++++++++-------- src/simplewallet/simplewallet.cpp | 2 +- src/wallet/view_iface.h | 21 +++++++++++++++----- src/wallet/wallet2.cpp | 6 +++++- src/wallet/wallets_manager.cpp | 19 +++++++++++++++++- src/wallet/wallets_manager.h | 5 ++++- 8 files changed, 80 insertions(+), 18 deletions(-) diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index dcb5f2b6..468b8aaf 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -2127,6 +2127,27 @@ QString MainWindow::get_mining_estimate(const QString& param) return MAKE_RESPONSE(ar); CATCH_ENTRY_FAIL_API_RESPONCE(); } +QString MainWindow::add_custom_asset_id(const QString& param) +{ + TRY_ENTRY(); + LOG_API_TIMING(); + PREPARE_ARG_FROM_JSON(view::wallet_and_asset_id, waid); + PREPARE_RESPONSE(currency::COMMAND_RPC_GET_ASSET_INFO::response, ar); + + ar.error_code = m_backend.add_custom_asset_id(waid.wallet_id, waid.asset_id, ar.response_data.asset_descriptor); + ar.response_data.status = ar.error_code; + return MAKE_RESPONSE(ar); + CATCH_ENTRY_FAIL_API_RESPONCE(); +} +QString MainWindow::remove_custom_asset_id(const QString& param) +{ + TRY_ENTRY(); + LOG_API_TIMING(); + PREPARE_ARG_FROM_JSON(view::wallet_and_asset_id, waid); + default_ar.error_code = m_backend.delete_custom_asset_id(waid.wallet_id, waid.asset_id); + return MAKE_RESPONSE(default_ar); + CATCH_ENTRY_FAIL_API_RESPONCE(); +} QString MainWindow::backup_wallet_keys(const QString& param) { TRY_ENTRY(); diff --git a/src/gui/qt-daemon/application/mainwindow.h b/src/gui/qt-daemon/application/mainwindow.h index 98a3d03b..64bdd6d3 100644 --- a/src/gui/qt-daemon/application/mainwindow.h +++ b/src/gui/qt-daemon/application/mainwindow.h @@ -168,7 +168,10 @@ public: QString get_default_fee(); QString get_options(); void bool_toggle_icon(const QString& param); - + QString add_custom_asset_id(const QString& param); + QString remove_custom_asset_id(const QString& param); + + bool get_is_disabled_notifications(); bool set_is_disabled_notifications(const bool& param); QString export_wallet_history(const QString& param); diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index b611cb52..ce904da3 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -82,16 +82,19 @@ namespace currency }; }; + struct asset_id_kv + { + crypto::hash asset_id; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE_POD_AS_HEX_STRING(asset_id) + END_KV_SERIALIZE_MAP() + }; + + struct COMMAND_RPC_GET_ASSET_INFO { - struct request - { - crypto::hash asset_id; - - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE_POD_AS_HEX_STRING(asset_id) - END_KV_SERIALIZE_MAP() - }; + typedef asset_id_kv request; struct response { diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index e3d3019a..246ed80a 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -766,7 +766,7 @@ bool simple_wallet::show_balance(const std::vector& args/* = std::v std::stringstream ss; for (const tools::wallet_public::asset_balance_entry& b : balances) { - ss << std::setw(21) << print_fixed_decimal_point(b.total, b.asset_info.decimal_point) << "\t" << b.asset_info.ticker << ENDL; + ss << std::setw(21) << print_fixed_decimal_point(b.total, b.asset_info.decimal_point) << "\t" << b.asset_info.ticker << "\t" << b.asset_info.asset_id << ENDL; } success_msg_writer() << "Balance: " << ENDL << ss.str(); return true; diff --git a/src/wallet/view_iface.h b/src/wallet/view_iface.h index 70d60bfe..16b82069 100644 --- a/src/wallet/view_iface.h +++ b/src/wallet/view_iface.h @@ -426,10 +426,10 @@ public: struct get_recent_transfers_request { - uint64_t wallet_id; - uint64_t offset; - uint64_t count; - bool exclude_mining_txs; + uint64_t wallet_id = 0; + uint64_t offset = 0; + uint64_t count = 0; + bool exclude_mining_txs = false; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(wallet_id) @@ -439,9 +439,20 @@ public: END_KV_SERIALIZE_MAP() }; + struct wallet_and_asset_id + { + uint64_t wallet_id = 0; + crypto::hash asset_id = currency::null_hash; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(wallet_id) + KV_SERIALIZE_POD_AS_HEX_STRING(asset_id) + END_KV_SERIALIZE_MAP() + }; + struct reset_pass_request { - uint64_t wallet_id; + uint64_t wallet_id = 0; std::string pass; BEGIN_KV_SERIALIZE_MAP() diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 7c844b97..84c3435e 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3152,7 +3152,10 @@ bool wallet2::balance(std::list& balances, u for (auto& own_asset : m_own_asset_descriptors) { - custom_assets_local[own_asset.first] = own_asset.second.asset_descriptor; + if (m_whitelisted_assets.find(own_asset.first) == m_whitelisted_assets.end()) + { + custom_assets_local[own_asset.first] = own_asset.second.asset_descriptor; + } } asset_descriptor_base native_asset_info = AUTO_VAL_INIT(native_asset_info); @@ -3218,6 +3221,7 @@ bool wallet2::add_custom_asset_id(const crypto::hash& asset_id, asset_descriptor { currency::COMMAND_RPC_GET_ASSET_INFO::request req = AUTO_VAL_INIT(req); currency::COMMAND_RPC_GET_ASSET_INFO::response resp = AUTO_VAL_INIT(resp); + req.asset_id = asset_id; bool r = m_core_proxy->call_COMMAND_RPC_GET_ASSET_INFO(req, resp); if (resp.status == API_RETURN_CODE_OK) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index ac3c266e..31e37d80 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1361,7 +1361,7 @@ std::string wallets_manager::request_alias_update(const currency::alias_rpc_deta } -std::string wallets_manager::transfer(size_t wallet_id, const view::transfer_params& tp, currency::transaction& res_tx) +std::string wallets_manager::transfer(uint64_t wallet_id, const view::transfer_params& tp, currency::transaction& res_tx) { std::vector dsts; @@ -1675,6 +1675,23 @@ std::string wallets_manager::reset_wallet_password(uint64_t wallet_id, const std else return API_RETURN_CODE_FAIL; } +std::string wallets_manager::add_custom_asset_id(uint64_t wallet_id, const crypto::hash& asset_id, currency::asset_descriptor_base& asset_descriptor) +{ + GET_WALLET_OPT_BY_ID(wallet_id, w); + if(w.w->get()->add_custom_asset_id(asset_id, asset_descriptor)) + return API_RETURN_CODE_OK; + else + return API_RETURN_CODE_FAIL; +} +std::string wallets_manager::delete_custom_asset_id(uint64_t wallet_id, const crypto::hash& asset_id) +{ + GET_WALLET_OPT_BY_ID(wallet_id, w); + if (w.w->get()->delete_custom_asset_id(asset_id)) + return API_RETURN_CODE_OK; + else + return API_RETURN_CODE_FAIL; + +} std::string wallets_manager::is_wallet_password_valid(uint64_t wallet_id, const std::string& pass) { GET_WALLET_OPT_BY_ID(wallet_id, w); diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index 45dec851..8f09475f 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -148,7 +148,7 @@ public: std::vector& days); std::string is_pos_allowed(); void toggle_pos_mining(); - std::string transfer(size_t wallet_id, const view::transfer_params& tp, currency::transaction& res_tx); + std::string transfer(uint64_t wallet_id, const view::transfer_params& tp, currency::transaction& res_tx); std::string get_config_folder(); std::string is_valid_brain_restore_data(const std::string& seed_phrase, const std::string& seed_password); std::string get_seed_phrase_info(const std::string& seed_phrase, const std::string& seed_password, view::seed_phrase_info& result); @@ -162,6 +162,9 @@ public: std::string get_qt_dev_tools_option() const { return m_qt_dev_tools; } void set_use_deffered_global_outputs(bool use) { m_use_deffered_global_outputs = use; } bool set_use_tor(bool use_tor); + std::string add_custom_asset_id(uint64_t wallet_id, const crypto::hash& asset_id, currency::asset_descriptor_base& asset_descriptor); + std::string delete_custom_asset_id(uint64_t wallet_id, const crypto::hash& asset_id); + private: void main_worker(const po::variables_map& vm); bool init_local_daemon(); From 65cfb4910f59ff8f19c0788bd3fd6ac1877f0d36 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 3 Dec 2022 20:59:51 +0100 Subject: [PATCH 06/21] moved to latest tor-connect commit --- contrib/tor-connect | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/tor-connect b/contrib/tor-connect index 4db19f54..b589edb1 160000 --- a/contrib/tor-connect +++ b/contrib/tor-connect @@ -1 +1 @@ -Subproject commit 4db19f5422bd59264e4d274e4fdcbedb4a284bef +Subproject commit b589edb1906dccb387cfeded6ed12286c5f0405f From 18ec6fb2ddb8a63cc0a75b7452bbe0216e64d8d9 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 5 Dec 2022 21:56:00 +0100 Subject: [PATCH 07/21] moved UI to latest commit --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 3471178c..73d36003 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 3471178cf9a40a16933d7000d7b4f171e03b446a +Subproject commit 73d36003da48622469ebe8f5bd39d2a8ed49a5d5 From 9c30c608818473b5657f99c16538644001d0ec15 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 6 Dec 2022 21:31:17 +0100 Subject: [PATCH 08/21] fixed scaling issue, fixed missing Zano entry in balances list --- src/gui/qt-daemon/application/mainwindow.cpp | 2 ++ src/gui/qt-daemon/main.cpp | 2 +- src/wallet/wallet2.cpp | 36 ++++++++------------ 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index 468b8aaf..7c4fd788 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -142,6 +142,8 @@ bool MainWindow::init_window() m_view->page()->setWebChannel(m_channel); QWidget* central_widget_to_be_set = m_view; + double zoom_factor_test = 0.75; + m_view->setZoomFactor(zoom_factor_test); std::string qt_dev_tools_option = m_backend.get_qt_dev_tools_option(); if (!qt_dev_tools_option.empty()) diff --git a/src/gui/qt-daemon/main.cpp b/src/gui/qt-daemon/main.cpp index 39ecae9d..8d3a3244 100644 --- a/src/gui/qt-daemon/main.cpp +++ b/src/gui/qt-daemon/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) #ifdef _MSC_VER #if _MSC_VER >= 1910 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); //HiDPI pixmaps - qputenv("QT_SCALE_FACTOR", "0.75"); + //qputenv("QT_SCALE_FACTOR", "0.75"); #endif #endif diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 84c3435e..d277b099 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2372,7 +2372,7 @@ void wallet2::refresh(size_t & blocks_fetched, bool& received_money, std::atomic } - WLT_LOG("Refresh done, blocks received: " << blocks_fetched << ", balance: " << print_money_brief(balance()) << ", unlocked: " << print_money_brief(unlocked_balance()), blocks_fetched > 0 ? LOG_LEVEL_1 : LOG_LEVEL_2); + WLT_LOG("Refresh done, blocks received: " << blocks_fetched, blocks_fetched > 0 ? LOG_LEVEL_1 : LOG_LEVEL_2); } //---------------------------------------------------------------------------------------------------- bool wallet2::handle_expiration_list(uint64_t tx_expiration_ts_median) @@ -3162,37 +3162,31 @@ bool wallet2::balance(std::list& balances, u native_asset_info.full_name = CURRENCY_NAME_SHORT_BASE; native_asset_info.ticker = CURRENCY_NAME_ABR; native_asset_info.decimal_point = CURRENCY_DISPLAY_DECIMAL_POINT; + custom_assets_local[currency::null_hash] = native_asset_info; for (const auto& item : balances_map) { asset_descriptor_base asset_info = AUTO_VAL_INIT(asset_info); //check if asset is whitelisted or customly added - if (item.first == currency::null_hash) + auto it = m_whitelisted_assets.find(item.first); + if (it == m_whitelisted_assets.end()) { - asset_info = native_asset_info; - } - else - { - auto it = m_whitelisted_assets.find(item.first); - if (it == m_whitelisted_assets.end()) + //check if it custom asset + auto it_cust = custom_assets_local.find(item.first); + if (it_cust == custom_assets_local.end()) { - //check if it custom asset - auto it_cust = custom_assets_local.find(item.first); - if (it_cust == custom_assets_local.end()) - { - continue; - } - else - { - asset_info = it_cust->second; - custom_assets_local.erase(it_cust); - } + continue; } else { - asset_info = it->second; + asset_info = it_cust->second; + custom_assets_local.erase(it_cust); } - } + } + else + { + asset_info = it->second; + } balances.push_back(wallet_public::asset_balance_entry()); wallet_public::asset_balance_entry& new_item = balances.back(); static_cast(new_item) = item.second; From 0dc8a4255574a3afb4c6f87c102202499c092cc1 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 6 Dec 2022 21:59:49 +0100 Subject: [PATCH 09/21] added api for UI to fetch balance after whitelisting of asset --- src/gui/qt-daemon/application/mainwindow.cpp | 11 +++++++++++ src/gui/qt-daemon/application/mainwindow.h | 1 + src/wallet/wallets_manager.cpp | 2 +- src/wallet/wallets_manager.h | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index 7c4fd788..2d8a3736 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -2150,6 +2150,17 @@ QString MainWindow::remove_custom_asset_id(const QString& param) return MAKE_RESPONSE(default_ar); CATCH_ENTRY_FAIL_API_RESPONCE(); } +QString MainWindow::get_wallet_info(const QString& param) +{ + TRY_ENTRY(); + LOG_API_TIMING(); + PREPARE_ARG_FROM_JSON(view::wallet_id_obj, waid); + PREPARE_RESPONSE(view::wallet_info, ar); + default_ar.error_code = m_backend.get_wallet_info(waid.wallet_id, ar.response_data); + return MAKE_RESPONSE(default_ar); + CATCH_ENTRY_FAIL_API_RESPONCE(); +} + QString MainWindow::backup_wallet_keys(const QString& param) { TRY_ENTRY(); diff --git a/src/gui/qt-daemon/application/mainwindow.h b/src/gui/qt-daemon/application/mainwindow.h index 64bdd6d3..37f1dc92 100644 --- a/src/gui/qt-daemon/application/mainwindow.h +++ b/src/gui/qt-daemon/application/mainwindow.h @@ -170,6 +170,7 @@ public: void bool_toggle_icon(const QString& param); QString add_custom_asset_id(const QString& param); QString remove_custom_asset_id(const QString& param); + QString get_wallet_info(const QString& param); bool get_is_disabled_notifications(); diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 31e37d80..9f3aa81d 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1538,7 +1538,7 @@ std::string wallets_manager::invoke(uint64_t wallet_id, std::string params) return response_info.m_body; } -std::string wallets_manager::get_wallet_info(size_t wallet_id, view::wallet_info& wi) +std::string wallets_manager::get_wallet_info(uint64_t wallet_id, view::wallet_info& wi) { GET_WALLET_OPT_BY_ID(wallet_id, w); return get_wallet_info(w, wi); diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index 8f09475f..899dc928 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -104,7 +104,7 @@ public: std::string get_wallet_status(uint64_t wallet_id); std::string run_wallet(uint64_t wallet_id); std::string get_recent_transfers(size_t wallet_id, uint64_t offset, uint64_t count, view::transfers_array& tr_hist, bool exclude_mining_txs = false); - std::string get_wallet_info(size_t wallet_id, view::wallet_info& wi); + std::string get_wallet_info(uint64_t wallet_id, view::wallet_info& wi); std::string get_contracts(size_t wallet_id, std::vector& contracts); std::string create_proposal(const view::create_proposal_param_gui& cpp); std::string accept_proposal(size_t wallet_id, const crypto::hash& contract_id); From 7cda58a7cfaf1b089e048e9fda13c2301cb617cd Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 7 Dec 2022 18:04:40 +0100 Subject: [PATCH 10/21] fixed bug in get_wallet_info --- src/gui/qt-daemon/application/mainwindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index 2d8a3736..c4f44b7a 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -2156,8 +2156,8 @@ QString MainWindow::get_wallet_info(const QString& param) LOG_API_TIMING(); PREPARE_ARG_FROM_JSON(view::wallet_id_obj, waid); PREPARE_RESPONSE(view::wallet_info, ar); - default_ar.error_code = m_backend.get_wallet_info(waid.wallet_id, ar.response_data); - return MAKE_RESPONSE(default_ar); + ar.error_code = m_backend.get_wallet_info(waid.wallet_id, ar.response_data); + return MAKE_RESPONSE(ar); CATCH_ENTRY_FAIL_API_RESPONCE(); } From e6b820213a0de350e62c798a715c3888fa284785 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 9 Dec 2022 17:57:13 +0100 Subject: [PATCH 11/21] moved UI to latest commit --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 73d36003..3e9c936b 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 73d36003da48622469ebe8f5bd39d2a8ed49a5d5 +Subproject commit 3e9c936bf1054009a8c21097091ab26f9c3d18e2 From d6cf863687520a81c92527118f79973902a0b308 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 10 Dec 2022 00:00:20 +0100 Subject: [PATCH 12/21] fixed multiple UI bugs related to multiassets --- src/wallet/view_iface.h | 6 ++---- src/wallet/wallet2.cpp | 7 +++---- src/wallet/wallet2.h | 2 +- src/wallet/wallets_manager.cpp | 10 +++++----- src/wallet/wallets_manager.h | 2 +- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/wallet/view_iface.h b/src/wallet/view_iface.h index 16b82069..f4c295ab 100644 --- a/src/wallet/view_iface.h +++ b/src/wallet/view_iface.h @@ -377,16 +377,14 @@ public: struct transfer_event_info { tools::wallet_public::wallet_transfer_info ti; - uint64_t unlocked_balance; - uint64_t balance; + std::list balances; uint64_t total_mined; uint64_t wallet_id; bool is_wallet_in_sync_process; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(ti) - KV_SERIALIZE(unlocked_balance) - KV_SERIALIZE(balance) + KV_SERIALIZE(balances) KV_SERIALIZE(total_mined) KV_SERIALIZE(wallet_id) KV_SERIALIZE(is_wallet_in_sync_process) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index d277b099..21d3bb83 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1429,11 +1429,10 @@ void wallet2::rise_on_transfer2(const wallet_public::wallet_transfer_info& wti) PROFILE_FUNC("wallet2::rise_on_transfer2"); if (!m_do_rise_transfer) return; - uint64_t fake = 0; - uint64_t unlocked_balance = 0; + std::list balances; uint64_t mined = 0; - uint64_t balance = this->balance(unlocked_balance, fake, fake, mined); - m_wcallback->on_transfer2(wti, balance, unlocked_balance, mined); + this->balance(balances, mined); + m_wcallback->on_transfer2(wti, balances, mined); } //---------------------------------------------------------------------------------------------------- void wallet2::handle_money_spent2(const currency::block& b, diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 529b78a1..d647b307 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -119,7 +119,7 @@ namespace tools virtual ~i_wallet2_callback() = default; virtual void on_new_block(uint64_t /*height*/, const currency::block& /*block*/) {} - virtual void on_transfer2(const wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) {} + virtual void on_transfer2(const wallet_public::wallet_transfer_info& wti, const std::list& balances, uint64_t total_mined) {} virtual void on_pos_block_found(const currency::block& /*block*/) {} virtual void on_sync_progress(const uint64_t& /*percents*/) {} virtual void on_transfer_canceled(const wallet_public::wallet_transfer_info& wti) {} diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 9f3aa81d..02874be6 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1417,6 +1417,7 @@ std::string wallets_manager::transfer(uint64_t wallet_id, const view::transfer_p return API_RETURN_CODE_BAD_ARG_WRONG_PAYMENT_ID; // payment id is specified more than once payment_id = embedded_payment_id; } + dsts.back().asset_id = d.asset_id; } if (payment_id.size()) @@ -1854,12 +1855,12 @@ void wallets_manager::on_new_block(size_t wallet_id, uint64_t /*height*/, const } -void wallets_manager::on_transfer2(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) +void wallets_manager::on_transfer2(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti, const std::list& balances, uint64_t total_mined) { view::transfer_event_info tei = AUTO_VAL_INIT(tei); tei.ti = wti; - tei.balance = balance; - tei.unlocked_balance = unlocked_balance; + tei.balances = balances; + tei.total_mined = total_mined; tei.wallet_id = wallet_id; GET_WALLET_OPTIONS_BY_ID_VOID_RET(wallet_id, w); @@ -1903,8 +1904,7 @@ void wallets_manager::on_transfer_canceled(size_t wallet_id, const tools::wallet auto& w = m_wallets[wallet_id].w; if (w->get() != nullptr) { - tei.balance = w->get()->balance(); - tei.unlocked_balance = w->get()->unlocked_balance(); + w->get()->balance(tei.balances, tei.total_mined); tei.wallet_id = wallet_id; } else diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index 899dc928..b5c2922f 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -184,7 +184,7 @@ private: //----- i_backend_wallet_callback ------ virtual void on_new_block(size_t wallet_id, uint64_t height, const currency::block& block); - virtual void on_transfer2(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined); + virtual void on_transfer2(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti, const std::list& balances, uint64_t total_mined); virtual void on_pos_block_found(size_t wallet_id, const currency::block& /*block*/); virtual void on_sync_progress(size_t wallet_id, const uint64_t& /*percents*/); virtual void on_transfer_canceled(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti); From c057909e819e3fad102cfa10ec77397ea7551efa Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 12 Dec 2022 18:12:44 +0100 Subject: [PATCH 13/21] UI moved to latest commit --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 3e9c936b..88b6279f 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 3e9c936bf1054009a8c21097091ab26f9c3d18e2 +Subproject commit 88b6279fa8cb26ab972b301d427b0b5e9018b2a3 From 63cdb84b80c8c8e1317fbdefdc09709c669f8701 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 13 Dec 2022 14:32:42 +0100 Subject: [PATCH 14/21] fixed simplewallet compilation problem --- src/simplewallet/simplewallet.cpp | 5 ++--- src/simplewallet/simplewallet.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 246ed80a..3616d0fe 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -642,14 +642,13 @@ std::string print_money_trailing_zeros_replaced_with_spaces(uint64_t amount) return s; } //---------------------------------------------------------------------------------------------------- -void simple_wallet::on_transfer2(const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) +void simple_wallet::on_transfer2(const tools::wallet_public::wallet_transfer_info& wti, const std::list& balances, uint64_t total_mined) { epee::log_space::console_colors color = wti.is_income ? epee::log_space::console_color_green : epee::log_space::console_color_magenta; message_writer(color, false) << "height " << wti.height << ", tx " << wti.tx_hash << - " " << std::right << std::setw(18) << print_money_trailing_zeros_replaced_with_spaces(wti.amount) << (wti.is_income ? " received," : " spent, ") << - " balance: " << print_money_brief(balance); + " " << std::right << std::setw(18) << print_money_trailing_zeros_replaced_with_spaces(wti.amount) << (wti.is_income ? " received," : " spent"); m_refresh_progress_reporter.update(wti.height, true); } //---------------------------------------------------------------------------------------------------- diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 47cc4bfd..823fee05 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -102,7 +102,7 @@ namespace currency //----------------- i_wallet2_callback --------------------- virtual void on_new_block(uint64_t height, const currency::block& block) override; - virtual void on_transfer2(const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) override; + virtual void on_transfer2(const tools::wallet_public::wallet_transfer_info& wti, const std::list& balances, uint64_t total_mined) override; virtual void on_message(i_wallet2_callback::message_severity severity, const std::string& m) override; virtual void on_tor_status_change(const std::string& state) override; From 5c6de2fddb6d2005a508e0b0006c3e17f3926dab Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 15 Dec 2022 17:11:55 +0100 Subject: [PATCH 15/21] fixed asset duplication in balances with custom list --- src/wallet/wallet2.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 21d3bb83..e88dbacd 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3167,25 +3167,27 @@ bool wallet2::balance(std::list& balances, u { asset_descriptor_base asset_info = AUTO_VAL_INIT(asset_info); //check if asset is whitelisted or customly added - auto it = m_whitelisted_assets.find(item.first); - if (it == m_whitelisted_assets.end()) + + //check if it custom asset + auto it_cust = custom_assets_local.find(item.first); + if(it_cust == custom_assets_local.end()) { - //check if it custom asset - auto it_cust = custom_assets_local.find(item.first); - if (it_cust == custom_assets_local.end()) + auto it_local = m_whitelisted_assets.find(item.first); + if(it_local == m_whitelisted_assets.end()) { continue; } - else + else { - asset_info = it_cust->second; - custom_assets_local.erase(it_cust); + asset_info = it_local->second; } } - else + else { - asset_info = it->second; - } + asset_info = it_cust->second; + custom_assets_local.erase(it_cust); + } + balances.push_back(wallet_public::asset_balance_entry()); wallet_public::asset_balance_entry& new_item = balances.back(); static_cast(new_item) = item.second; From 28f1ed42d9a99cb5275da50d0c59ac1a70ea41a5 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 15 Dec 2022 18:50:05 +0100 Subject: [PATCH 16/21] moved UI to latest commits --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 88b6279f..f8d6ed1b 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 88b6279fa8cb26ab972b301d427b0b5e9018b2a3 +Subproject commit f8d6ed1bbe38d48d7e762154ea9ccbdb33d88424 From 102e0c1cf9171bd0a467517d6d51fe6e4b41f9f2 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 16 Dec 2022 15:38:49 +0100 Subject: [PATCH 17/21] disabled aliases registration fee checks for testnet --- .clang-format | 9 +++------ src/currency_core/currency_format_utils.cpp | 6 +++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.clang-format b/.clang-format index 2fa1f67a..12d0e405 100644 --- a/.clang-format +++ b/.clang-format @@ -4,22 +4,19 @@ AlignConsecutiveAssignments: 'true' AlignConsecutiveDeclarations: 'false' AlignEscapedNewlines: Right AlignOperands: 'false' -AlignTrailingComments: 'true' +AlignTrailingComments: 'false' AllowAllParametersOfDeclarationOnNextLine: 'false' AllowShortBlocksOnASingleLine: 'false' AllowShortCaseLabelsOnASingleLine: 'true' AllowShortFunctionsOnASingleLine: None -AllowShortIfStatementsOnASingleLine: 'true' AllowShortLoopsOnASingleLine: 'false' AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: 'false' -AlwaysBreakTemplateDeclarations: 'true' BinPackArguments: 'true' BinPackParameters: 'true' BreakAfterJavaFieldAnnotations: 'true' BreakBeforeBinaryOperators: None -BreakBeforeBraces: Stroustrup -BreakBeforeInheritanceComma: 'false' +BreakBeforeBraces: Allman BreakBeforeTernaryOperators: 'false' BreakConstructorInitializers: BeforeColon BreakStringLiterals: 'false' @@ -56,4 +53,4 @@ SpacesInParentheses: 'false' SpacesInSquareBrackets: 'false' Standard: Cpp11 TabWidth: '2' -UseTab: Never \ No newline at end of file +UseTab: Never diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 9adeb482..8249f9b5 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -3153,8 +3153,12 @@ namespace currency VARIANT_CASE_CONST(tx_out_zarcanum, o) //@#@ VARIANT_SWITCH_END(); - } +#ifdef TESTNET + found_alias_reward = 10 * COIN; +#else + @#@ fix it for mainnet bui +#endif return found_alias_reward; } From 67334071a67c6d8dfc0791d2b8394ac29609d331 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 19 Dec 2022 23:09:17 +0100 Subject: [PATCH 18/21] fixed sweep_below command in simplewallet(credits to @sowle) --- src/wallet/wallet2.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 1a62584d..d710c52e 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -6336,8 +6336,11 @@ void wallet2::sweep_below(size_t fake_outs_count, const currency::account_public return rc_too_few_outputs; // try to construct a transaction + + assets_selection_context needed_money_map; + needed_money_map[currency::null_hash] = {}; std::vector dsts({ tx_destination_entry(amount_swept - fee, destination_addr) }); - prepare_tx_destinations(0, 0, get_current_split_strategy(), tools::tx_dust_policy(), dsts, ftp.prepared_destinations, currency::null_hash); + prepare_tx_destinations(needed_money_map, get_current_split_strategy(), tools::tx_dust_policy(), dsts, ftp.prepared_destinations); currency::transaction tx = AUTO_VAL_INIT(tx); crypto::secret_key tx_key = AUTO_VAL_INIT(tx_key); From 64a90d190aa29ea7421eb014bfa54f1e2ae2d692 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 20 Dec 2022 21:22:11 +0100 Subject: [PATCH 19/21] optimization on get_random_outs --- .../include/storages/http_abstract_invoke.h | 4 ++++ src/currency_core/blockchain_storage.cpp | 20 ++++++++++++++++++- src/rpc/core_rpc_server.cpp | 3 ++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/contrib/epee/include/storages/http_abstract_invoke.h b/contrib/epee/include/storages/http_abstract_invoke.h index fc27faaa..8dfca43d 100644 --- a/contrib/epee/include/storages/http_abstract_invoke.h +++ b/contrib/epee/include/storages/http_abstract_invoke.h @@ -85,6 +85,8 @@ namespace epee if(!serialization::store_t_to_binary(out_struct, req_param)) return false; + LOG_PRINT_L3("[HTTP_BIN] ---> " << "[" << &req_param << "][" << method << "][" << url << "] REQUEST BODY BASE64: " << ENDL << epee::string_encoding::base64_encode(req_param)); + const http::http_response_info* pri = NULL; if(!invoke_request(url, transport, timeout, &pri, method, req_param)) { @@ -98,6 +100,8 @@ namespace epee return false; } + LOG_PRINT_L3("[HTTP_BIN] <--- " << "[" << &req_param << "][" << method << "][" << url << "] RESPONSE(" << pri->m_response_code << ") BODY BASE64: " << ENDL << epee::string_encoding::base64_encode(pri->m_body)); + if(pri->m_response_code != 200) { LOG_PRINT_L1("Failed to invoke http request to " << url << ", wrong response code: " << pri->m_response_code); diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 57fc8ea4..34a8707b 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -2549,6 +2549,8 @@ bool blockchain_storage::add_out_to_get_random_outs(COMMAND_RPC_GET_RANDOM_OUTPU VARIANT_SWITCH_BEGIN(out_v); VARIANT_CASE_CONST(tx_out_bare, o) { + CHECK_AND_ASSERT_MES(amount != 0, false, "unexpected amount == 0 for tx_out_bare"); + if (o.target.type() == typeid(txout_htlc)) { //silently return false, it's ok @@ -2563,6 +2565,8 @@ bool blockchain_storage::add_out_to_get_random_outs(COMMAND_RPC_GET_RANDOM_OUTPU } VARIANT_CASE_CONST(tx_out_zarcanum, toz) { + CHECK_AND_ASSERT_MES(amount == 0, false, "unexpected amount != 0 for tx_out_zarcanum"); + COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::out_entry& oen = *result_outs.outs.insert(result_outs.outs.end(), COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::out_entry()); oen.global_amount_index = g_index; oen.stealth_address = toz.stealth_address; @@ -2597,6 +2601,9 @@ size_t blockchain_storage::find_end_of_allowed_index(uint64_t amount) const bool blockchain_storage::get_random_outs_for_amounts(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res)const { CRITICAL_REGION_LOCAL(m_read_lock); + LOG_PRINT_L3("[get_random_outs_for_amounts] amounts: " << req.amounts.size()); + std::map amounts_to_up_index_limit_cache; + for(uint64_t amount : req.amounts) { COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& result_outs = *res.outs.insert(res.outs.end(), COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount()); @@ -2609,7 +2616,18 @@ bool blockchain_storage::get_random_outs_for_amounts(const COMMAND_RPC_GET_RANDO } //it is not good idea to use top fresh outs, because it increases possibility of transaction canceling on split //lets find upper bound of not fresh outs - size_t up_index_limit = find_end_of_allowed_index(amount); + size_t up_index_limit = 0; + auto it_limit = amounts_to_up_index_limit_cache.find(amount); + if (it_limit == amounts_to_up_index_limit_cache.end()) + { + up_index_limit = find_end_of_allowed_index(amount); + amounts_to_up_index_limit_cache[up_index_limit]; + } + else + { + up_index_limit = it_limit->second; + } + CHECK_AND_ASSERT_MES(up_index_limit <= outs_container_size, false, "internal error: find_end_of_allowed_index returned wrong index=" << up_index_limit << ", with amount_outs.size = " << outs_container_size); if (up_index_limit >= req.decoys_count) { diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 249cda11..42112077 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -366,7 +366,7 @@ namespace currency std::stringstream ss; typedef COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount outs_for_amount; typedef COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::out_entry out_entry; - std::for_each(res.outs.begin(), res.outs.end(), [&](outs_for_amount& ofa) + /*std::for_each(res.outs.begin(), res.outs.end(), [&](outs_for_amount& ofa) { ss << "[" << ofa.amount << "]:"; CHECK_AND_ASSERT_MES(ofa.outs.size(), ;, "internal error: ofa.outs.size() is empty for amount " << ofa.amount); @@ -378,6 +378,7 @@ namespace currency }); std::string s = ss.str(); LOG_PRINT_L2("COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS: " << ENDL << s); + */ res.status = API_RETURN_CODE_OK; return true; } From 48f9466b3e7de8dc2ea370437ea9a894f3962c36 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 20 Dec 2022 21:23:53 +0100 Subject: [PATCH 20/21] extra verification checks in add_out_to_get_random_outs() --- src/currency_core/blockchain_storage.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 34a8707b..589f7d22 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -2550,7 +2550,6 @@ bool blockchain_storage::add_out_to_get_random_outs(COMMAND_RPC_GET_RANDOM_OUTPU VARIANT_CASE_CONST(tx_out_bare, o) { CHECK_AND_ASSERT_MES(amount != 0, false, "unexpected amount == 0 for tx_out_bare"); - if (o.target.type() == typeid(txout_htlc)) { //silently return false, it's ok @@ -2566,7 +2565,6 @@ bool blockchain_storage::add_out_to_get_random_outs(COMMAND_RPC_GET_RANDOM_OUTPU VARIANT_CASE_CONST(tx_out_zarcanum, toz) { CHECK_AND_ASSERT_MES(amount == 0, false, "unexpected amount != 0 for tx_out_zarcanum"); - COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::out_entry& oen = *result_outs.outs.insert(result_outs.outs.end(), COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::out_entry()); oen.global_amount_index = g_index; oen.stealth_address = toz.stealth_address; From 0c0c2874180db0d2c3c539ea4459f919ad811f76 Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 26 Dec 2022 22:47:31 +0100 Subject: [PATCH 21/21] build script windows: ZANO_BUILDS_HOST added --- utils/build_script_windows.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/build_script_windows.bat b/utils/build_script_windows.bat index 7a80b8aa..4bdce4d0 100644 --- a/utils/build_script_windows.bat +++ b/utils/build_script_windows.bat @@ -178,14 +178,14 @@ set installer_path=%BUILDS_PATH%\builds\%installer_file% @echo " UPLOADING TO SERVER ...." -pscp -load zano_build_server %installer_path% build.zano.org:/var/www/html/builds +pscp -load zano_build_server %installer_path% %ZANO_BUILDS_HOST%:/var/www/html/builds IF %ERRORLEVEL% NEQ 0 ( @echo "FAILED TO UPLOAD EXE TO SERVER" goto error ) call :sha256 %installer_path% installer_checksum -pscp -load zano_build_server %build_zip_path% build.zano.org:/var/www/html/builds +pscp -load zano_build_server %build_zip_path% %ZANO_BUILDS_HOST%:/var/www/html/builds IF %ERRORLEVEL% NEQ 0 ( @echo "FAILED TO UPLOAD ZIP TO SERVER" goto error