From 13accb65ad2d164332be660339ee71f1146bd3da Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 29 Aug 2020 01:14:26 +0200 Subject: [PATCH 01/18] fixed few issues with attachment encryption --- src/currency_core/currency_basic.h | 6 ++-- .../currency_boost_serialization.h | 2 +- src/currency_core/currency_config.h | 2 +- src/currency_core/currency_format_utils.cpp | 35 +++++++++++++++---- src/currency_core/currency_format_utils.h | 29 +++++++++++++++ src/wallet/wallet2.cpp | 22 ++++++++++++ src/wallet/wallet2.h | 6 ++++ 7 files changed, 91 insertions(+), 11 deletions(-) diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index f3972253..8ac26a6f 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -508,7 +508,7 @@ namespace currency END_SERIALIZE() }; - struct etc_tx_uint16_t + struct etc_tx_flags16_t { uint16_t v; BEGIN_SERIALIZE() @@ -518,7 +518,7 @@ namespace currency typedef boost::mpl::vector21< tx_service_attachment, tx_comment, tx_payer_old, tx_receiver_old, tx_derivation_hint, std::string, tx_crypto_checksum, etc_tx_time, etc_tx_details_unlock_time, etc_tx_details_expiration_time, - etc_tx_details_flags, crypto::public_key, extra_attachment_info, extra_alias_entry_old, extra_user_data, extra_padding, etc_tx_uint16_t, etc_tx_details_unlock_time2, + etc_tx_details_flags, crypto::public_key, extra_attachment_info, extra_alias_entry_old, extra_user_data, extra_padding, etc_tx_flags16_t, etc_tx_details_unlock_time2, tx_payer, tx_receiver, extra_alias_entry > all_payload_types; @@ -749,7 +749,7 @@ SET_VARIANT_TAGS(currency::extra_user_data, 19, "user_data"); SET_VARIANT_TAGS(currency::extra_alias_entry_old, 20, "alias_entry"); SET_VARIANT_TAGS(currency::extra_padding, 21, "extra_padding"); SET_VARIANT_TAGS(crypto::public_key, 22, "pub_key"); -SET_VARIANT_TAGS(currency::etc_tx_uint16_t, 23, "etc_tx_uint16"); +SET_VARIANT_TAGS(currency::etc_tx_flags16_t, 23, "etc_tx_flags16"); SET_VARIANT_TAGS(uint16_t, 24, "derive_xor"); //txout_v SET_VARIANT_TAGS(currency::ref_by_id, 25, "ref_by_id"); diff --git a/src/currency_core/currency_boost_serialization.h b/src/currency_core/currency_boost_serialization.h index 49f4b9cf..93e240cb 100644 --- a/src/currency_core/currency_boost_serialization.h +++ b/src/currency_core/currency_boost_serialization.h @@ -252,7 +252,7 @@ namespace boost } template - inline void serialize(Archive &a, currency::etc_tx_uint16_t&at, const boost::serialization::version_type ver) + inline void serialize(Archive &a, currency::etc_tx_flags16_t&at, const boost::serialization::version_type ver) { a & at.v; } diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 6bb298f6..4e06493b 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -221,7 +221,7 @@ #define BC_OFFERS_CURRENCY_MARKET_FILENAME "market.bin" -#define WALLET_FILE_SERIALIZATION_VERSION (CURRENCY_FORMATION_VERSION+67) +#define WALLET_FILE_SERIALIZATION_VERSION (CURRENCY_FORMATION_VERSION+68) #define CURRENT_MEMPOOL_ARCHIVE_VER (CURRENCY_FORMATION_VERSION+31) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index ed017a34..740c7afc 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -710,6 +710,16 @@ namespace currency crypto::chacha_crypt(m.acc_addr, m_key); m_was_crypted_entries = true; } + void operator()(tx_payer_old& pr) + { + crypto::chacha_crypt(pr.acc_addr, m_key); + m_was_crypted_entries = true; + } + void operator()(tx_receiver_old& m) + { + crypto::chacha_crypt(m.acc_addr, m_key); + m_was_crypted_entries = true; + } void operator()(tx_service_attachment& sa) { if (sa.flags&TX_SERVICE_ATTACHMENT_DEFLATE_BODY) @@ -772,7 +782,18 @@ namespace currency crypto::chacha_crypt(receiver_local.acc_addr, rkey); rdecrypted_att.push_back(receiver_local); } - + void operator()(const tx_payer_old& pr) + { + tx_payer_old payer_local = pr; + crypto::chacha_crypt(payer_local.acc_addr, rkey); + rdecrypted_att.push_back(payer_local); + } + void operator()(const tx_receiver_old& pr) + { + tx_receiver_old receiver_local = pr; + crypto::chacha_crypt(receiver_local.acc_addr, rkey); + rdecrypted_att.push_back(receiver_local); + } template void operator()(const attachment_t& att) { @@ -1049,6 +1070,11 @@ namespace currency add_tx_pub_key_to_extra(tx, txkey.pub); one_time_secret_key = txkey.sec; + //add flags + etc_tx_flags16_t e = AUTO_VAL_INIT(e); + //todo: add some flags here + update_or_add_field_to_extra(tx.extra, e); + //include offers if need tx.attachment = attachments; encrypt_attachments(tx, sender_account_keys, crypt_destination_addr, txkey); @@ -2316,18 +2342,15 @@ namespace currency return true; } - bool operator()(const etc_tx_uint16_t& dh) + bool operator()(const etc_tx_flags16_t& dh) { - tv.type = "XOR"; + tv.type = "FLAGS16"; tv.short_view = epee::string_tools::pod_to_hex(dh); tv.datails_view = epee::string_tools::pod_to_hex(dh); return true; } - }; - - //------------------------------------------------------------------ template bool fill_tx_rpc_payload_items(std::vector& target_vector, const t_container& tc) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index c17d3f14..ce7642b9 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -459,6 +459,35 @@ namespace currency } variant_container.push_back(v); } + //--------------------------------------------------------------- + template + bool has_field_of_type_in_extra(std::vector& variant_container) + { + for (auto& ev : variant_container) + { + if (ev.type() == typeid(variant_type_t)) + { + return true; + } + } + return false; + } + //--------------------------------------------------------------- + template + void remove_field_of_type_from_extra(std::vector& variant_container) + { + for (size_t i = 0; i != variant_container.size();) + { + if (variant_container[i].type() == typeid(variant_type_t)) + { + variant_container.erase(variant_container.begin()+i); + } + else + { + i++; + } + } + } //--------------------------------------------------------------- template diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index b1eae98f..47d7f01d 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1184,6 +1184,15 @@ void wallet2::prepare_wti(wallet_public::wallet_transfer_info& wti, uint64_t hei decrypt_payload_items(decrypt_attachment_as_income, tx, m_account.get_keys(), decrypted_att); + if (is_watch_only() || (height > 638000 && !has_field_of_type_in_extra(decrypted_att))) + { + remove_field_of_type_from_extra(decrypted_att); + remove_field_of_type_from_extra(decrypted_att); + } + if (is_watch_only()) + { + remove_field_of_type_from_extra(decrypted_att); + } prepare_wti_decrypted_attachments(wti, decrypted_att); process_contract_info(wti, decrypted_att); } @@ -4302,6 +4311,19 @@ bool wallet2::is_transfer_ready_to_go(const transfer_details& td, uint64_t fake_ return false; } //---------------------------------------------------------------------------------------------------- +void wallet2::wipeout_extra_if_needed(std::vector& transfer_history) +{ + WLT_LOG_L0("Processing [wipeout_extra_if_needed]..."); + for (auto it = transfer_history.begin(); it != transfer_history.end(); ) + { + if (it->height > 638000) + { + it->remote_addresses.clear(); + } + } + WLT_LOG_L0("Processing [wipeout_extra_if_needed] DONE"); +} +//---------------------------------------------------------------------------------------------------- bool wallet2::is_transfer_able_to_go(const transfer_details& td, uint64_t fake_outputs_count) { if (!td.is_spendable()) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index fedc856e..f8993de0 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -730,8 +730,14 @@ namespace tools a & m_tx_keys; a & m_last_pow_block_h; + //after processing + if (ver < 152) + { + wipeout_extra_if_needed(m_transfer_history); + } } + void wipeout_extra_if_needed(std::vector& transfer_history); bool is_transfer_ready_to_go(const transfer_details& td, uint64_t fake_outputs_count); bool is_transfer_able_to_go(const transfer_details& td, uint64_t fake_outputs_count); uint64_t select_indices_for_transfer(std::vector& ind, free_amounts_cache_type& found_free_amounts, uint64_t needed_money, uint64_t fake_outputs_count); From 2dd0848b0aeccb4183d2908814c484fd413a3eaa Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 31 Aug 2020 18:23:41 +0200 Subject: [PATCH 02/18] added extra conditions on extra fields update in wallet --- src/wallet/wallet2.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 47d7f01d..279bfc36 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1184,12 +1184,12 @@ void wallet2::prepare_wti(wallet_public::wallet_transfer_info& wti, uint64_t hei decrypt_payload_items(decrypt_attachment_as_income, tx, m_account.get_keys(), decrypted_att); - if (is_watch_only() || (height > 638000 && !has_field_of_type_in_extra(decrypted_att))) + if ((is_watch_only() && !wti.is_income)|| (height > 638000 && !has_field_of_type_in_extra(decrypted_att))) { remove_field_of_type_from_extra(decrypted_att); remove_field_of_type_from_extra(decrypted_att); } - if (is_watch_only()) + if (is_watch_only() && !wti.is_income) { remove_field_of_type_from_extra(decrypted_att); } @@ -4221,8 +4221,8 @@ bool wallet2::extract_offers_from_transfer_entry(size_t i, std::unordered_map& selected_in WLT_LOG_GREEN("Selecting indices for transfer of " << print_money_brief(needed_money) << " with " << fake_outputs_count << " fake outs, found_free_amounts.size()=" << found_free_amounts.size() << "...", LOG_LEVEL_0); uint64_t found_money = 0; std::string selected_amounts_str; - while(found_money < needed_money && found_free_amounts.size()) + while (found_money < needed_money && found_free_amounts.size()) { auto it = found_free_amounts.lower_bound(needed_money - found_money); if (!(it != found_free_amounts.end() && it->second.size())) @@ -4319,6 +4319,10 @@ void wallet2::wipeout_extra_if_needed(std::vectorheight > 638000) { it->remote_addresses.clear(); + if (is_watch_only() && !it->is_income) + { + it->comment.clear(); + } } } WLT_LOG_L0("Processing [wipeout_extra_if_needed] DONE"); From bd894a0119bfe6a68d160a808c98af236758b913 Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 31 Aug 2020 20:03:49 +0300 Subject: [PATCH 03/18] has_field_of_type_in_extra() -> have_type_in_variant_container() --- src/currency_core/currency_format_utils.h | 18 ++---------------- src/wallet/wallet2.cpp | 2 +- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index ce7642b9..b53931e3 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -433,8 +433,7 @@ namespace currency ai.m_alias = ard.alias; return true; } - - + //--------------------------------------------------------------- template extra_t& get_or_add_field_to_extra(std::vector& extra) { @@ -446,6 +445,7 @@ namespace currency extra.push_back(extra_t()); return boost::get(extra.back()); } + //--------------------------------------------------------------- template void update_or_add_field_to_extra(std::vector& variant_container, const variant_type_t& v) { @@ -461,19 +461,6 @@ namespace currency } //--------------------------------------------------------------- template - bool has_field_of_type_in_extra(std::vector& variant_container) - { - for (auto& ev : variant_container) - { - if (ev.type() == typeid(variant_type_t)) - { - return true; - } - } - return false; - } - //--------------------------------------------------------------- - template void remove_field_of_type_from_extra(std::vector& variant_container) { for (size_t i = 0; i != variant_container.size();) @@ -488,7 +475,6 @@ namespace currency } } } - //--------------------------------------------------------------- template bool get_payment_id_from_tx(const t_container& att, std::string& payment_id) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 279bfc36..036057f2 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1184,7 +1184,7 @@ void wallet2::prepare_wti(wallet_public::wallet_transfer_info& wti, uint64_t hei decrypt_payload_items(decrypt_attachment_as_income, tx, m_account.get_keys(), decrypted_att); - if ((is_watch_only() && !wti.is_income)|| (height > 638000 && !has_field_of_type_in_extra(decrypted_att))) + if ((is_watch_only() && !wti.is_income)|| (height > 638000 && !have_type_in_variant_container(decrypted_att))) { remove_field_of_type_from_extra(decrypted_att); remove_field_of_type_from_extra(decrypted_att); From aea993f36be73a5667de49282b1b991b181ccd3b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 1 Sep 2020 00:26:22 +0200 Subject: [PATCH 04/18] implemented exclude_staking_txs filter --- src/gui/qt-daemon/application/mainwindow.cpp | 4 +-- src/wallet/view_iface.h | 5 +++ src/wallet/wallet2.cpp | 32 +++++++++++++++----- src/wallet/wallet2.h | 4 +-- src/wallet/wallet_public_structs_defs.h | 4 +++ src/wallet/wallet_rpc_server.cpp | 4 +-- src/wallet/wallets_manager.cpp | 12 ++++---- src/wallet/wallets_manager.h | 4 +-- 8 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index bad0d821..80777b98 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -1651,7 +1651,7 @@ QString MainWindow::open_wallet(const QString& param) //return que_call2("open_wallet", param, [this](const view::open_wallet_request& owd, view::api_response& ar){ PREPARE_ARG_FROM_JSON(view::open_wallet_request, owd); PREPARE_RESPONSE(view::open_wallet_response, ar); - ar.error_code = m_backend.open_wallet(epee::string_encoding::utf8_to_wstring(owd.path), owd.pass, owd.txs_to_return, ar.response_data); + ar.error_code = m_backend.open_wallet(epee::string_encoding::utf8_to_wstring(owd.path), owd.pass, owd.txs_to_return, ar.response_data, owd.exclude_mining_txs); return MAKE_RESPONSE(ar); CATCH_ENTRY_FAIL_API_RESPONCE(); } @@ -1795,7 +1795,7 @@ QString MainWindow::get_recent_transfers(const QString& param) LOG_API_TIMING(); PREPARE_ARG_FROM_JSON(view::get_recent_transfers_request, a); PREPARE_RESPONSE(view::transfers_array, ar); - ar.error_code = m_backend.get_recent_transfers(a.wallet_id, a.offset, a.count, ar.response_data); + ar.error_code = m_backend.get_recent_transfers(a.wallet_id, a.offset, a.count, ar.response_data, a.exclude_mining_txs); return MAKE_RESPONSE(ar); CATCH_ENTRY_FAIL_API_RESPONCE(); } diff --git a/src/wallet/view_iface.h b/src/wallet/view_iface.h index ee1cc254..0443bde2 100644 --- a/src/wallet/view_iface.h +++ b/src/wallet/view_iface.h @@ -371,11 +371,13 @@ public: std::vector unconfirmed; std::vector history; uint64_t total_history_items; + uint64_t last_item_index; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(unconfirmed) KV_SERIALIZE(history) KV_SERIALIZE(total_history_items) + KV_SERIALIZE(last_item_index) END_KV_SERIALIZE_MAP() }; @@ -385,11 +387,13 @@ public: std::string pass; std::string path; uint64_t txs_to_return; + bool exclude_mining_txs; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(pass) KV_SERIALIZE(path) KV_SERIALIZE(txs_to_return) + KV_SERIALIZE(exclude_mining_txs) END_KV_SERIALIZE_MAP() }; @@ -398,6 +402,7 @@ public: uint64_t wallet_id; uint64_t offset; uint64_t count; + bool exclude_mining_txs; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(wallet_id) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 036057f2..e8905a7f 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2948,17 +2948,27 @@ uint64_t wallet2::get_transfer_entries_count() return m_transfers.size(); } //---------------------------------------------------------------------------------------------------- -void wallet2::get_recent_transfers_history(std::vector& trs, size_t offset, size_t count, uint64_t& total) +void wallet2::get_recent_transfers_history(std::vector& trs, size_t offset, size_t count, uint64_t& total, uint64_t& last_item_index, bool exclude_mining_txs) { - if (offset >= m_transfer_history.size()) + if (!count || offset >= m_transfer_history.size()) return; auto start = m_transfer_history.rbegin() + offset; - auto stop = m_transfer_history.size() - offset >= count ? start + count : m_transfer_history.rend(); - if (!count) - stop = m_transfer_history.rend(); - - trs.insert(trs.end(), start, stop); + for (auto it = m_transfer_history.rbegin() + offset; it != m_transfer_history.rend(); it++) + { + if (exclude_mining_txs) + { + if(it->is_mining) + continue; + } + trs.push_back(*it); + last_item_index = it - m_transfer_history.rbegin(); + + if (trs.size() >= count) + { + break; + } + } total = m_transfer_history.size(); } //---------------------------------------------------------------------------------------------------- @@ -3281,10 +3291,16 @@ bool wallet2::build_minted_block(const currency::COMMAND_RPC_SCAN_POS::request& return true; } //---------------------------------------------------------------------------------------------------- -void wallet2::get_unconfirmed_transfers(std::vector& trs) +void wallet2::get_unconfirmed_transfers(std::vector& trs, bool exclude_mining_txs) { for (auto& u : m_unconfirmed_txs) + { + if (exclude_mining_txs && u.second.is_mining) + { + continue; + } trs.push_back(u.second); + } } //---------------------------------------------------------------------------------------------------- void wallet2::set_core_runtime_config(const currency::core_runtime_config& pc) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index f8993de0..e91052a5 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -482,10 +482,10 @@ namespace tools currency::account_base& get_account() { return m_account; } const currency::account_base& get_account() const { return m_account; } - void get_recent_transfers_history(std::vector& trs, size_t offset, size_t count, uint64_t& total); + void get_recent_transfers_history(std::vector& trs, size_t offset, size_t count, uint64_t& total, uint64_t& last_item_index, bool exclude_mining_txs = false); uint64_t get_recent_transfers_total_count(); uint64_t get_transfer_entries_count(); - void get_unconfirmed_transfers(std::vector& trs); + void get_unconfirmed_transfers(std::vector& trs, bool exclude_mining_txs = false); void init(const std::string& daemon_address = "http://localhost:8080"); bool deinit(); diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index da115c33..420c4953 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -275,11 +275,13 @@ namespace wallet_public of GET_RECENT_TXS_AND_INFO with offsets) */ bool update_provision_info; + bool exclude_mining_txs; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(offset) KV_SERIALIZE(count) KV_SERIALIZE(update_provision_info) + KV_SERIALIZE(exclude_mining_txs) END_KV_SERIALIZE_MAP() }; @@ -288,11 +290,13 @@ namespace wallet_public wallet_provision_info pi; std::vector transfers; uint64_t total_transfers; + uint64_t last_item_index; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(pi) KV_SERIALIZE(transfers) KV_SERIALIZE(total_transfers) + KV_SERIALIZE(last_item_index) END_KV_SERIALIZE_MAP() }; }; diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index edcbfc41..a2ea9db3 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -223,9 +223,9 @@ namespace tools } if (req.offset == 0) - m_wallet.get_unconfirmed_transfers(res.transfers); + m_wallet.get_unconfirmed_transfers(res.transfers, req.exclude_mining_txs); - m_wallet.get_recent_transfers_history(res.transfers, req.offset, req.count, res.total_transfers); + m_wallet.get_recent_transfers_history(res.transfers, req.offset, req.count, res.total_transfers, res.last_item_index, req.exclude_mining_txs); return true; } diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index e65cf6dd..9aedac42 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -815,7 +815,7 @@ std::string wallets_manager::get_my_offers(const bc_services::core_offers_filter #endif } -std::string wallets_manager::open_wallet(const std::wstring& path, const std::string& password, uint64_t txs_to_return, view::open_wallet_response& owr) +std::string wallets_manager::open_wallet(const std::wstring& path, const std::string& password, uint64_t txs_to_return, view::open_wallet_response& owr, bool exclude_mining_txs) { // check if that file already opened SHARED_CRITICAL_REGION_BEGIN(m_wallets_lock); @@ -854,9 +854,9 @@ std::string wallets_manager::open_wallet(const std::wstring& path, const std::st if (w->is_watch_only() && !w->is_auditable()) return API_RETURN_CODE_WALLET_WATCH_ONLY_NOT_SUPPORTED; - w->get_recent_transfers_history(owr.recent_history.history, 0, txs_to_return, owr.recent_history.total_history_items); + 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); + w->get_unconfirmed_transfers(owr.recent_history.history, exclude_mining_txs); owr.wallet_local_bc_size = w->get_blockchain_current_size(); //workaround for missed fee owr.seed = w->get_account().get_seed_phrase(); @@ -912,7 +912,7 @@ bool wallets_manager::get_opened_wallets(std::list& return true; } -std::string wallets_manager::get_recent_transfers(size_t wallet_id, uint64_t offset, uint64_t count, view::transfers_array& tr_hist) +std::string wallets_manager::get_recent_transfers(size_t wallet_id, uint64_t offset, uint64_t count, view::transfers_array& tr_hist, bool exclude_mining_txs) { GET_WALLET_BY_ID(wallet_id, w); auto wallet_locked = w.try_lock(); @@ -921,8 +921,8 @@ std::string wallets_manager::get_recent_transfers(size_t wallet_id, uint64_t off return API_RETURN_CODE_CORE_BUSY; } - w->get()->get_unconfirmed_transfers(tr_hist.unconfirmed); - w->get()->get_recent_transfers_history(tr_hist.history, offset, count, tr_hist.total_history_items); + w->get()->get_unconfirmed_transfers(tr_hist.unconfirmed, exclude_mining_txs); + w->get()->get_recent_transfers_history(tr_hist.history, offset, count, tr_hist.total_history_items, tr_hist.last_item_index, exclude_mining_txs); auto fix_tx = [](tools::wallet_public::wallet_transfer_info& wti) -> void { wti.show_sender = currency::is_showing_sender_addres(wti.tx); diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index ccd054e6..75cd8827 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -97,13 +97,13 @@ public: bool quick_clear_wallets_no_save(); bool send_stop_signal(); bool get_opened_wallets(std::list& result); - std::string open_wallet(const std::wstring& path, const std::string& password, uint64_t txs_to_return, view::open_wallet_response& owr); + std::string open_wallet(const std::wstring& path, const std::string& password, uint64_t txs_to_return, view::open_wallet_response& owr, bool exclude_mining_txs = false); std::string generate_wallet(const std::wstring& path, const std::string& password, view::open_wallet_response& owr); std::string restore_wallet(const std::wstring& path, const std::string& password, const std::string& restore_key, view::open_wallet_response& owr); std::string invoke(uint64_t wallet_id, std::string params); 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); + 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_contracts(size_t wallet_id, std::vector& contracts); std::string create_proposal(const view::create_proposal_param_gui& cpp); From 3b3dbd6fa222ed51535efecdc50586815c9f9223 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 1 Sep 2020 18:48:10 +0200 Subject: [PATCH 05/18] fixed core tests --- tests/core_tests/multisig_wallet_tests.cpp | 2 +- tests/core_tests/tx_validation.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/core_tests/multisig_wallet_tests.cpp b/tests/core_tests/multisig_wallet_tests.cpp index 9bc3be84..88c86b24 100644 --- a/tests/core_tests/multisig_wallet_tests.cpp +++ b/tests/core_tests/multisig_wallet_tests.cpp @@ -1622,7 +1622,7 @@ multisig_and_checkpoints::multisig_and_checkpoints() bool multisig_and_checkpoints::set_cp(currency::core& c, size_t ev_index, const std::vector& events) { currency::checkpoints checkpoints; - checkpoints.add_checkpoint(15, "72d63d6500c62d6783108f5a2e2c9f1dc1f0aae57011cf123583eec679a52cf9"); + checkpoints.add_checkpoint(15, "6f9194c144afd73077478e7f04e947c50160b5673558e6f696a4f662a3ca261e"); c.set_checkpoints(std::move(checkpoints)); return true; diff --git a/tests/core_tests/tx_validation.cpp b/tests/core_tests/tx_validation.cpp index cb202875..bd23fdf0 100644 --- a/tests/core_tests/tx_validation.cpp +++ b/tests/core_tests/tx_validation.cpp @@ -934,7 +934,7 @@ bool gen_crypted_attachments::check_crypted_tx(currency::core& c, size_t ev_inde std::vector at; bool r = currency::decrypt_payload_items(true, *ptx_from_bc, bob_acc.get_keys(), at); CHECK_EQ(r, true); - CHECK_EQ(at.size(), 7); // custom attachments: 1) tx_payer, 2) tx_comment, 3) std::string; system attachments: 4) tx_crypto_checksum; system extra: 5) tx pub key, 6) extra_attachment_info + CHECK_EQ(at.size(), 8); // custom attachments: 1) tx_payer, 2) tx_comment, 3) std::string; system attachments: 4) tx_crypto_checksum; system extra: 5) tx pub key, 6) extra_attachment_info, 7) etc_tx_flags16_t currency::tx_payer decrypted_pr = AUTO_VAL_INIT(decrypted_pr); r = get_type_in_variant_container(at, decrypted_pr); From 3dce5fd078fd13e2ee65519484dd4e8150a4c73b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 1 Sep 2020 23:30:18 +0200 Subject: [PATCH 06/18] fixed simplewallet.cpp --- src/simplewallet/simplewallet.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index c37fef0a..3770251a 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -756,8 +756,9 @@ bool simple_wallet::list_recent_transfers(const std::vector& args) std::vector unconfirmed; std::vector recent; uint64_t total = 0; - m_wallet->get_recent_transfers_history(recent, 0, 0, total); - m_wallet->get_unconfirmed_transfers(unconfirmed); + uint64_t last_index = 0; + m_wallet->get_recent_transfers_history(recent, 0, 0, total, last_index, false); + m_wallet->get_unconfirmed_transfers(unconfirmed, false); //workaround for missed fee success_msg_writer() << "Unconfirmed transfers: "; @@ -809,8 +810,9 @@ bool simple_wallet::export_recent_transfers(const std::vector& args std::vector unconfirmed; std::vector recent; uint64_t total = 0; - m_wallet->get_recent_transfers_history(recent, 0, 0, total); - m_wallet->get_unconfirmed_transfers(unconfirmed); + uint64_t last_index = 0; + m_wallet->get_recent_transfers_history(recent, 0, 0, total, last_index, false); + m_wallet->get_unconfirmed_transfers(unconfirmed, false); //workaround for missed fee stringstream ss; LOG_PRINT_GREEN("Generating text....", LOG_LEVEL_0); From baaf1c06ecd95ab85e09bc5feacf3db14d21aacf Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 2 Sep 2020 17:28:19 +0200 Subject: [PATCH 07/18] let's pretend this never happened --- src/wallet/wallet2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 7a31708b..d06c9020 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -4281,7 +4281,7 @@ bool wallet2::is_transfer_ready_to_go(const transfer_details& td, uint64_t fake_ void wallet2::wipeout_extra_if_needed(std::vector& transfer_history) { WLT_LOG_L0("Processing [wipeout_extra_if_needed]..."); - for (auto it = transfer_history.begin(); it != transfer_history.end(); ) + for (auto it = transfer_history.begin(); it != transfer_history.end(); it++ ) { if (it->height > 638000) { From 8b8bbf3247a4e5819a1014cf8f299ef72100f1ac Mon Sep 17 00:00:00 2001 From: Sergey Radionov Date: Thu, 3 Sep 2020 19:27:00 +0700 Subject: [PATCH 08/18] initial snap support added (#210) --- snap/snapcraft.yaml | 71 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 snap/snapcraft.yaml diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 00000000..a80ede85 --- /dev/null +++ b/snap/snapcraft.yaml @@ -0,0 +1,71 @@ +name: zano +base: core18 +adopt-info: zano +summary: "Zano coin: official wallet. Secure. Scalable. Easy to Use." +description: | + Zano is a scalable and secure coin, designed for use in e-commerce. + The technology behind our blockchain provides reliability, security, + and flexibility a perfect option for P2P transactions. + More info: http://zano.org +grade: devel +confinement: devmode + +architectures: + - build-on: amd64 + - build-on: i386 + +environment: + LC_ALL: C + +parts: + zano: + source: https://github.com/hyle-team/zano.git + plugin: cmake + override-pull: | + snapcraftctl pull + snapcraftctl set-version "$(git describe)" + configflags: + - -DBUILD_GUI=TRUE + override-build: | + snapcraftctl build + mkdir -p $SNAPCRAFT_PART_INSTALL/opt/Zano + cp $SNAPCRAFT_PART_BUILD/src/Zano $SNAPCRAFT_PART_INSTALL/opt/Zano/ + cp $SNAPCRAFT_PART_BUILD/src/simplewallet $SNAPCRAFT_PART_INSTALL/opt/Zano/ + cp $SNAPCRAFT_PART_BUILD/src/zanod $SNAPCRAFT_PART_INSTALL/opt/Zano/ + rsync -a $SNAPCRAFT_PART_SRC/src/gui/qt-daemon/html $SNAPCRAFT_PART_INSTALL/opt/Zano --exclude less --exclude package.json --exclude gulpfile.js + build-packages: + - make + - g++ + - libboost-all-dev + - qtwebengine5-dev + - rsync + build-attributes: [keep-execstack] + stage-packages: + - libboost-system1.65.1 + - libboost-filesystem1.65.1 + - libboost-thread1.65.1 + - libboost-date-time1.65.1 + - libboost-chrono1.65.1 + - libboost-regex1.65.1 + - libboost-serialization1.65.1 + - libboost-program-options1.65.1 + - libboost-locale1.65.1 + +apps: + zano: + command: opt/Zano/Zano --data-dir $SNAP_USER_COMMON + extensions: + - kde-neon + plugs: + - network + - home + simplewallet: + command: opt/Zano/simplewallet + plugs: + - network + - home + zanod: + command: opt/Zano/zanod --data-dir $SNAP_USER_COMMON + plugs: + - network + - network-bind From dc961928d93c86e52d5d7a88de73a82930ea6eb0 Mon Sep 17 00:00:00 2001 From: Sergey Radionov Date: Thu, 3 Sep 2020 19:27:00 +0700 Subject: [PATCH 09/18] initial snap support added (#210) --- snap/snapcraft.yaml | 71 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 snap/snapcraft.yaml diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 00000000..a80ede85 --- /dev/null +++ b/snap/snapcraft.yaml @@ -0,0 +1,71 @@ +name: zano +base: core18 +adopt-info: zano +summary: "Zano coin: official wallet. Secure. Scalable. Easy to Use." +description: | + Zano is a scalable and secure coin, designed for use in e-commerce. + The technology behind our blockchain provides reliability, security, + and flexibility a perfect option for P2P transactions. + More info: http://zano.org +grade: devel +confinement: devmode + +architectures: + - build-on: amd64 + - build-on: i386 + +environment: + LC_ALL: C + +parts: + zano: + source: https://github.com/hyle-team/zano.git + plugin: cmake + override-pull: | + snapcraftctl pull + snapcraftctl set-version "$(git describe)" + configflags: + - -DBUILD_GUI=TRUE + override-build: | + snapcraftctl build + mkdir -p $SNAPCRAFT_PART_INSTALL/opt/Zano + cp $SNAPCRAFT_PART_BUILD/src/Zano $SNAPCRAFT_PART_INSTALL/opt/Zano/ + cp $SNAPCRAFT_PART_BUILD/src/simplewallet $SNAPCRAFT_PART_INSTALL/opt/Zano/ + cp $SNAPCRAFT_PART_BUILD/src/zanod $SNAPCRAFT_PART_INSTALL/opt/Zano/ + rsync -a $SNAPCRAFT_PART_SRC/src/gui/qt-daemon/html $SNAPCRAFT_PART_INSTALL/opt/Zano --exclude less --exclude package.json --exclude gulpfile.js + build-packages: + - make + - g++ + - libboost-all-dev + - qtwebengine5-dev + - rsync + build-attributes: [keep-execstack] + stage-packages: + - libboost-system1.65.1 + - libboost-filesystem1.65.1 + - libboost-thread1.65.1 + - libboost-date-time1.65.1 + - libboost-chrono1.65.1 + - libboost-regex1.65.1 + - libboost-serialization1.65.1 + - libboost-program-options1.65.1 + - libboost-locale1.65.1 + +apps: + zano: + command: opt/Zano/Zano --data-dir $SNAP_USER_COMMON + extensions: + - kde-neon + plugs: + - network + - home + simplewallet: + command: opt/Zano/simplewallet + plugs: + - network + - home + zanod: + command: opt/Zano/zanod --data-dir $SNAP_USER_COMMON + plugs: + - network + - network-bind From 211c1b4838d7f9e978c2d0520a72196ea0f0e5fc Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 3 Sep 2020 23:20:25 +0200 Subject: [PATCH 10/18] fixing i386 build --- contrib/db/liblmdb/mdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/db/liblmdb/mdb.c b/contrib/db/liblmdb/mdb.c index ca9f3b12..f9b48233 100644 --- a/contrib/db/liblmdb/mdb.c +++ b/contrib/db/liblmdb/mdb.c @@ -133,7 +133,7 @@ extern int cacheflush(char *addr, int nbytes, int cache); #ifdef _WIN32 typedef int64_t off64_t; #else -typedef off_t off64_t; +//typedef off_t off64_t; #endif From 038348ac779f54e7d1594aed3d09e7c0e9aa2bbf Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 4 Sep 2020 12:32:21 +0200 Subject: [PATCH 11/18] Changed devmode to strict --- snap/snapcraft.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index a80ede85..574a8602 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -8,7 +8,7 @@ description: | and flexibility a perfect option for P2P transactions. More info: http://zano.org grade: devel -confinement: devmode +confinement: strict architectures: - build-on: amd64 From 1028751ee69a08623f32317bda18359df8c211b2 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 4 Sep 2020 14:03:56 +0200 Subject: [PATCH 12/18] grade -> stable --- snap/snapcraft.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 574a8602..e8bd23e0 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -7,7 +7,7 @@ description: | The technology behind our blockchain provides reliability, security, and flexibility a perfect option for P2P transactions. More info: http://zano.org -grade: devel +grade: stable confinement: strict architectures: From f24e271119de3528c546c44e472cbe414664696f Mon Sep 17 00:00:00 2001 From: Sergey Radionov Date: Sat, 5 Sep 2020 22:29:41 +0700 Subject: [PATCH 13/18] Some minor issues are fixed (#212) * It's just waste of resources to use temp variable to call static members also, according to docs, QString::fromStdString already take care about utf8 conversion, so there is no need to do std::string -> C string -> QString conversion. * Don't try use tray actions if tray is not available. It just leads to the crash. --- src/gui/qt-daemon/application/mainwindow.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index 80777b98..78a1ac0d 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -941,9 +941,12 @@ QString MainWindow::set_localization_strings(const QString param) else { m_localization = lr.strings; - m_quit_action->setText(QString().fromUtf8(m_localization[localization_id_quit].c_str())); - m_restore_action->setText(QString().fromUtf8(m_localization[localization_id_tray_menu_show].c_str())); - m_minimize_action->setText(QString().fromUtf8(m_localization[localization_id_tray_menu_minimize].c_str())); + if(m_quit_action) + m_quit_action->setText(QString::fromStdString(m_localization[localization_id_quit])); + if(m_restore_action) + m_restore_action->setText(QString::fromStdString(m_localization[localization_id_tray_menu_show])); + if(m_minimize_action) + m_minimize_action->setText(QString::fromStdString(m_localization[localization_id_tray_menu_minimize])); resp.error_code = API_RETURN_CODE_OK; LOG_PRINT_L0("New localization set, language title: " << lr.language_title << ", strings " << lr.strings.size()); } From 349709298dd5c6a801d194d79ecb53ade0965f36 Mon Sep 17 00:00:00 2001 From: Sergey Radionov Date: Sun, 6 Sep 2020 03:13:03 +0700 Subject: [PATCH 14/18] snap: fixed run on strict confinement (#213) --- snap/snapcraft.yaml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index a80ede85..9eb0e524 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -14,9 +14,6 @@ architectures: - build-on: amd64 - build-on: i386 -environment: - LC_ALL: C - parts: zano: source: https://github.com/hyle-team/zano.git @@ -59,6 +56,11 @@ apps: plugs: - network - home + - desktop + - opengl #for QML support + - browser-support #for Qt WebEngine support + - audio-playback + - unity7 #for tray icon support simplewallet: command: opt/Zano/simplewallet plugs: @@ -66,6 +68,8 @@ apps: - home zanod: command: opt/Zano/zanod --data-dir $SNAP_USER_COMMON + environment: + LC_ALL: C plugs: - network - network-bind From 4ba14a2d4f91cf43348dd5b55a04b593bc901e4b Mon Sep 17 00:00:00 2001 From: Sergey Radionov Date: Sun, 6 Sep 2020 03:13:03 +0700 Subject: [PATCH 15/18] snap: fixed run on strict confinement (#213) --- snap/snapcraft.yaml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index e8bd23e0..f27305af 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -14,9 +14,6 @@ architectures: - build-on: amd64 - build-on: i386 -environment: - LC_ALL: C - parts: zano: source: https://github.com/hyle-team/zano.git @@ -59,6 +56,11 @@ apps: plugs: - network - home + - desktop + - opengl #for QML support + - browser-support #for Qt WebEngine support + - audio-playback + - unity7 #for tray icon support simplewallet: command: opt/Zano/simplewallet plugs: @@ -66,6 +68,8 @@ apps: - home zanod: command: opt/Zano/zanod --data-dir $SNAP_USER_COMMON + environment: + LC_ALL: C plugs: - network - network-bind From 9067e09e2216b9bcbf5c297ee127f78bd1fe668c Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 7 Sep 2020 17:36:41 +0300 Subject: [PATCH 16/18] wallet: fix for outgoing unconfirmed txs handling in tracking wallets --- src/wallet/wallet2.cpp | 102 ++++++++++++++++++++++++++--------------- src/wallet/wallet2.h | 1 + 2 files changed, 67 insertions(+), 36 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index d06c9020..9ced041a 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -327,42 +327,12 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t const currency::txin_to_key& intk = boost::get(in); // check if this input spends our output - //transfer_details* p_td = nullptr; uint64_t tid = UINT64_MAX; if (is_auditable() && is_watch_only()) { - // auditable wallet - // try to find a reference among own UTXOs - std::vector abs_key_offsets = relative_output_offsets_to_absolute(intk.key_offsets); // potential speed-up: don't convert to abs offsets as we interested only in direct spends for auditable wallets. Now it's kind a bit paranoid. - for(auto v : abs_key_offsets) - { - if (v.type() != typeid(uint64_t)) - continue; - uint64_t gindex = boost::get(v); - auto it = m_amount_gindex_to_transfer_id.find(std::make_pair(intk.amount, gindex)); - if (it != m_amount_gindex_to_transfer_id.end()) - { - tid = it->second; - WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(tid < m_transfers.size(), "invalid tid: " << tid << ", ref from input with amount: " << intk.amount << ", gindex: " << gindex); - auto& td = m_transfers[it->second]; - if (intk.key_offsets.size() != 1) - { - // own output was used in non-direct transaction - // the core should not allow this to happen, the only way it may happen - mixing in own output that was sent without mix_attr == 1 - // log strange situation - std::stringstream ss; - ss << "own transfer tid=" << tid << " tx=" << td.tx_hash() << " mix_attr=" << td.mix_attr() << ", is referenced by a transaction with mixins, ref from input with amount: " << intk.amount << ", gindex: " << gindex; - WLT_LOG_YELLOW(ss.str(), LOG_LEVEL_0); - if (m_wcallback) - m_wcallback->on_message(i_wallet2_callback::ms_yellow, ss.str()); - continue; - } - WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(!td.is_spent(), "transfer is spent, tid: " << tid << ", ref from input with amount: " << intk.amount << ", gindex: " << gindex); - // own output is spent, handle it - break; - } - } + // tracking wallet, assuming all outputs are spent directly because of mix_attr = 1 + tid = get_directly_spent_transfer_id_by_input_in_tracking_wallet(intk); } else { @@ -1584,6 +1554,49 @@ bool wallet2::has_related_alias_entry_unconfirmed(const currency::transaction& t return false; } //---------------------------------------------------------------------------------------------------- +uint64_t wallet2::get_directly_spent_transfer_id_by_input_in_tracking_wallet(const currency::txin_to_key& intk) +{ + WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(is_auditable() && is_watch_only(), "this is not an auditable-watch-only (tracking) wallet"); + + uint64_t tid = UINT64_MAX; + + // try to find a reference among own UTXOs + std::vector abs_key_offsets = relative_output_offsets_to_absolute(intk.key_offsets); // potential speed-up: don't convert to abs offsets as we interested only in direct spends for auditable wallets. Now it's kind a bit paranoid. + for (auto v : abs_key_offsets) + { + if (v.type() != typeid(uint64_t)) + continue; + uint64_t gindex = boost::get(v); + auto it = m_amount_gindex_to_transfer_id.find(std::make_pair(intk.amount, gindex)); + if (it != m_amount_gindex_to_transfer_id.end()) + { + tid = it->second; + WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(tid < m_transfers.size(), "invalid tid: " << tid << ", ref from input with amount: " << intk.amount << ", gindex: " << gindex); + auto& td = m_transfers[it->second]; + if (intk.key_offsets.size() != 1) + { + // own output was used in non-direct transaction + // the core should not allow this to happen, the only way it may happen - mixing in own output that was sent without mix_attr == 1 + // log strange situation + std::stringstream ss; + ss << "own transfer tid=" << tid << " tx=" << td.tx_hash() << " mix_attr=" << td.mix_attr() << ", is referenced by a transaction with mixins, ref from input with amount: " << intk.amount << ", gindex: " << gindex; + WLT_LOG_YELLOW(ss.str(), LOG_LEVEL_0); + if (m_wcallback) + m_wcallback->on_message(i_wallet2_callback::ms_yellow, ss.str()); + WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(td.mix_attr() != CURRENCY_TO_KEY_OUT_FORCED_NO_MIX, ss.str()); // if mix_attr == 1 this should never happen (mixing in an output with mix_attr = 1) as the core must reject such txs + // our own output has mix_attr != 1 for some reason (a sender did not set correct mix_attr e.g.) + // but mixin count > 1 so we can't say it is spent for sure + tid = UINT64_MAX; + continue; + } + WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(td.m_spent_height == 0, "transfer is spent in blockchain, tid: " << tid << ", ref from input with amount: " << intk.amount << ", gindex: " << gindex); + // okay, own output is being spent, return it + break; + } + } + return tid; +} +//---------------------------------------------------------------------------------------------------- void wallet2::scan_tx_pool(bool& has_related_alias_in_unconfirmed) { //get transaction pool content @@ -1663,12 +1676,29 @@ void wallet2::scan_tx_pool(bool& has_related_alias_in_unconfirmed) auto& in = tx.vin[i]; if (in.type() == typeid(currency::txin_to_key)) { - auto it = m_key_images.find(boost::get(in).k_image); - if (it != m_key_images.end()) + const currency::txin_to_key& intk = boost::get(in); + uint64_t tid = UINT64_MAX; + if (is_auditable() && is_watch_only()) { - tx_money_spent_in_ins += boost::get(in).amount; + // tracking wallet, assuming all outputs are spent directly because of mix_attr = 1 + tid = get_directly_spent_transfer_id_by_input_in_tracking_wallet(intk); + } + else + { + // wallet with spend secret key -- we can calculate own key images and then search among them + auto it = m_key_images.find(intk.k_image); + if (it != m_key_images.end()) + { + tid = it->second; + } + } + + if (tid != UINT64_MAX) + { + // own output is being spent by this input + tx_money_spent_in_ins += intk.amount; td.spent_indices.push_back(i); - spend_transfers.push_back(it->second); + spend_transfers.push_back(tid); } } else if (in.type() == typeid(currency::txin_multisig)) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 4f3a5b48..e0507696 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -936,6 +936,7 @@ private: //void check_if_block_matched(uint64_t i, const crypto::hash& id, bool& block_found, bool& block_matched, bool& full_reset_needed); uint64_t detach_from_block_ids(uint64_t height); uint64_t get_wallet_minimum_height(); + uint64_t get_directly_spent_transfer_id_by_input_in_tracking_wallet(const currency::txin_to_key& intk); void push_alias_info_to_extra_according_to_hf_status(const currency::extra_alias_entry& ai, std::vector& extra); void remove_transfer_from_amount_gindex_map(uint64_t tid); From e52412facb59202ce4b58c796e7aeaed83de9d60 Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 7 Sep 2020 17:36:41 +0300 Subject: [PATCH 17/18] wallet: fix for outgoing unconfirmed txs handling in tracking wallets --- src/wallet/wallet2.cpp | 102 ++++++++++++++++++++++++++--------------- src/wallet/wallet2.h | 1 + 2 files changed, 67 insertions(+), 36 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 64e1d0e1..ad616c6b 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -324,42 +324,12 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t const currency::txin_to_key& intk = boost::get(in); // check if this input spends our output - //transfer_details* p_td = nullptr; uint64_t tid = UINT64_MAX; if (is_auditable() && is_watch_only()) { - // auditable wallet - // try to find a reference among own UTXOs - std::vector abs_key_offsets = relative_output_offsets_to_absolute(intk.key_offsets); // potential speed-up: don't convert to abs offsets as we interested only in direct spends for auditable wallets. Now it's kind a bit paranoid. - for(auto v : abs_key_offsets) - { - if (v.type() != typeid(uint64_t)) - continue; - uint64_t gindex = boost::get(v); - auto it = m_amount_gindex_to_transfer_id.find(std::make_pair(intk.amount, gindex)); - if (it != m_amount_gindex_to_transfer_id.end()) - { - tid = it->second; - WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(tid < m_transfers.size(), "invalid tid: " << tid << ", ref from input with amount: " << intk.amount << ", gindex: " << gindex); - auto& td = m_transfers[it->second]; - if (intk.key_offsets.size() != 1) - { - // own output was used in non-direct transaction - // the core should not allow this to happen, the only way it may happen - mixing in own output that was sent without mix_attr == 1 - // log strange situation - std::stringstream ss; - ss << "own transfer tid=" << tid << " tx=" << td.tx_hash() << " mix_attr=" << td.mix_attr() << ", is referenced by a transaction with mixins, ref from input with amount: " << intk.amount << ", gindex: " << gindex; - WLT_LOG_YELLOW(ss.str(), LOG_LEVEL_0); - if (m_wcallback) - m_wcallback->on_message(i_wallet2_callback::ms_yellow, ss.str()); - continue; - } - WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(!td.is_spent(), "transfer is spent, tid: " << tid << ", ref from input with amount: " << intk.amount << ", gindex: " << gindex); - // own output is spent, handle it - break; - } - } + // tracking wallet, assuming all outputs are spent directly because of mix_attr = 1 + tid = get_directly_spent_transfer_id_by_input_in_tracking_wallet(intk); } else { @@ -1567,6 +1537,49 @@ bool wallet2::has_related_alias_entry_unconfirmed(const currency::transaction& t return false; } //---------------------------------------------------------------------------------------------------- +uint64_t wallet2::get_directly_spent_transfer_id_by_input_in_tracking_wallet(const currency::txin_to_key& intk) +{ + WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(is_auditable() && is_watch_only(), "this is not an auditable-watch-only (tracking) wallet"); + + uint64_t tid = UINT64_MAX; + + // try to find a reference among own UTXOs + std::vector abs_key_offsets = relative_output_offsets_to_absolute(intk.key_offsets); // potential speed-up: don't convert to abs offsets as we interested only in direct spends for auditable wallets. Now it's kind a bit paranoid. + for (auto v : abs_key_offsets) + { + if (v.type() != typeid(uint64_t)) + continue; + uint64_t gindex = boost::get(v); + auto it = m_amount_gindex_to_transfer_id.find(std::make_pair(intk.amount, gindex)); + if (it != m_amount_gindex_to_transfer_id.end()) + { + tid = it->second; + WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(tid < m_transfers.size(), "invalid tid: " << tid << ", ref from input with amount: " << intk.amount << ", gindex: " << gindex); + auto& td = m_transfers[it->second]; + if (intk.key_offsets.size() != 1) + { + // own output was used in non-direct transaction + // the core should not allow this to happen, the only way it may happen - mixing in own output that was sent without mix_attr == 1 + // log strange situation + std::stringstream ss; + ss << "own transfer tid=" << tid << " tx=" << td.tx_hash() << " mix_attr=" << td.mix_attr() << ", is referenced by a transaction with mixins, ref from input with amount: " << intk.amount << ", gindex: " << gindex; + WLT_LOG_YELLOW(ss.str(), LOG_LEVEL_0); + if (m_wcallback) + m_wcallback->on_message(i_wallet2_callback::ms_yellow, ss.str()); + WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(td.mix_attr() != CURRENCY_TO_KEY_OUT_FORCED_NO_MIX, ss.str()); // if mix_attr == 1 this should never happen (mixing in an output with mix_attr = 1) as the core must reject such txs + // our own output has mix_attr != 1 for some reason (a sender did not set correct mix_attr e.g.) + // but mixin count > 1 so we can't say it is spent for sure + tid = UINT64_MAX; + continue; + } + WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(td.m_spent_height == 0, "transfer is spent in blockchain, tid: " << tid << ", ref from input with amount: " << intk.amount << ", gindex: " << gindex); + // okay, own output is being spent, return it + break; + } + } + return tid; +} +//---------------------------------------------------------------------------------------------------- void wallet2::scan_tx_pool(bool& has_related_alias_in_unconfirmed) { //get transaction pool content @@ -1646,12 +1659,29 @@ void wallet2::scan_tx_pool(bool& has_related_alias_in_unconfirmed) auto& in = tx.vin[i]; if (in.type() == typeid(currency::txin_to_key)) { - auto it = m_key_images.find(boost::get(in).k_image); - if (it != m_key_images.end()) + const currency::txin_to_key& intk = boost::get(in); + uint64_t tid = UINT64_MAX; + if (is_auditable() && is_watch_only()) { - tx_money_spent_in_ins += boost::get(in).amount; + // tracking wallet, assuming all outputs are spent directly because of mix_attr = 1 + tid = get_directly_spent_transfer_id_by_input_in_tracking_wallet(intk); + } + else + { + // wallet with spend secret key -- we can calculate own key images and then search among them + auto it = m_key_images.find(intk.k_image); + if (it != m_key_images.end()) + { + tid = it->second; + } + } + + if (tid != UINT64_MAX) + { + // own output is being spent by this input + tx_money_spent_in_ins += intk.amount; td.spent_indices.push_back(i); - spend_transfers.push_back(it->second); + spend_transfers.push_back(tid); } } else if (in.type() == typeid(currency::txin_multisig)) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 65400b88..349750db 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -927,6 +927,7 @@ private: //void check_if_block_matched(uint64_t i, const crypto::hash& id, bool& block_found, bool& block_matched, bool& full_reset_needed); uint64_t detach_from_block_ids(uint64_t height); uint64_t get_wallet_minimum_height(); + uint64_t get_directly_spent_transfer_id_by_input_in_tracking_wallet(const currency::txin_to_key& intk); void push_alias_info_to_extra_according_to_hf_status(const currency::extra_alias_entry& ai, std::vector& extra); void remove_transfer_from_amount_gindex_map(uint64_t tid); From 3678ba2154bd5d785dca2c019c90db0279b638ba Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 7 Sep 2020 20:59:44 +0200 Subject: [PATCH 18/18] fixed connectivity for simplewallet in srv mode --- src/wallet/wallet2.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index ad616c6b..33e18f82 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -155,6 +155,7 @@ void wallet2::init(const std::string& daemon_address) { m_miner_text_info = PROJECT_VERSION_LONG; m_core_proxy->set_connection_addr(daemon_address); + m_core_proxy->check_connection(); } //---------------------------------------------------------------------------------------------------- bool wallet2::set_core_proxy(const std::shared_ptr& proxy)