From b41d87a05159f58d61dfc12ec9eba376158a0fde Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 27 May 2021 13:19:20 +0200 Subject: [PATCH 01/83] fixed errors reporting for mobile wallet --- src/wallet/wallet_errors.h | 32 ++++++++++++------- tests/functional_tests/plain_wallet_tests.cpp | 13 ++++++-- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h index efafaf97..c2636d70 100644 --- a/src/wallet/wallet_errors.h +++ b/src/wallet/wallet_errors.h @@ -385,14 +385,20 @@ namespace tools std::string to_string() const { std::ostringstream ss; - ss << transfer_error::to_string() << ", mixin_count = " << m_mixin_count << ", scanty_outs:"; - for (const auto& outs_for_amount : m_scanty_outs) - { - ss << '\n' << currency::print_money(outs_for_amount.amount) << " - " << outs_for_amount.outs.size(); - } + ss << API_RETURN_CODE_NOT_ENOUGH_OUTPUTS_FOR_MIXING; + //ss << transfer_error::to_string() << ", mixin_count = " << m_mixin_count << ", scanty_outs:"; + //for (const auto& outs_for_amount : m_scanty_outs) + //{ + // ss << '\n' << currency::print_money(outs_for_amount.amount) << " - " << outs_for_amount.outs.size(); + //} return ss.str(); } + virtual const char* what() const noexcept + { + return API_RETURN_CODE_NOT_ENOUGH_OUTPUTS_FOR_MIXING; + } + private: scanty_outs_t m_scanty_outs; size_t m_mixin_count; @@ -534,14 +540,18 @@ namespace tools std::string to_string() const { std::ostringstream ss; - currency::transaction tx = m_tx; - ss << transfer_error::to_string() << - ", tx_size_limit = " << m_tx_size_limit << - ", tx size = " << get_object_blobsize(m_tx) << - ", tx:\n" << currency::obj_to_json_str(tx); + ss << API_RETURN_CODE_TX_IS_TOO_BIG; + //currency::transaction tx = m_tx; + //ss << transfer_error::to_string() << + // ", tx_size_limit = " << m_tx_size_limit << + // ", tx size = " << get_object_blobsize(m_tx) << + // ", tx:\n" << currency::obj_to_json_str(tx); return ss.str(); } - + virtual const char* what() const noexcept + { + return API_RETURN_CODE_TX_IS_TOO_BIG; + } private: currency::transaction m_tx; uint64_t m_tx_size_limit; diff --git a/tests/functional_tests/plain_wallet_tests.cpp b/tests/functional_tests/plain_wallet_tests.cpp index f6efe29f..e92084fb 100644 --- a/tests/functional_tests/plain_wallet_tests.cpp +++ b/tests/functional_tests/plain_wallet_tests.cpp @@ -40,11 +40,18 @@ void run_plain_wallet_api_test() std::string res = plain_wallet::sync_call("get_seed_phrase_info", 0, "{\"seed_phrase\":\"aZxat4HAWriVQ3enkGcVsrZRdMseAJswG3CSEwTqZS246VsFQ53w26eZstYsu1jWE74Atz9ajLxFnBsVTafncWNH5SMv4zHFaTS:1780c4d5dd7e97cc4a75ea8baa7977d12ef948b9a6dddc2a9a37e5e22ac7180e:1599495055\"}"); - res = plain_wallet::restore("footstep knowledge fur capture honey minute carefully peaceful lovely crawl lunch government nightmare friendship myself sign possibly plan flower depression bread rainbow wrong hardly dark chest", - "test_wall2.zan", "111", ""); +// res = plain_wallet::restore("footstep knowledge fur capture honey minute carefully peaceful lovely crawl lunch government nightmare friendship myself sign possibly plan flower depression bread rainbow wrong hardly dark chest", +// "test_wall2.zan", "111", ""); + +// epee::misc_utils::sleep_no_w(30000); + +// plain_wallet::close_wallet(0); + res = plain_wallet::open("test_wall2.zan", "111"); - epee::misc_utils::sleep_no_w(10000000); + res = plain_wallet::invoke(0, "{\"method\":\"transfer\",\"params\":{\"destinations\":[{\"amount\":10000000000,\"address\":\"aZxat4HAWriVQ3enkGcVsrZRdMseAJswG3CSEwTqZS246VsFQ53w26eZstYsu1jWE74Atz9ajLxFnBsVTafncWNH5SMv4zHFaTS\"}],\"fee\":10000000000,\"mixin\":1011111,\"payment_id\":\"\",\"push_payer\":true,\"hide_receiver\":false}}"); + + //epee::misc_utils::sleep_no_w(10000000); //std::string key = plain_wallet::generate_random_key(10); //std::string test_data = "1234567890 test test "; From a9eb5f5f5ab7251e4ca7b745e705f879612e23ed Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 28 May 2021 20:36:17 +0200 Subject: [PATCH 02/83] Added extra logs to research Orson's problem --- src/wallet/wallet2.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 9c8c9c33..0cfdd67b 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2682,7 +2682,15 @@ void wallet2::load(const std::wstring& wallet_, const std::string& password) if (m_watch_only && !is_auditable()) load_keys2ki(true, need_to_resync); - WLT_LOG_L0("Loaded wallet file" << (m_watch_only ? " (WATCH ONLY) " : " ") << string_encoding::convert_to_ansii(m_wallet_file) << " with public address: " << m_account.get_public_address_str()); + boost::system::error_code ec = AUTO_VAL_INIT(ec); + m_current_wallet_file_size = boost::filesystem::file_size(wallet_, ec); + + WLT_LOG_L0("Loaded wallet file" << (m_watch_only ? " (WATCH ONLY) " : " ") << string_encoding::convert_to_ansii(m_wallet_file) + << " with public address: " << m_account.get_public_address_str() + << ", file_size=" << m_current_wallet_file_size + << ", blockchain_size: " << m_chain.get_blockchain_current_size() + ); + WLT_LOG_L0("(after loading: pending_key_images: " << m_pending_key_images.size() << ", pki file elements: " << m_pending_key_images_file_container.size() << ", tx_keys: " << m_tx_keys.size() << ")"); if (need_to_resync) @@ -2691,9 +2699,6 @@ void wallet2::load(const std::wstring& wallet_, const std::string& password) WLT_LOG_L0("Unable to load history data from wallet file, wallet will be resynced!"); } - boost::system::error_code ec = AUTO_VAL_INIT(ec); - m_current_wallet_file_size = boost::filesystem::file_size(wallet_, ec); - THROW_IF_TRUE_WALLET_EX(need_to_resync, error::wallet_load_notice_wallet_restored, epee::string_encoding::convert_to_ansii(m_wallet_file)); } //---------------------------------------------------------------------------------------------------- @@ -2755,8 +2760,8 @@ void wallet2::store(const std::wstring& path_to_save, const std::string& passwor data_file.flush(); data_file.close(); - - WLT_LOG_L1("Stored successfully to temporary file " << tmp_file_path.string()); + boost::uintmax_t tmp_file_size = boost::filesystem::file_size(tmp_file_path); + WLT_LOG_L0("Stored successfully to temporary file " << tmp_file_path.string() << ", file size=" << tmp_file_size); // for the sake of safety perform a double-renaming: wallet file -> old tmp, new tmp -> wallet file, remove old tmp @@ -2785,7 +2790,9 @@ void wallet2::store(const std::wstring& path_to_save, const std::string& passwor m_current_wallet_file_size = boost::filesystem::file_size(path_to_save, ec); if (path_to_save_exists && !tmp_file_path_exists && !tmp_old_file_path_exists) { - WLT_LOG_L0("Wallet was successfully stored to " << ascii_path_to_save); + + WLT_LOG_L0("Wallet was successfully stored to " << ascii_path_to_save << ", file size=" << m_current_wallet_file_size + << " blockchain_size: " << m_chain.get_blockchain_current_size()); } else { From ce79505087f90cefb9a963959bea5eff6b2760e0 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 31 May 2021 22:24:38 +0300 Subject: [PATCH 03/83] added wallet version logging on load/store --- src/wallet/wallet2.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index f1ab885e..1a6ce4f0 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -698,6 +698,12 @@ namespace tools template inline void serialize(t_archive &a, const unsigned int ver) { + if (t_archive::is_saving::value) + { + WLT_LOG_MAGENTA("Serializing file with ver: " << ver, LOG_LEVEL_0); + } + + // do not load wallet if data version is greather than the code version if (ver > WALLET_FILE_SERIALIZATION_VERSION) { @@ -707,7 +713,7 @@ namespace tools if (ver < 149) { - WLT_LOG_MAGENTA("Wallet file truncated due to old version", LOG_LEVEL_0); + WLT_LOG_MAGENTA("Wallet file truncated due to old version. ver: " << ver << ", WALLET_FILE_SERIALIZATION_VERSION=" << WALLET_FILE_SERIALIZATION_VERSION, LOG_LEVEL_0); return; } From 9ff5e7a9ca49c23befdc0e63d1c89c14bf1063a3 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 1 Jun 2021 15:45:30 +0300 Subject: [PATCH 04/83] got rid from ugly hardcoded paths --- CMakeLists.txt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d6b61e72..f21fb093 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,10 +185,7 @@ endif() message("CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}") if(CMAKE_SYSTEM_NAME STREQUAL "iOS") - set(Boost_INCLUDE_DIRS "/Users/roky/projects/Zano/mobile_repo/ofxiOSBoost/libs/boost/include") - set(Boost_LIBRARY_DIRS "/Users/roky/projects/Zano/mobile_repo/ofxiOSBoost/libs/boost/ios/") set(Boost_LIBRARIES "libboost.a") - set(Boost_VERSION "ofxiOSBoost 1.60.0") #workaround for new XCode 12 policy for builds(now it includes a slice for the "arm64" when builds for simulator) set(__iphoneos_archs "armv7 armv7s arm64") set(__iphonesimulator_archs "i386 x86_64") @@ -197,10 +194,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "iOS") set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=iphonesimulator*] "${__iphonesimulator_archs}") set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphonesimulator*] "${__iphonesimulator_archs}") elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") - set(Boost_INCLUDE_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/1.69.0/include") - set(Boost_LIBRARY_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/1.69.0/libs/llvm/${CMAKE_ANDROID_ARCH_ABI}/") + set(Boost_LIBRARY_DIRS "${Boost_LIBRARY_DIRS}/${CMAKE_ANDROID_ARCH_ABI}/") set(Boost_LIBRARIES "${Boost_LIBRARY_DIRS}libboost_system.a;${Boost_LIBRARY_DIRS}libboost_filesystem.a;${Boost_LIBRARY_DIRS}libboost_thread.a;${Boost_LIBRARY_DIRS}libboost_timer.a;${Boost_LIBRARY_DIRS}libboost_date_time.a;${Boost_LIBRARY_DIRS}libboost_chrono.a;${Boost_LIBRARY_DIRS}libboost_regex.a;${Boost_LIBRARY_DIRS}libboost_serialization.a;${Boost_LIBRARY_DIRS}libboost_atomic.a;${Boost_LIBRARY_DIRS}libboost_program_options.a") - set(Boost_VERSION "PurpleI2PBoost 1.69.0") else() find_package(Boost 1.55 REQUIRED COMPONENTS system filesystem thread timer date_time chrono regex serialization atomic program_options locale) endif() From 8f12632ca6d8d5055c2444402bcbbf6d40908d85 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 1 Jun 2021 23:20:24 +0300 Subject: [PATCH 05/83] android fix for new boost(1_72) --- contrib/epee/include/net/abstract_tcp_server2.inl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl index 6e57b54a..2bb45f69 100644 --- a/contrib/epee/include/net/abstract_tcp_server2.inl +++ b/contrib/epee/include/net/abstract_tcp_server2.inl @@ -588,10 +588,18 @@ bool boosted_tcp_server::timed_wait_server_stop(uint64_t wai TRY_ENTRY(); boost::chrono::milliseconds ms(wait_mseconds); for(std::size_t i = 0; i < m_threads.size(); ++i) { - if(m_threads[i]->joinable() && !m_threads[i]->try_join_for(ms)) { +#ifdef ANDROID_BUILD + if (m_threads[i]->joinable()) + { + m_threads[i]->join(); + } +#else + if (m_threads[i]->joinable() && !m_threads[i]->try_join_for(ms)) + { LOG_PRINT_L0("Interrupting thread " << m_threads[i]->native_handle()); m_threads[i]->interrupt(); } +#endif } return true; CATCH_ENTRY_L0("boosted_tcp_server::timed_wait_server_stop", false); From d31802a703823fdac7da574f858dde799628ac01 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 2 Jun 2021 19:12:59 +0300 Subject: [PATCH 06/83] fixed warning --- contrib/epee/include/serialization/keyvalue_serialization.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/epee/include/serialization/keyvalue_serialization.h b/contrib/epee/include/serialization/keyvalue_serialization.h index 31a4fb8b..31c90df7 100644 --- a/contrib/epee/include/serialization/keyvalue_serialization.h +++ b/contrib/epee/include/serialization/keyvalue_serialization.h @@ -115,7 +115,7 @@ public: \ template inline static bool get_value_of_flag_by_mask(const t_uint& given_flags) { - return given_flags&mask == 0 ? false : true; + return (given_flags&mask) == 0 ? false : true; } }; From 569d64b5f2841901900498858974e8080f61da2a Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 2 Jun 2021 20:50:04 +0300 Subject: [PATCH 07/83] experimental: try different portable_storage for android --- src/common/boost_serialization_helper.h | 28 ++++ src/common/portable_binary_archive.hpp | 46 ++++++ src/common/portable_binary_iarchive.cpp | 131 +++++++++++++++ src/common/portable_binary_iarchive.hpp | 204 ++++++++++++++++++++++++ src/common/portable_binary_oarchive.cpp | 98 ++++++++++++ src/common/portable_binary_oarchive.hpp | 191 ++++++++++++++++++++++ src/wallet/wallet2.cpp | 4 +- 7 files changed, 700 insertions(+), 2 deletions(-) create mode 100644 src/common/portable_binary_archive.hpp create mode 100644 src/common/portable_binary_iarchive.cpp create mode 100644 src/common/portable_binary_iarchive.hpp create mode 100644 src/common/portable_binary_oarchive.cpp create mode 100644 src/common/portable_binary_oarchive.hpp diff --git a/src/common/boost_serialization_helper.h b/src/common/boost_serialization_helper.h index 2ba8a52c..81708f39 100644 --- a/src/common/boost_serialization_helper.h +++ b/src/common/boost_serialization_helper.h @@ -9,6 +9,10 @@ #include #include #include +#include "common/portable_binary_iarchive.hpp" +#include "common/portable_binary_oarchive.hpp" + +//#include @@ -100,4 +104,28 @@ namespace tools return !stream.fail(); CATCH_ENTRY_L0("portable_unserialize_obj_from_stream", false); } + + template + bool portable_unserialize_obj_from_stream2(t_object& obj, t_stream& stream) + { + TRY_ENTRY(); + + portable_binary_iarchive a(stream); + + a >> obj; + return !stream.fail(); + CATCH_ENTRY_L0("portable_unserialize_obj_from_stream", false); + } + + template + bool portble_serialize_obj_to_stream2(t_object& obj, t_stream& stream) + { + TRY_ENTRY(); + + portable_binary_oarchive a(stream); + a << obj; + + return !stream.fail(); + CATCH_ENTRY_L0("portble_serialize_obj_to_stream", false); + } } diff --git a/src/common/portable_binary_archive.hpp b/src/common/portable_binary_archive.hpp new file mode 100644 index 00000000..eecd9508 --- /dev/null +++ b/src/common/portable_binary_archive.hpp @@ -0,0 +1,46 @@ +#ifndef PORTABLE_BINARY_ARCHIVE_HPP +#define PORTABLE_BINARY_ARCHIVE_HPP + +// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// MS compatible compilers support #pragma once +#if defined(_MSC_VER) +# pragma once +#endif + +#include +#include +#include + +#include +#if CHAR_BIT != 8 +#error This code assumes an eight-bit byte. +#endif + +#include +#include + +enum portable_binary_archive_flags { + endian_big = 0x4000, + endian_little = 0x8000 +}; + +//#if ( endian_big <= boost::archive::flags_last ) +//#error archive flags conflict +//#endif + +inline void +reverse_bytes(char size, char *address){ + char * first = address; + char * last = first + size - 1; + for(;first < last;++first, --last){ + char x = *last; + *last = *first; + *first = x; + } +} + +#endif // PORTABLE_BINARY_ARCHIVE_HPP diff --git a/src/common/portable_binary_iarchive.cpp b/src/common/portable_binary_iarchive.cpp new file mode 100644 index 00000000..a0b61d52 --- /dev/null +++ b/src/common/portable_binary_iarchive.cpp @@ -0,0 +1,131 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// portable_binary_iarchive.cpp + +// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for updates, documentation, and revision history. + +#include +#include + +#include +#include +#include + +#include "portable_binary_iarchive.hpp" + +void +portable_binary_iarchive::load_impl(boost::intmax_t & l, char maxsize){ + char size; + l = 0; + this->primitive_base_t::load(size); + + if(0 == size){ + return; + } + + bool negative = (size < 0); + if(negative) + size = -size; + + if(size > maxsize) + boost::serialization::throw_exception( + portable_binary_iarchive_exception() + ); + + char * cptr = reinterpret_cast(& l); + #ifdef BOOST_BIG_ENDIAN + cptr += (sizeof(boost::intmax_t) - size); + #endif + this->primitive_base_t::load_binary(cptr, size); + + #ifdef BOOST_BIG_ENDIAN + if(m_flags & endian_little) + #else + if(m_flags & endian_big) + #endif + reverse_bytes(size, cptr); + + if(negative) + l = -l; +} + +void +portable_binary_iarchive::load_override( + boost::archive::class_name_type & t +){ + std::string cn; + cn.reserve(BOOST_SERIALIZATION_MAX_KEY_SIZE); + load_override(cn); + if(cn.size() > (BOOST_SERIALIZATION_MAX_KEY_SIZE - 1)) + boost::serialization::throw_exception( + boost::archive::archive_exception( + boost::archive::archive_exception::invalid_class_name) + ); + std::memcpy(t, cn.data(), cn.size()); + // borland tweak + t.t[cn.size()] = '\0'; +} + +void +portable_binary_iarchive::init(unsigned int flags){ + if(0 == (flags & boost::archive::no_header)){ + // read signature in an archive version independent manner + std::string file_signature; + * this >> file_signature; + if(file_signature != boost::archive::BOOST_ARCHIVE_SIGNATURE()) + boost::serialization::throw_exception( + boost::archive::archive_exception( + boost::archive::archive_exception::invalid_signature + ) + ); + // make sure the version of the reading archive library can + // support the format of the archive being read + boost::archive::library_version_type input_library_version; + * this >> input_library_version; + + // extra little .t is to get around borland quirk + if(boost::archive::BOOST_ARCHIVE_VERSION() < input_library_version) + boost::serialization::throw_exception( + boost::archive::archive_exception( + boost::archive::archive_exception::unsupported_version + ) + ); + + #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205)) + this->set_library_version(input_library_version); + //#else + //#if ! BOOST_WORKAROUND(BOOST_MSVC, <= 1200) + //detail:: + //#endif + boost::archive::detail::basic_iarchive::set_library_version( + input_library_version + ); + #endif + } + unsigned char x; + load(x); + m_flags = x << CHAR_BIT; +} + +#include +#include + +namespace boost { +namespace archive { + +namespace detail { + template class archive_serializer_map; +} + +template class basic_binary_iprimitive< + portable_binary_iarchive, + std::istream::char_type, + std::istream::traits_type +> ; + +} // namespace archive +} // namespace boost diff --git a/src/common/portable_binary_iarchive.hpp b/src/common/portable_binary_iarchive.hpp new file mode 100644 index 00000000..3730660c --- /dev/null +++ b/src/common/portable_binary_iarchive.hpp @@ -0,0 +1,204 @@ +#ifndef PORTABLE_BINARY_IARCHIVE_HPP +#define PORTABLE_BINARY_IARCHIVE_HPP + +// MS compatible compilers support #pragma once +#if defined(_MSC_VER) +# pragma once +#endif + +#if defined(_MSC_VER) +#pragma warning( push ) +#pragma warning( disable : 4244 ) +#endif + +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// portable_binary_iarchive.hpp + +// (C) Copyright 2002-7 Robert Ramey - http://www.rrsd.com . +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for updates, documentation, and revision history. + +#include +#include +#include +#include +#include +#include +#include + +#include "portable_binary_archive.hpp" + +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// exception to be thrown if integer read from archive doesn't fit +// variable being loaded +class portable_binary_iarchive_exception : + public boost::archive::archive_exception +{ +public: + enum exception_code { + incompatible_integer_size + } m_exception_code ; + portable_binary_iarchive_exception(exception_code c = incompatible_integer_size ) : + boost::archive::archive_exception(boost::archive::archive_exception::other_exception), + m_exception_code(c) + {} + virtual const char *what( ) const throw( ) + { + const char *msg = "programmer error"; + switch(m_exception_code){ + case incompatible_integer_size: + msg = "integer cannot be represented"; + break; + default: + msg = boost::archive::archive_exception::what(); + assert(false); + break; + } + return msg; + } +}; + +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// "Portable" input binary archive. It addresses integer size and endienness so +// that binary archives can be passed across systems. Note:floating point types +// not addressed here +class portable_binary_iarchive : + public boost::archive::basic_binary_iprimitive< + portable_binary_iarchive, + std::istream::char_type, + std::istream::traits_type + >, + public boost::archive::detail::common_iarchive< + portable_binary_iarchive + > + { + typedef boost::archive::basic_binary_iprimitive< + portable_binary_iarchive, + std::istream::char_type, + std::istream::traits_type + > primitive_base_t; + typedef boost::archive::detail::common_iarchive< + portable_binary_iarchive + > archive_base_t; +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS +public: +#else + friend archive_base_t; + friend primitive_base_t; // since with override load below + friend class boost::archive::detail::interface_iarchive< + portable_binary_iarchive + >; + friend class boost::archive::load_access; +protected: +#endif + unsigned int m_flags; + void load_impl(boost::intmax_t & l, char maxsize); + + // default fall through for any types not specified here + template + void load(T & t){ + boost::intmax_t l; + load_impl(l, sizeof(T)); + // use cast to avoid compile time warning + //t = static_cast< T >(l); + t = T(l); + } + void load(boost::serialization::item_version_type & t){ + boost::intmax_t l; + load_impl(l, sizeof(boost::serialization::item_version_type)); + // use cast to avoid compile time warning + t = boost::serialization::item_version_type(l); + } + void load(boost::archive::version_type & t){ + boost::intmax_t l; + load_impl(l, sizeof(boost::archive::version_type)); + // use cast to avoid compile time warning + t = boost::archive::version_type(l); + } + void load(boost::archive::class_id_type & t){ + boost::intmax_t l; + load_impl(l, sizeof(boost::archive::class_id_type)); + // use cast to avoid compile time warning + t = boost::archive::class_id_type(static_cast(l)); + } + void load(std::string & t){ + this->primitive_base_t::load(t); + } + #ifndef BOOST_NO_STD_WSTRING + void load(std::wstring & t){ + this->primitive_base_t::load(t); + } + #endif + void load(float & t){ + this->primitive_base_t::load(t); + // floats not supported + //BOOST_STATIC_ASSERT(false); + } + void load(double & t){ + this->primitive_base_t::load(t); + // doubles not supported + //BOOST_STATIC_ASSERT(false); + } + void load(char & t){ + this->primitive_base_t::load(t); + } + void load(unsigned char & t){ + this->primitive_base_t::load(t); + } + typedef boost::archive::detail::common_iarchive + detail_common_iarchive; + template + void load_override(T & t){ + this->detail_common_iarchive::load_override(t); + } + void load_override(boost::archive::class_name_type & t); + // binary files don't include the optional information + void load_override(boost::archive::class_id_optional_type &){} + + void init(unsigned int flags); +public: + portable_binary_iarchive(std::istream & is, unsigned flags = 0) : + primitive_base_t( + * is.rdbuf(), + 0 != (flags & boost::archive::no_codecvt) + ), + archive_base_t(flags), + m_flags(0) + { + init(flags); + } + + portable_binary_iarchive( + std::basic_streambuf< + std::istream::char_type, + std::istream::traits_type + > & bsb, + unsigned int flags + ) : + primitive_base_t( + bsb, + 0 != (flags & boost::archive::no_codecvt) + ), + archive_base_t(flags), + m_flags(0) + { + init(flags); + } +}; + +// required by export in boost version > 1.34 +#ifdef BOOST_SERIALIZATION_REGISTER_ARCHIVE + BOOST_SERIALIZATION_REGISTER_ARCHIVE(portable_binary_iarchive) +#endif + +// required by export in boost <= 1.34 +#define BOOST_ARCHIVE_CUSTOM_IARCHIVE_TYPES portable_binary_iarchive + +#if defined(_MSC_VER) +#pragma warning( pop ) +#endif + +#endif // PORTABLE_BINARY_IARCHIVE_HPP diff --git a/src/common/portable_binary_oarchive.cpp b/src/common/portable_binary_oarchive.cpp new file mode 100644 index 00000000..6f94eeb5 --- /dev/null +++ b/src/common/portable_binary_oarchive.cpp @@ -0,0 +1,98 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// portable_binary_oarchive.cpp + +// (C) Copyright 2002-7 Robert Ramey - http://www.rrsd.com . +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for updates, documentation, and revision history. + +#include +#include +#include "portable_binary_oarchive.hpp" + +void +portable_binary_oarchive::save_impl( + const boost::intmax_t l, + const char maxsize +){ + char size = 0; + + if(l == 0){ + this->primitive_base_t::save(size); + return; + } + + boost::intmax_t ll; + bool negative = (l < 0); + if(negative) + ll = -l; + else + ll = l; + + do{ + ll >>= CHAR_BIT; + ++size; + }while(ll != 0); + + this->primitive_base_t::save( + static_cast(negative ? -size : size) + ); + + if(negative) + ll = -l; + else + ll = l; + char * cptr = reinterpret_cast(& ll); + #ifdef BOOST_BIG_ENDIAN + cptr += (sizeof(boost::intmax_t) - size); + if(m_flags & endian_little) + reverse_bytes(size, cptr); + #else + if(m_flags & endian_big) + reverse_bytes(size, cptr); + #endif + this->primitive_base_t::save_binary(cptr, size); +} + +void +portable_binary_oarchive::init(unsigned int flags) { + if(m_flags == (endian_big | endian_little)){ + boost::serialization::throw_exception( + portable_binary_oarchive_exception() + ); + } + if(0 == (flags & boost::archive::no_header)){ + // write signature in an archive version independent manner + const std::string file_signature( + boost::archive::BOOST_ARCHIVE_SIGNATURE() + ); + * this << file_signature; + // write library version + const boost::archive::library_version_type v( + boost::archive::BOOST_ARCHIVE_VERSION() + ); + * this << v; + } + save(static_cast(m_flags >> CHAR_BIT)); +} + +#include +#include + +namespace boost { +namespace archive { + +namespace detail { + template class archive_serializer_map; +} + +template class basic_binary_oprimitive< + portable_binary_oarchive, + std::ostream::char_type, + std::ostream::traits_type +> ; + +} // namespace archive +} // namespace boost diff --git a/src/common/portable_binary_oarchive.hpp b/src/common/portable_binary_oarchive.hpp new file mode 100644 index 00000000..317aa1d7 --- /dev/null +++ b/src/common/portable_binary_oarchive.hpp @@ -0,0 +1,191 @@ +#ifndef PORTABLE_BINARY_OARCHIVE_HPP +#define PORTABLE_BINARY_OARCHIVE_HPP + +// MS compatible compilers support #pragma once +#if defined(_MSC_VER) +# pragma once +#endif + +#if defined(_MSC_VER) +#pragma warning( push ) +#pragma warning( disable : 4244 ) +#endif + +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// portable_binary_oarchive.hpp + +// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for updates, documentation, and revision history. + +#include +#include +#include +#include +#include +#include + +#include "portable_binary_archive.hpp" + +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// exception to be thrown if integer read from archive doesn't fit +// variable being loaded +class portable_binary_oarchive_exception : + public boost::archive::archive_exception +{ +public: + typedef enum { + invalid_flags + } exception_code; + portable_binary_oarchive_exception(exception_code c = invalid_flags ) + {} + virtual const char *what( ) const throw( ) + { + const char *msg = "programmer error"; + switch(code){ + case invalid_flags: + msg = "cannot be both big and little endian"; + default: + boost::archive::archive_exception::what(); + } + return msg; + } +}; + +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// "Portable" output binary archive. This is a variation of the native binary +// archive. it addresses integer size and endienness so that binary archives can +// be passed across systems. Note:floating point types not addressed here + +class portable_binary_oarchive : + public boost::archive::basic_binary_oprimitive< + portable_binary_oarchive, + std::ostream::char_type, + std::ostream::traits_type + >, + public boost::archive::detail::common_oarchive< + portable_binary_oarchive + > +{ + typedef boost::archive::basic_binary_oprimitive< + portable_binary_oarchive, + std::ostream::char_type, + std::ostream::traits_type + > primitive_base_t; + typedef boost::archive::detail::common_oarchive< + portable_binary_oarchive + > archive_base_t; +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS +public: +#else + friend archive_base_t; + friend primitive_base_t; // since with override save below + friend class boost::archive::detail::interface_oarchive< + portable_binary_oarchive + >; + friend class boost::archive::save_access; +protected: +#endif + unsigned int m_flags; + void save_impl(const boost::intmax_t l, const char maxsize); + // add base class to the places considered when matching + // save function to a specific set of arguments. Note, this didn't + // work on my MSVC 7.0 system so we use the sure-fire method below + // using archive_base_t::save; + + // default fall through for any types not specified here + template + void save(const T & t){ + save_impl(t, sizeof(T)); + } + void save(const std::string & t){ + this->primitive_base_t::save(t); + } + #ifndef BOOST_NO_STD_WSTRING + void save(const std::wstring & t){ + this->primitive_base_t::save(t); + } + #endif + void save(const float & t){ + this->primitive_base_t::save(t); + // floats not supported + //BOOST_STATIC_ASSERT(false); + } + void save(const double & t){ + this->primitive_base_t::save(t); + // doubles not supported + //BOOST_STATIC_ASSERT(false); + } + void save(const char & t){ + this->primitive_base_t::save(t); + } + void save(const unsigned char & t){ + this->primitive_base_t::save(t); + } + + // default processing - kick back to base class. Note the + // extra stuff to get it passed borland compilers + typedef boost::archive::detail::common_oarchive + detail_common_oarchive; + template + void save_override(T & t){ + this->detail_common_oarchive::save_override(t); + } + // explicitly convert to char * to avoid compile ambiguities + void save_override(const boost::archive::class_name_type & t){ + const std::string s(t); + * this << s; + } + // binary files don't include the optional information + void save_override( + const boost::archive::class_id_optional_type & /* t */ + ){} + + void init(unsigned int flags); +public: + portable_binary_oarchive(std::ostream & os, unsigned flags = 0) : + primitive_base_t( + * os.rdbuf(), + 0 != (flags & boost::archive::no_codecvt) + ), + archive_base_t(flags), + m_flags(flags & (endian_big | endian_little)) + { + init(flags); + } + + portable_binary_oarchive( + std::basic_streambuf< + std::ostream::char_type, + std::ostream::traits_type + > & bsb, + unsigned int flags + ) : + primitive_base_t( + bsb, + 0 != (flags & boost::archive::no_codecvt) + ), + archive_base_t(flags), + m_flags(0) + { + init(flags); + } +}; + + +// required by export in boost version > 1.34 +#ifdef BOOST_SERIALIZATION_REGISTER_ARCHIVE + BOOST_SERIALIZATION_REGISTER_ARCHIVE(portable_binary_oarchive) +#endif + +// required by export in boost <= 1.34 +#define BOOST_ARCHIVE_CUSTOM_OARCHIVE_TYPES portable_binary_oarchive + +#if defined(_MSC_VER) +#pragma warning( pop ) +#endif + +#endif // PORTABLE_BINARY_OARCHIVE_HPP diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 0cfdd67b..81a68705 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2674,7 +2674,7 @@ void wallet2::load(const std::wstring& wallet_, const std::string& password) boost::iostreams::filtering_istream in; in.push(decrypt_filter); in.push(data_file); - need_to_resync = !tools::portable_unserialize_obj_from_stream(*this, in); + need_to_resync = !tools::portable_unserialize_obj_from_stream2(*this, in); } @@ -2750,7 +2750,7 @@ void wallet2::store(const std::wstring& path_to_save, const std::string& passwor out.push(decrypt_filter); out.push(data_file); - r = tools::portble_serialize_obj_to_stream(*this, out); + r = tools::portble_serialize_obj_to_stream2(*this, out); if (!r) { data_file.close(); From c8c2414fd34d670e79e74683567dd8733e542479 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 2 Jun 2021 23:52:18 +0300 Subject: [PATCH 08/83] added new portable storage --- src/currency_core/currency_config.h | 4 +++- src/wallet/wallet2.cpp | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 1b658a69..164170be 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -148,7 +148,9 @@ #define WALLET_FILE_SIGNATURE_OLD 0x1111012101101011LL // Bender's nightmare #define WALLET_FILE_SIGNATURE_V2 0x1111011201101011LL // another Bender's nightmare -#define WALLET_FILE_BINARY_HEADER_VERSION 1001 +#define WALLET_FILE_BINARY_HEADER_VERSION_INITAL 1000 +#define WALLET_FILE_BINARY_HEADER_VERSION_2 1001 +#define WALLET_FILE_BINARY_HEADER_VERSION_3 1002 #define WALLET_FILE_MAX_KEYS_SIZE 10000 // #define WALLET_BRAIN_DATE_OFFSET 1543622400 diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 81a68705..faa7f267 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2664,11 +2664,19 @@ void wallet2::load(const std::wstring& wallet_, const std::string& password) load_keys(keys_buff, password, wbh.m_signature, kf_data); bool need_to_resync = false; - if (wbh.m_ver == 1000) + if (wbh.m_ver == WALLET_FILE_BINARY_HEADER_VERSION_INITAL) { need_to_resync = !tools::portable_unserialize_obj_from_stream(*this, data_file); } - else + else if (wbh.m_ver == WALLET_FILE_BINARY_HEADER_VERSION_2) + { + tools::encrypt_chacha_in_filter decrypt_filter(password, kf_data.iv); + boost::iostreams::filtering_istream in; + in.push(decrypt_filter); + in.push(data_file); + need_to_resync = !tools::portable_unserialize_obj_from_stream(*this, in); + } + else if(wbh.m_ver == WALLET_FILE_BINARY_HEADER_VERSION_3) { tools::encrypt_chacha_in_filter decrypt_filter(password, kf_data.iv); boost::iostreams::filtering_istream in; @@ -2676,6 +2684,11 @@ void wallet2::load(const std::wstring& wallet_, const std::string& password) in.push(data_file); need_to_resync = !tools::portable_unserialize_obj_from_stream2(*this, in); } + else + { + WLT_LOG_L0("Unknown wallet body version(" << wbh.m_ver << "), resync initiated."); + need_to_resync = true; + } @@ -2729,7 +2742,7 @@ void wallet2::store(const std::wstring& path_to_save, const std::string& passwor wbh.m_signature = WALLET_FILE_SIGNATURE_V2; wbh.m_cb_keys = keys_buff.size(); //@#@ change it to proper - wbh.m_ver = WALLET_FILE_BINARY_HEADER_VERSION; + wbh.m_ver = WALLET_FILE_BINARY_HEADER_VERSION_3; std::string header_buff((const char*)&wbh, sizeof(wbh)); uint64_t ts = m_core_runtime_config.get_core_time(); From a3dcb32834cbc0df686382e3a1c7520e183ac583 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 3 Jun 2021 15:15:05 +0300 Subject: [PATCH 09/83] more logs on chainshortener --- src/wallet/wallet2.cpp | 7 +++++++ src/wallet/wallet_chain_shortener.cpp | 17 +++++++++++++++++ src/wallet/wallet_chain_shortener.h | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index faa7f267..bf93de6a 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2667,6 +2667,7 @@ void wallet2::load(const std::wstring& wallet_, const std::string& password) if (wbh.m_ver == WALLET_FILE_BINARY_HEADER_VERSION_INITAL) { need_to_resync = !tools::portable_unserialize_obj_from_stream(*this, data_file); + WLT_LOG_L0("Detected format: WALLET_FILE_BINARY_HEADER_VERSION_INITAL(need_to_resync=" << need_to_resync << ")"); } else if (wbh.m_ver == WALLET_FILE_BINARY_HEADER_VERSION_2) { @@ -2675,6 +2676,7 @@ void wallet2::load(const std::wstring& wallet_, const std::string& password) in.push(decrypt_filter); in.push(data_file); need_to_resync = !tools::portable_unserialize_obj_from_stream(*this, in); + WLT_LOG_L0("Detected format: WALLET_FILE_BINARY_HEADER_VERSION_2(need_to_resync=" << need_to_resync << ")"); } else if(wbh.m_ver == WALLET_FILE_BINARY_HEADER_VERSION_3) { @@ -2683,6 +2685,7 @@ void wallet2::load(const std::wstring& wallet_, const std::string& password) in.push(decrypt_filter); in.push(data_file); need_to_resync = !tools::portable_unserialize_obj_from_stream2(*this, in); + WLT_LOG_L0("Detected format: WALLET_FILE_BINARY_HEADER_VERSION_3(need_to_resync="<< need_to_resync <<")"); } else { @@ -2703,6 +2706,8 @@ void wallet2::load(const std::wstring& wallet_, const std::string& password) << ", file_size=" << m_current_wallet_file_size << ", blockchain_size: " << m_chain.get_blockchain_current_size() ); + WLT_LOG_L0("[LOADING]Blockchain shortener state: " << ENDL << m_chain.get_internal_state_text()); + WLT_LOG_L0("(after loading: pending_key_images: " << m_pending_key_images.size() << ", pki file elements: " << m_pending_key_images_file_container.size() << ", tx_keys: " << m_tx_keys.size() << ")"); @@ -2776,6 +2781,8 @@ void wallet2::store(const std::wstring& path_to_save, const std::string& passwor boost::uintmax_t tmp_file_size = boost::filesystem::file_size(tmp_file_path); WLT_LOG_L0("Stored successfully to temporary file " << tmp_file_path.string() << ", file size=" << tmp_file_size); + WLT_LOG_L0("[LOADING]Blockchain shortener state: " << ENDL << m_chain.get_internal_state_text()); + // for the sake of safety perform a double-renaming: wallet file -> old tmp, new tmp -> wallet file, remove old tmp boost::filesystem::path tmp_old_file_path = boost::filesystem::path(path_to_save); diff --git a/src/wallet/wallet_chain_shortener.cpp b/src/wallet/wallet_chain_shortener.cpp index 9d30cb5f..8633c40d 100644 --- a/src/wallet/wallet_chain_shortener.cpp +++ b/src/wallet/wallet_chain_shortener.cpp @@ -274,6 +274,23 @@ void wallet_chain_shortener::check_if_block_matched(uint64_t i, const crypto::ha } } //---------------------------------------------------------------------------------------------------- +std::string wallet_chain_shortener::get_internal_state_text() const +{ + std::stringstream ss; +#define PRINT_CHAIN_SHORTENER_STATE_INFO(cont_name) \ + if (cont_name.size()) \ + { \ + ss << #cont_name << ".size(): [" << cont_name.begin().first << ": " << cont_name.begin().second << "]" << ENDL; \ + } + + PRINT_CHAIN_SHORTENER_STATE_INFO(m_last_20_blocks); + PRINT_CHAIN_SHORTENER_STATE_INFO(m_last_144_blocks_every_10); + PRINT_CHAIN_SHORTENER_STATE_INFO(m_last_144_blocks_every_100); + PRINT_CHAIN_SHORTENER_STATE_INFO(m_last_144_blocks_every_1000); + ss << "m_local_bc_size = " << m_local_bc_size << ENDL; + return ss.str(); +} +//---------------------------------------------------------------------------------------------------- void clean_map_from_items_above(std::map& container, uint64_t height) { while (container.size() && (--container.end())->first >= height) diff --git a/src/wallet/wallet_chain_shortener.h b/src/wallet/wallet_chain_shortener.h index 2ea61366..500c2494 100644 --- a/src/wallet/wallet_chain_shortener.h +++ b/src/wallet/wallet_chain_shortener.h @@ -46,7 +46,7 @@ public: } //debug functions - + std::string get_internal_state_text() const; private: std::atomic m_local_bc_size; //temporary workaround crypto::hash m_genesis; From e302c34f7e55c9b9a6ef9dd2321673a9843c1273 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 3 Jun 2021 15:42:57 +0300 Subject: [PATCH 10/83] fixed access to secon and first --- src/wallet/wallet_chain_shortener.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet_chain_shortener.cpp b/src/wallet/wallet_chain_shortener.cpp index 8633c40d..e353c1a6 100644 --- a/src/wallet/wallet_chain_shortener.cpp +++ b/src/wallet/wallet_chain_shortener.cpp @@ -280,7 +280,7 @@ std::string wallet_chain_shortener::get_internal_state_text() const #define PRINT_CHAIN_SHORTENER_STATE_INFO(cont_name) \ if (cont_name.size()) \ { \ - ss << #cont_name << ".size(): [" << cont_name.begin().first << ": " << cont_name.begin().second << "]" << ENDL; \ + ss << #cont_name << ".size(): [" << cont_name.begin()->first << ": " << cont_name.begin()->second << "]" << ENDL; \ } PRINT_CHAIN_SHORTENER_STATE_INFO(m_last_20_blocks); From 51bb91c66c70affaa421bd4197ce17fd0dc8d083 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 3 Jun 2021 18:46:44 +0300 Subject: [PATCH 11/83] rolled back eperimental code --- src/common/boost_serialization_helper.h | 24 --- src/common/portable_binary_archive.hpp | 46 ------ src/common/portable_binary_iarchive.cpp | 131 --------------- src/common/portable_binary_iarchive.hpp | 204 ------------------------ src/common/portable_binary_oarchive.cpp | 98 ------------ src/common/portable_binary_oarchive.hpp | 191 ---------------------- src/currency_core/currency_config.h | 8 +- src/wallet/wallet2.cpp | 13 +- src/wallet/wallet2.h | 2 +- 9 files changed, 8 insertions(+), 709 deletions(-) delete mode 100644 src/common/portable_binary_archive.hpp delete mode 100644 src/common/portable_binary_iarchive.cpp delete mode 100644 src/common/portable_binary_iarchive.hpp delete mode 100644 src/common/portable_binary_oarchive.cpp delete mode 100644 src/common/portable_binary_oarchive.hpp diff --git a/src/common/boost_serialization_helper.h b/src/common/boost_serialization_helper.h index 81708f39..873a7d76 100644 --- a/src/common/boost_serialization_helper.h +++ b/src/common/boost_serialization_helper.h @@ -104,28 +104,4 @@ namespace tools return !stream.fail(); CATCH_ENTRY_L0("portable_unserialize_obj_from_stream", false); } - - template - bool portable_unserialize_obj_from_stream2(t_object& obj, t_stream& stream) - { - TRY_ENTRY(); - - portable_binary_iarchive a(stream); - - a >> obj; - return !stream.fail(); - CATCH_ENTRY_L0("portable_unserialize_obj_from_stream", false); - } - - template - bool portble_serialize_obj_to_stream2(t_object& obj, t_stream& stream) - { - TRY_ENTRY(); - - portable_binary_oarchive a(stream); - a << obj; - - return !stream.fail(); - CATCH_ENTRY_L0("portble_serialize_obj_to_stream", false); - } } diff --git a/src/common/portable_binary_archive.hpp b/src/common/portable_binary_archive.hpp deleted file mode 100644 index eecd9508..00000000 --- a/src/common/portable_binary_archive.hpp +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef PORTABLE_BINARY_ARCHIVE_HPP -#define PORTABLE_BINARY_ARCHIVE_HPP - -// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . -// Use, modification and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// MS compatible compilers support #pragma once -#if defined(_MSC_VER) -# pragma once -#endif - -#include -#include -#include - -#include -#if CHAR_BIT != 8 -#error This code assumes an eight-bit byte. -#endif - -#include -#include - -enum portable_binary_archive_flags { - endian_big = 0x4000, - endian_little = 0x8000 -}; - -//#if ( endian_big <= boost::archive::flags_last ) -//#error archive flags conflict -//#endif - -inline void -reverse_bytes(char size, char *address){ - char * first = address; - char * last = first + size - 1; - for(;first < last;++first, --last){ - char x = *last; - *last = *first; - *first = x; - } -} - -#endif // PORTABLE_BINARY_ARCHIVE_HPP diff --git a/src/common/portable_binary_iarchive.cpp b/src/common/portable_binary_iarchive.cpp deleted file mode 100644 index a0b61d52..00000000 --- a/src/common/portable_binary_iarchive.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 -// portable_binary_iarchive.cpp - -// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . -// Use, modification and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org for updates, documentation, and revision history. - -#include -#include - -#include -#include -#include - -#include "portable_binary_iarchive.hpp" - -void -portable_binary_iarchive::load_impl(boost::intmax_t & l, char maxsize){ - char size; - l = 0; - this->primitive_base_t::load(size); - - if(0 == size){ - return; - } - - bool negative = (size < 0); - if(negative) - size = -size; - - if(size > maxsize) - boost::serialization::throw_exception( - portable_binary_iarchive_exception() - ); - - char * cptr = reinterpret_cast(& l); - #ifdef BOOST_BIG_ENDIAN - cptr += (sizeof(boost::intmax_t) - size); - #endif - this->primitive_base_t::load_binary(cptr, size); - - #ifdef BOOST_BIG_ENDIAN - if(m_flags & endian_little) - #else - if(m_flags & endian_big) - #endif - reverse_bytes(size, cptr); - - if(negative) - l = -l; -} - -void -portable_binary_iarchive::load_override( - boost::archive::class_name_type & t -){ - std::string cn; - cn.reserve(BOOST_SERIALIZATION_MAX_KEY_SIZE); - load_override(cn); - if(cn.size() > (BOOST_SERIALIZATION_MAX_KEY_SIZE - 1)) - boost::serialization::throw_exception( - boost::archive::archive_exception( - boost::archive::archive_exception::invalid_class_name) - ); - std::memcpy(t, cn.data(), cn.size()); - // borland tweak - t.t[cn.size()] = '\0'; -} - -void -portable_binary_iarchive::init(unsigned int flags){ - if(0 == (flags & boost::archive::no_header)){ - // read signature in an archive version independent manner - std::string file_signature; - * this >> file_signature; - if(file_signature != boost::archive::BOOST_ARCHIVE_SIGNATURE()) - boost::serialization::throw_exception( - boost::archive::archive_exception( - boost::archive::archive_exception::invalid_signature - ) - ); - // make sure the version of the reading archive library can - // support the format of the archive being read - boost::archive::library_version_type input_library_version; - * this >> input_library_version; - - // extra little .t is to get around borland quirk - if(boost::archive::BOOST_ARCHIVE_VERSION() < input_library_version) - boost::serialization::throw_exception( - boost::archive::archive_exception( - boost::archive::archive_exception::unsupported_version - ) - ); - - #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205)) - this->set_library_version(input_library_version); - //#else - //#if ! BOOST_WORKAROUND(BOOST_MSVC, <= 1200) - //detail:: - //#endif - boost::archive::detail::basic_iarchive::set_library_version( - input_library_version - ); - #endif - } - unsigned char x; - load(x); - m_flags = x << CHAR_BIT; -} - -#include -#include - -namespace boost { -namespace archive { - -namespace detail { - template class archive_serializer_map; -} - -template class basic_binary_iprimitive< - portable_binary_iarchive, - std::istream::char_type, - std::istream::traits_type -> ; - -} // namespace archive -} // namespace boost diff --git a/src/common/portable_binary_iarchive.hpp b/src/common/portable_binary_iarchive.hpp deleted file mode 100644 index 3730660c..00000000 --- a/src/common/portable_binary_iarchive.hpp +++ /dev/null @@ -1,204 +0,0 @@ -#ifndef PORTABLE_BINARY_IARCHIVE_HPP -#define PORTABLE_BINARY_IARCHIVE_HPP - -// MS compatible compilers support #pragma once -#if defined(_MSC_VER) -# pragma once -#endif - -#if defined(_MSC_VER) -#pragma warning( push ) -#pragma warning( disable : 4244 ) -#endif - -/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 -// portable_binary_iarchive.hpp - -// (C) Copyright 2002-7 Robert Ramey - http://www.rrsd.com . -// Use, modification and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org for updates, documentation, and revision history. - -#include -#include -#include -#include -#include -#include -#include - -#include "portable_binary_archive.hpp" - -/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 -// exception to be thrown if integer read from archive doesn't fit -// variable being loaded -class portable_binary_iarchive_exception : - public boost::archive::archive_exception -{ -public: - enum exception_code { - incompatible_integer_size - } m_exception_code ; - portable_binary_iarchive_exception(exception_code c = incompatible_integer_size ) : - boost::archive::archive_exception(boost::archive::archive_exception::other_exception), - m_exception_code(c) - {} - virtual const char *what( ) const throw( ) - { - const char *msg = "programmer error"; - switch(m_exception_code){ - case incompatible_integer_size: - msg = "integer cannot be represented"; - break; - default: - msg = boost::archive::archive_exception::what(); - assert(false); - break; - } - return msg; - } -}; - -/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 -// "Portable" input binary archive. It addresses integer size and endienness so -// that binary archives can be passed across systems. Note:floating point types -// not addressed here -class portable_binary_iarchive : - public boost::archive::basic_binary_iprimitive< - portable_binary_iarchive, - std::istream::char_type, - std::istream::traits_type - >, - public boost::archive::detail::common_iarchive< - portable_binary_iarchive - > - { - typedef boost::archive::basic_binary_iprimitive< - portable_binary_iarchive, - std::istream::char_type, - std::istream::traits_type - > primitive_base_t; - typedef boost::archive::detail::common_iarchive< - portable_binary_iarchive - > archive_base_t; -#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS -public: -#else - friend archive_base_t; - friend primitive_base_t; // since with override load below - friend class boost::archive::detail::interface_iarchive< - portable_binary_iarchive - >; - friend class boost::archive::load_access; -protected: -#endif - unsigned int m_flags; - void load_impl(boost::intmax_t & l, char maxsize); - - // default fall through for any types not specified here - template - void load(T & t){ - boost::intmax_t l; - load_impl(l, sizeof(T)); - // use cast to avoid compile time warning - //t = static_cast< T >(l); - t = T(l); - } - void load(boost::serialization::item_version_type & t){ - boost::intmax_t l; - load_impl(l, sizeof(boost::serialization::item_version_type)); - // use cast to avoid compile time warning - t = boost::serialization::item_version_type(l); - } - void load(boost::archive::version_type & t){ - boost::intmax_t l; - load_impl(l, sizeof(boost::archive::version_type)); - // use cast to avoid compile time warning - t = boost::archive::version_type(l); - } - void load(boost::archive::class_id_type & t){ - boost::intmax_t l; - load_impl(l, sizeof(boost::archive::class_id_type)); - // use cast to avoid compile time warning - t = boost::archive::class_id_type(static_cast(l)); - } - void load(std::string & t){ - this->primitive_base_t::load(t); - } - #ifndef BOOST_NO_STD_WSTRING - void load(std::wstring & t){ - this->primitive_base_t::load(t); - } - #endif - void load(float & t){ - this->primitive_base_t::load(t); - // floats not supported - //BOOST_STATIC_ASSERT(false); - } - void load(double & t){ - this->primitive_base_t::load(t); - // doubles not supported - //BOOST_STATIC_ASSERT(false); - } - void load(char & t){ - this->primitive_base_t::load(t); - } - void load(unsigned char & t){ - this->primitive_base_t::load(t); - } - typedef boost::archive::detail::common_iarchive - detail_common_iarchive; - template - void load_override(T & t){ - this->detail_common_iarchive::load_override(t); - } - void load_override(boost::archive::class_name_type & t); - // binary files don't include the optional information - void load_override(boost::archive::class_id_optional_type &){} - - void init(unsigned int flags); -public: - portable_binary_iarchive(std::istream & is, unsigned flags = 0) : - primitive_base_t( - * is.rdbuf(), - 0 != (flags & boost::archive::no_codecvt) - ), - archive_base_t(flags), - m_flags(0) - { - init(flags); - } - - portable_binary_iarchive( - std::basic_streambuf< - std::istream::char_type, - std::istream::traits_type - > & bsb, - unsigned int flags - ) : - primitive_base_t( - bsb, - 0 != (flags & boost::archive::no_codecvt) - ), - archive_base_t(flags), - m_flags(0) - { - init(flags); - } -}; - -// required by export in boost version > 1.34 -#ifdef BOOST_SERIALIZATION_REGISTER_ARCHIVE - BOOST_SERIALIZATION_REGISTER_ARCHIVE(portable_binary_iarchive) -#endif - -// required by export in boost <= 1.34 -#define BOOST_ARCHIVE_CUSTOM_IARCHIVE_TYPES portable_binary_iarchive - -#if defined(_MSC_VER) -#pragma warning( pop ) -#endif - -#endif // PORTABLE_BINARY_IARCHIVE_HPP diff --git a/src/common/portable_binary_oarchive.cpp b/src/common/portable_binary_oarchive.cpp deleted file mode 100644 index 6f94eeb5..00000000 --- a/src/common/portable_binary_oarchive.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 -// portable_binary_oarchive.cpp - -// (C) Copyright 2002-7 Robert Ramey - http://www.rrsd.com . -// Use, modification and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org for updates, documentation, and revision history. - -#include -#include -#include "portable_binary_oarchive.hpp" - -void -portable_binary_oarchive::save_impl( - const boost::intmax_t l, - const char maxsize -){ - char size = 0; - - if(l == 0){ - this->primitive_base_t::save(size); - return; - } - - boost::intmax_t ll; - bool negative = (l < 0); - if(negative) - ll = -l; - else - ll = l; - - do{ - ll >>= CHAR_BIT; - ++size; - }while(ll != 0); - - this->primitive_base_t::save( - static_cast(negative ? -size : size) - ); - - if(negative) - ll = -l; - else - ll = l; - char * cptr = reinterpret_cast(& ll); - #ifdef BOOST_BIG_ENDIAN - cptr += (sizeof(boost::intmax_t) - size); - if(m_flags & endian_little) - reverse_bytes(size, cptr); - #else - if(m_flags & endian_big) - reverse_bytes(size, cptr); - #endif - this->primitive_base_t::save_binary(cptr, size); -} - -void -portable_binary_oarchive::init(unsigned int flags) { - if(m_flags == (endian_big | endian_little)){ - boost::serialization::throw_exception( - portable_binary_oarchive_exception() - ); - } - if(0 == (flags & boost::archive::no_header)){ - // write signature in an archive version independent manner - const std::string file_signature( - boost::archive::BOOST_ARCHIVE_SIGNATURE() - ); - * this << file_signature; - // write library version - const boost::archive::library_version_type v( - boost::archive::BOOST_ARCHIVE_VERSION() - ); - * this << v; - } - save(static_cast(m_flags >> CHAR_BIT)); -} - -#include -#include - -namespace boost { -namespace archive { - -namespace detail { - template class archive_serializer_map; -} - -template class basic_binary_oprimitive< - portable_binary_oarchive, - std::ostream::char_type, - std::ostream::traits_type -> ; - -} // namespace archive -} // namespace boost diff --git a/src/common/portable_binary_oarchive.hpp b/src/common/portable_binary_oarchive.hpp deleted file mode 100644 index 317aa1d7..00000000 --- a/src/common/portable_binary_oarchive.hpp +++ /dev/null @@ -1,191 +0,0 @@ -#ifndef PORTABLE_BINARY_OARCHIVE_HPP -#define PORTABLE_BINARY_OARCHIVE_HPP - -// MS compatible compilers support #pragma once -#if defined(_MSC_VER) -# pragma once -#endif - -#if defined(_MSC_VER) -#pragma warning( push ) -#pragma warning( disable : 4244 ) -#endif - -/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 -// portable_binary_oarchive.hpp - -// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . -// Use, modification and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org for updates, documentation, and revision history. - -#include -#include -#include -#include -#include -#include - -#include "portable_binary_archive.hpp" - -/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 -// exception to be thrown if integer read from archive doesn't fit -// variable being loaded -class portable_binary_oarchive_exception : - public boost::archive::archive_exception -{ -public: - typedef enum { - invalid_flags - } exception_code; - portable_binary_oarchive_exception(exception_code c = invalid_flags ) - {} - virtual const char *what( ) const throw( ) - { - const char *msg = "programmer error"; - switch(code){ - case invalid_flags: - msg = "cannot be both big and little endian"; - default: - boost::archive::archive_exception::what(); - } - return msg; - } -}; - -/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 -// "Portable" output binary archive. This is a variation of the native binary -// archive. it addresses integer size and endienness so that binary archives can -// be passed across systems. Note:floating point types not addressed here - -class portable_binary_oarchive : - public boost::archive::basic_binary_oprimitive< - portable_binary_oarchive, - std::ostream::char_type, - std::ostream::traits_type - >, - public boost::archive::detail::common_oarchive< - portable_binary_oarchive - > -{ - typedef boost::archive::basic_binary_oprimitive< - portable_binary_oarchive, - std::ostream::char_type, - std::ostream::traits_type - > primitive_base_t; - typedef boost::archive::detail::common_oarchive< - portable_binary_oarchive - > archive_base_t; -#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS -public: -#else - friend archive_base_t; - friend primitive_base_t; // since with override save below - friend class boost::archive::detail::interface_oarchive< - portable_binary_oarchive - >; - friend class boost::archive::save_access; -protected: -#endif - unsigned int m_flags; - void save_impl(const boost::intmax_t l, const char maxsize); - // add base class to the places considered when matching - // save function to a specific set of arguments. Note, this didn't - // work on my MSVC 7.0 system so we use the sure-fire method below - // using archive_base_t::save; - - // default fall through for any types not specified here - template - void save(const T & t){ - save_impl(t, sizeof(T)); - } - void save(const std::string & t){ - this->primitive_base_t::save(t); - } - #ifndef BOOST_NO_STD_WSTRING - void save(const std::wstring & t){ - this->primitive_base_t::save(t); - } - #endif - void save(const float & t){ - this->primitive_base_t::save(t); - // floats not supported - //BOOST_STATIC_ASSERT(false); - } - void save(const double & t){ - this->primitive_base_t::save(t); - // doubles not supported - //BOOST_STATIC_ASSERT(false); - } - void save(const char & t){ - this->primitive_base_t::save(t); - } - void save(const unsigned char & t){ - this->primitive_base_t::save(t); - } - - // default processing - kick back to base class. Note the - // extra stuff to get it passed borland compilers - typedef boost::archive::detail::common_oarchive - detail_common_oarchive; - template - void save_override(T & t){ - this->detail_common_oarchive::save_override(t); - } - // explicitly convert to char * to avoid compile ambiguities - void save_override(const boost::archive::class_name_type & t){ - const std::string s(t); - * this << s; - } - // binary files don't include the optional information - void save_override( - const boost::archive::class_id_optional_type & /* t */ - ){} - - void init(unsigned int flags); -public: - portable_binary_oarchive(std::ostream & os, unsigned flags = 0) : - primitive_base_t( - * os.rdbuf(), - 0 != (flags & boost::archive::no_codecvt) - ), - archive_base_t(flags), - m_flags(flags & (endian_big | endian_little)) - { - init(flags); - } - - portable_binary_oarchive( - std::basic_streambuf< - std::ostream::char_type, - std::ostream::traits_type - > & bsb, - unsigned int flags - ) : - primitive_base_t( - bsb, - 0 != (flags & boost::archive::no_codecvt) - ), - archive_base_t(flags), - m_flags(0) - { - init(flags); - } -}; - - -// required by export in boost version > 1.34 -#ifdef BOOST_SERIALIZATION_REGISTER_ARCHIVE - BOOST_SERIALIZATION_REGISTER_ARCHIVE(portable_binary_oarchive) -#endif - -// required by export in boost <= 1.34 -#define BOOST_ARCHIVE_CUSTOM_OARCHIVE_TYPES portable_binary_oarchive - -#if defined(_MSC_VER) -#pragma warning( pop ) -#endif - -#endif // PORTABLE_BINARY_OARCHIVE_HPP diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 164170be..5378cff0 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -150,7 +150,7 @@ #define WALLET_FILE_SIGNATURE_V2 0x1111011201101011LL // another Bender's nightmare #define WALLET_FILE_BINARY_HEADER_VERSION_INITAL 1000 #define WALLET_FILE_BINARY_HEADER_VERSION_2 1001 -#define WALLET_FILE_BINARY_HEADER_VERSION_3 1002 +//#define WALLET_FILE_BINARY_HEADER_VERSION_3 1002 #define WALLET_FILE_MAX_KEYS_SIZE 10000 // #define WALLET_BRAIN_DATE_OFFSET 1543622400 @@ -225,9 +225,11 @@ #define BC_OFFERS_CURRENT_OFFERS_SERVICE_ARCHIVE_VER CURRENCY_FORMATION_VERSION + BLOCKCHAIN_STORAGE_MAJOR_COMPATIBILITY_VERSION + 9 #define BC_OFFERS_CURRENCY_MARKET_FILENAME "market.bin" - +#ifndef TESTNET +#define WALLET_FILE_SERIALIZATION_VERSION 154 +#else #define WALLET_FILE_SERIALIZATION_VERSION (CURRENCY_FORMATION_VERSION+69) - +#endif #define CURRENT_MEMPOOL_ARCHIVE_VER (CURRENCY_FORMATION_VERSION+31) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index bf93de6a..556769cc 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2678,15 +2678,6 @@ void wallet2::load(const std::wstring& wallet_, const std::string& password) need_to_resync = !tools::portable_unserialize_obj_from_stream(*this, in); WLT_LOG_L0("Detected format: WALLET_FILE_BINARY_HEADER_VERSION_2(need_to_resync=" << need_to_resync << ")"); } - else if(wbh.m_ver == WALLET_FILE_BINARY_HEADER_VERSION_3) - { - tools::encrypt_chacha_in_filter decrypt_filter(password, kf_data.iv); - boost::iostreams::filtering_istream in; - in.push(decrypt_filter); - in.push(data_file); - need_to_resync = !tools::portable_unserialize_obj_from_stream2(*this, in); - WLT_LOG_L0("Detected format: WALLET_FILE_BINARY_HEADER_VERSION_3(need_to_resync="<< need_to_resync <<")"); - } else { WLT_LOG_L0("Unknown wallet body version(" << wbh.m_ver << "), resync initiated."); @@ -2747,7 +2738,7 @@ void wallet2::store(const std::wstring& path_to_save, const std::string& passwor wbh.m_signature = WALLET_FILE_SIGNATURE_V2; wbh.m_cb_keys = keys_buff.size(); //@#@ change it to proper - wbh.m_ver = WALLET_FILE_BINARY_HEADER_VERSION_3; + wbh.m_ver = WALLET_FILE_BINARY_HEADER_VERSION_2; std::string header_buff((const char*)&wbh, sizeof(wbh)); uint64_t ts = m_core_runtime_config.get_core_time(); @@ -2768,7 +2759,7 @@ void wallet2::store(const std::wstring& path_to_save, const std::string& passwor out.push(decrypt_filter); out.push(data_file); - r = tools::portble_serialize_obj_to_stream2(*this, out); + r = tools::portble_serialize_obj_to_stream(*this, out); if (!r) { data_file.close(); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 1a6ce4f0..23d34df2 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -696,7 +696,7 @@ namespace tools uint64_t get_top_block_height() const { return m_chain.get_top_block_height(); } template - inline void serialize(t_archive &a, const unsigned int ver) + inline void serialize(t_archive &a, const unsigned int ver_) { if (t_archive::is_saving::value) { From b48c7b16c6eb3ea3e6d6c475ddd4dd2ca3781245 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 3 Jun 2021 18:50:29 +0300 Subject: [PATCH 12/83] Removed unused includes --- src/common/boost_serialization_helper.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/common/boost_serialization_helper.h b/src/common/boost_serialization_helper.h index 873a7d76..5ad68a05 100644 --- a/src/common/boost_serialization_helper.h +++ b/src/common/boost_serialization_helper.h @@ -9,10 +9,7 @@ #include #include #include -#include "common/portable_binary_iarchive.hpp" -#include "common/portable_binary_oarchive.hpp" -//#include From 9a94584ca4e3abcc4eaa20529e321af4d73e29e8 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 3 Jun 2021 19:00:34 +0300 Subject: [PATCH 13/83] Forgoten line --- src/wallet/wallet2.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 23d34df2..1a6ce4f0 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -696,7 +696,7 @@ namespace tools uint64_t get_top_block_height() const { return m_chain.get_top_block_height(); } template - inline void serialize(t_archive &a, const unsigned int ver_) + inline void serialize(t_archive &a, const unsigned int ver) { if (t_archive::is_saving::value) { From ff1914aab5b91668fdf2aa178961647052149999 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 11 Jun 2021 21:57:44 +0300 Subject: [PATCH 14/83] rolled back wallet version --- src/currency_core/currency_config.h | 2 +- tests/functional_tests/plain_wallet_tests.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 5378cff0..bda8f652 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -226,7 +226,7 @@ #define BC_OFFERS_CURRENCY_MARKET_FILENAME "market.bin" #ifndef TESTNET -#define WALLET_FILE_SERIALIZATION_VERSION 154 +#define WALLET_FILE_SERIALIZATION_VERSION 153 #else #define WALLET_FILE_SERIALIZATION_VERSION (CURRENCY_FORMATION_VERSION+69) #endif diff --git a/tests/functional_tests/plain_wallet_tests.cpp b/tests/functional_tests/plain_wallet_tests.cpp index e92084fb..f1f9f36b 100644 --- a/tests/functional_tests/plain_wallet_tests.cpp +++ b/tests/functional_tests/plain_wallet_tests.cpp @@ -47,6 +47,7 @@ void run_plain_wallet_api_test() // plain_wallet::close_wallet(0); res = plain_wallet::open("test_wall2.zan", "111"); + res = plain_wallet::close_wallet(0); res = plain_wallet::invoke(0, "{\"method\":\"transfer\",\"params\":{\"destinations\":[{\"amount\":10000000000,\"address\":\"aZxat4HAWriVQ3enkGcVsrZRdMseAJswG3CSEwTqZS246VsFQ53w26eZstYsu1jWE74Atz9ajLxFnBsVTafncWNH5SMv4zHFaTS\"}],\"fee\":10000000000,\"mixin\":1011111,\"payment_id\":\"\",\"push_payer\":true,\"hide_receiver\":false}}"); From 0925c02a770de21295c221b49169469c44eb3359 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 24 Jun 2021 00:57:38 +0200 Subject: [PATCH 15/83] implemented basic suppoer of wrapping in wallet(service commands) + inital support in simplewallet --- src/currency_core/currency_basic.h | 10 ++- src/currency_core/currency_format_utils.cpp | 90 ++++++++++++++++++--- src/currency_core/currency_format_utils.h | 1 + src/simplewallet/simplewallet.cpp | 32 +++++++- src/wallet/wrap_service.h | 12 +++ 5 files changed, 129 insertions(+), 16 deletions(-) create mode 100644 src/wallet/wrap_service.h diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index 274a2f25..29aa7483 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -386,8 +386,14 @@ namespace currency }; // applicable flags for tx_service_attachment::flags, can be combined using bitwise OR -#define TX_SERVICE_ATTACHMENT_ENCRYPT_BODY static_cast(1 << 0) -#define TX_SERVICE_ATTACHMENT_DEFLATE_BODY static_cast(1 << 1) +#define TX_SERVICE_ATTACHMENT_ENCRYPT_BODY static_cast(1 << 0) +#define TX_SERVICE_ATTACHMENT_DEFLATE_BODY static_cast(1 << 1) + +// with this flag enabled body encrypted/decrypted with the key created as a derivation from onetime key and "spend keys" of receiver +#define TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE static_cast(1 << 2) +// add proof of content, without revealing secrete +#define TX_SERVICE_ATTACHMENT_ENCRYPT_ADD_PROOF static_cast(1 << 3) + //, diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 7c014f2a..0d877864 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -759,8 +759,12 @@ namespace currency struct encrypt_attach_visitor : public boost::static_visitor { bool& m_was_crypted_entries; + const keypair& m_onetime_keypair; + const account_public_address& m_destination_addr; const crypto::key_derivation& m_key; - encrypt_attach_visitor(bool& was_crypted_entries, const crypto::key_derivation& key) :m_was_crypted_entries(was_crypted_entries), m_key(key) + + encrypt_attach_visitor(bool& was_crypted_entries, const crypto::key_derivation& key, const keypair& onetime_keypair = keypair(), const account_public_address& destination_addr = account_public_address()) : + m_was_crypted_entries(was_crypted_entries), m_key(key), m_onetime_keypair(onetime_keypair), m_destination_addr(m_destination_addr) {} void operator()(tx_comment& comment) { @@ -789,6 +793,7 @@ namespace currency } void operator()(tx_service_attachment& sa) { + const std::string orignal_body = sa.body; if (sa.flags&TX_SERVICE_ATTACHMENT_DEFLATE_BODY) { zlib_helper::pack(sa.body); @@ -796,7 +801,27 @@ namespace currency if (sa.flags&TX_SERVICE_ATTACHMENT_ENCRYPT_BODY) { - crypto::chacha_crypt(sa.body, m_key); + crypto::key_derivation derivation_local = m_key; + if (sa.flags&TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE) + { + CHECK_AND_ASSERT_THROW_MES(m_destination_addr.spend_public_key != currency::null_pkey && m_onetime_keypair.sec != currency::null_skey, "tx_service_attachment with TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE: keys uninitialized"); + //encrypt with "spend keys" only, to prevent auditable watchers decrypt it + bool r = crypto::generate_key_derivation(m_destination_addr.spend_public_key, m_onetime_keypair.sec, derivation_local); + crypto::chacha_crypt(sa.body, derivation_local); + } + else + { + crypto::chacha_crypt(sa.body, derivation_local); + } + if (sa.flags&TX_SERVICE_ATTACHMENT_ENCRYPT_ADD_PROOF) + { + //take hash from derivation and use it as a salt + crypto::hash derivation_hash = crypto::cn_fast_hash(&derivation_local, sizeof(derivation_local)); + std::string salted_body = orignal_body; + string_tools::apped_pod_to_strbuff(salted_body, derivation_hash); + crypto::hash proof_hash = crypto::cn_fast_hash(salted_body.data(), salted_body.size()); + sa.security.push_back(*(crypto::public_key*)&proof_hash); + } m_was_crypted_entries = true; } } @@ -808,12 +833,18 @@ namespace currency struct decrypt_attach_visitor : public boost::static_visitor { + const account_keys& m_acc_keys; + const crypto::public_key& m_tx_onetime_pubkey; const crypto::key_derivation& rkey; std::vector& rdecrypted_att; decrypt_attach_visitor(const crypto::key_derivation& key, - std::vector& decrypted_att) : + std::vector& decrypted_att, + const account_keys& acc_keys = account_keys(), + const crypto::public_key& tx_onetime_pubkey = crypto::public_key()) : rkey(key), - rdecrypted_att(decrypted_att) + rdecrypted_att(decrypted_att), + m_acc_keys(acc_keys), + m_tx_onetime_pubkey(tx_onetime_pubkey) {} void operator()(const tx_comment& comment) { @@ -825,15 +856,44 @@ namespace currency void operator()(const tx_service_attachment& sa) { tx_service_attachment local_sa = sa; + crypto::key_derivation derivation_local = rkey; if (sa.flags&TX_SERVICE_ATTACHMENT_ENCRYPT_BODY) { - crypto::chacha_crypt(local_sa.body, rkey); + if (sa.flags&TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE) + { + if (m_acc_keys.spend_secret_key == null_skey) + { + //this watch only wallet, decrypting supposed to be impossible + return; + } + CHECK_AND_ASSERT_THROW_MES(m_acc_keys.spend_secret_key != currency::null_skey, "tx_service_attachment with TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE: keys uninitialized"); + bool r = crypto::generate_key_derivation(m_tx_onetime_pubkey, m_acc_keys.spend_secret_key, derivation_local); + CHECK_AND_ASSERT_THROW_MES(r, "Failed to generate_key_derivation at TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE"); + crypto::chacha_crypt(sa.body, derivation_local); + + } + else + { + crypto::chacha_crypt(local_sa.body, derivation_local); + } } if (sa.flags&TX_SERVICE_ATTACHMENT_DEFLATE_BODY) { zlib_helper::unpack(local_sa.body); } + + if (sa.flags&TX_SERVICE_ATTACHMENT_ENCRYPT_BODY && sa.flags&TX_SERVICE_ATTACHMENT_ENCRYPT_ADD_PROOF) + { + CHECK_AND_ASSERT_MES(sa.security.size() == 1, void(), "Unexpected key in tx_service_attachment with TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE"); + //take hash from derivation and use it as a salt + crypto::hash derivation_hash = crypto::cn_fast_hash(&derivation_local, sizeof(derivation_local)); + std::string salted_body = local_sa.body; + string_tools::apped_pod_to_strbuff(salted_body, derivation_hash); + crypto::hash proof_hash = crypto::cn_fast_hash(salted_body.data(), salted_body.size()); + CHECK_AND_ASSERT_MES(*(crypto::public_key*)&proof_hash == sa.security.front(), void(), "Proof hash missmatch on decrypting with TX_SERVICE_ATTACHMENT_ENCRYPT_ADD_PROOF"); + } + rdecrypted_att.push_back(local_sa); } @@ -870,9 +930,10 @@ namespace currency //--------------------------------------------------------------- template - bool decrypt_payload_items(const crypto::key_derivation& derivation, const items_container_t& items_to_decrypt, std::vector& decrypted_att) + bool decrypt_payload_items(const crypto::key_derivation& derivation, const items_container_t& items_to_decrypt, std::vector& decrypted_att, const account_keys& acc_keys = account_keys(), + const crypto::public_key& tx_onetime_pubkey = crypto::public_key()) { - decrypt_attach_visitor v(derivation, decrypted_att); + decrypt_attach_visitor v(derivation, decrypted_att, acc_keys, tx_onetime_pubkey); for (auto& a : items_to_decrypt) boost::apply_visitor(v, a); @@ -955,8 +1016,8 @@ namespace currency return true; } - decrypt_payload_items(derivation, tx.extra, decrypted_items); - decrypt_payload_items(derivation, tx.attachment, decrypted_items); + decrypt_payload_items(derivation, tx.extra, decrypted_items, acc_keys, get_tx_pub_key_from_extra(tx)); + decrypt_payload_items(derivation, tx.attachment, decrypted_items, acc_keys, get_tx_pub_key_from_extra(tx)); return true; } @@ -969,11 +1030,11 @@ namespace currency bool was_attachment_crypted_entries = false; bool was_extra_crypted_entries = false; - encrypt_attach_visitor v(was_attachment_crypted_entries, derivation); + encrypt_attach_visitor v(was_attachment_crypted_entries, derivation, tx_random_key, destination_addr); for (auto& a : tx.attachment) boost::apply_visitor(v, a); - encrypt_attach_visitor v2(was_extra_crypted_entries, derivation); + encrypt_attach_visitor v2(was_extra_crypted_entries, derivation, tx_random_key, destination_addr); for (auto& a : tx.extra) boost::apply_visitor(v2, a); @@ -2888,6 +2949,13 @@ namespace currency return tools::base58::encode_addr(CURRENCY_PUBLIC_ADDRESS_BASE58_PREFIX, t_serializable_object_to_blob(addr)); // new format Zano address (normal) } //----------------------------------------------------------------------- + bool is_address_looks_like_wrapped(const std::string& addr) + { + if (addr.length() == 42 && addr.substr(0, 2) == "0x") + return true; + else return false; + } + //----------------------------------------------------------------------- std::string get_account_address_and_payment_id_as_str(const account_public_address& addr, const payment_id_t& payment_id) { if (addr.flags == 0) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 6474307d..86952896 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -289,6 +289,7 @@ namespace currency bool decrypt_payload_items(bool is_income, const transaction& tx, const account_keys& acc_keys, std::vector& decrypted_items); void encrypt_attachments(transaction& tx, const account_keys& sender_keys, const account_public_address& destination_addr, const keypair& tx_random_key); bool is_derivation_used_to_encrypt(const transaction& tx, const crypto::key_derivation& derivation); + bool is_address_looks_like_wrapped(const std::string& addr); void load_wallet_transfer_info_flags(tools::wallet_public::wallet_transfer_info& x); uint64_t get_tx_type(const transaction& tx); uint64_t get_tx_type_ex(const transaction& tx, tx_out& htlc_out, txin_htlc& htlc_in); diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 8656eb2c..3517e318 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -20,6 +20,7 @@ #include "wallet/wallet_rpc_server.h" #include "version.h" #include "string_coding.h" +#include "wallet/wrap_service.h" #include @@ -1208,13 +1209,32 @@ bool simple_wallet::transfer(const std::vector &args_) return true; } + std::vector extra; vector dsts; + bool wrapped_transaction = false; for (size_t i = 0; i < local_args.size(); i += 2) { std::string integrated_payment_id; currency::tx_destination_entry de; de.addr.resize(1); - if(!(de.addr.size() == 1 && m_wallet->get_transfer_address(local_args[i], de.addr.front(), integrated_payment_id))) + //check if address looks like wrapped address + if (is_address_looks_like_wrapped(local_args[i])) + { + success_msg_writer(true) << "Address " << local_args[i] << " recognized as wrapped address, creating wrapping transaction..."; + //put into service attachment specially encrypted entry which will contain wrap address and network + tx_service_attachment sa = AUTO_VAL_INIT(sa); + sa.service_id = BC_WRAP_SERVICE_ID; + sa.instruction = BC_WRAP_SERVICE_INSTRUCTION_ERC20; + sa.flags = TX_SERVICE_ATTACHMENT_ENCRYPT_BODY | TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE; + sa.body = local_args[i]; + extra.push_back(sa); + + currency::account_public_address acc = AUTO_VAL_INIT(acc); + currency::get_account_address_from_str(acc, BC_WRAP_SERVICE_CUSTODY_WALLET); + de.addr.front() = acc; + wrapped_transaction = true; + //encrypt body with a special way + }else if(!(de.addr.size() == 1 && m_wallet->get_transfer_address(local_args[i], de.addr.front(), integrated_payment_id))) { fail_msg_writer() << "wrong address: " << local_args[i]; return true; @@ -1258,13 +1278,19 @@ bool simple_wallet::transfer(const std::vector &args_) try { currency::transaction tx; - std::vector extra; m_wallet->transfer(dsts, fake_outs_count, 0, m_wallet->get_core_runtime_config().tx_default_fee, extra, attachments, tx); if (!m_wallet->is_watch_only()) - success_msg_writer(true) << "Money successfully sent, transaction " << get_transaction_hash(tx) << ", " << get_object_blobsize(tx) << " bytes"; + { + if(wrapped_transaction) + success_msg_writer(true) << "Money successfully sent to wZano custody wallet, transaction " << get_transaction_hash(tx) << ", " << get_object_blobsize(tx) << " bytes"; + else + success_msg_writer(true) << "Money successfully sent, transaction " << get_transaction_hash(tx) << ", " << get_object_blobsize(tx) << " bytes"; + } else + { success_msg_writer(true) << "Transaction prepared for signing and saved into \"zano_tx_unsigned\" file, use full wallet to sign transfer and then use \"submit_transfer\" on this wallet to broadcast the transaction to the network"; + } } catch (const tools::error::daemon_busy&) { diff --git a/src/wallet/wrap_service.h b/src/wallet/wrap_service.h new file mode 100644 index 00000000..852d60d7 --- /dev/null +++ b/src/wallet/wrap_service.h @@ -0,0 +1,12 @@ +// Copyright (c) 2014-2018 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#pragma once + +#define BC_WRAP_SERVICE_ID "W" + +#define BC_WRAP_SERVICE_INSTRUCTION_ERC20 "ERC20" //erc20 wrapped operation + + +#define BC_WRAP_SERVICE_CUSTODY_WALLET "aZxbJPXzkjCJDpGEVvkMir9B4fRKPo73r2e5D7nLHuVgEBXXQYc2Tk2hHroxVwiCDLDHZu215pgNocUsrchH4HHzWbHzL4nMfPq" \ No newline at end of file From 4d324fc1bfc2a01b86828913c8aba056de86a2cd Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 24 Jun 2021 20:34:13 +0200 Subject: [PATCH 16/83] fixed default initialization for decrypt/encrypt visitors --- src/currency_core/account.h | 1 + src/currency_core/currency_basic.h | 1 + src/currency_core/currency_format_utils.cpp | 13 +++++++------ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/currency_core/account.h b/src/currency_core/account.h index 305b02e3..e9674307 100644 --- a/src/currency_core/account.h +++ b/src/currency_core/account.h @@ -97,6 +97,7 @@ namespace currency std::vector m_keys_seed_binary; }; + const static account_keys null_acc_keys = AUTO_VAL_INIT(null_acc_keys); std::string transform_addr_to_str(const account_public_address& addr); account_public_address transform_str_to_addr(const std::string& str); diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index 29aa7483..1193bd8a 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -696,6 +696,7 @@ namespace currency return k; } }; + const static keypair null_keypair = AUTO_VAL_INIT(null_keypair); //--------------------------------------------------------------- //PoS //based from ppcoin/novacoin approach diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 0d877864..4e5d717d 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -763,7 +763,7 @@ namespace currency const account_public_address& m_destination_addr; const crypto::key_derivation& m_key; - encrypt_attach_visitor(bool& was_crypted_entries, const crypto::key_derivation& key, const keypair& onetime_keypair = keypair(), const account_public_address& destination_addr = account_public_address()) : + encrypt_attach_visitor(bool& was_crypted_entries, const crypto::key_derivation& key, const keypair& onetime_keypair = null_keypair, const account_public_address& destination_addr = null_pub_addr) : m_was_crypted_entries(was_crypted_entries), m_key(key), m_onetime_keypair(onetime_keypair), m_destination_addr(m_destination_addr) {} void operator()(tx_comment& comment) @@ -807,6 +807,7 @@ namespace currency CHECK_AND_ASSERT_THROW_MES(m_destination_addr.spend_public_key != currency::null_pkey && m_onetime_keypair.sec != currency::null_skey, "tx_service_attachment with TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE: keys uninitialized"); //encrypt with "spend keys" only, to prevent auditable watchers decrypt it bool r = crypto::generate_key_derivation(m_destination_addr.spend_public_key, m_onetime_keypair.sec, derivation_local); + CHECK_AND_ASSERT_THROW_MES(r, "tx_service_attachment with TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE: Failed to make derivation"); crypto::chacha_crypt(sa.body, derivation_local); } else @@ -839,8 +840,8 @@ namespace currency std::vector& rdecrypted_att; decrypt_attach_visitor(const crypto::key_derivation& key, std::vector& decrypted_att, - const account_keys& acc_keys = account_keys(), - const crypto::public_key& tx_onetime_pubkey = crypto::public_key()) : + const account_keys& acc_keys = null_acc_keys, + const crypto::public_key& tx_onetime_pubkey = null_pkey) : rkey(key), rdecrypted_att(decrypted_att), m_acc_keys(acc_keys), @@ -866,7 +867,7 @@ namespace currency //this watch only wallet, decrypting supposed to be impossible return; } - CHECK_AND_ASSERT_THROW_MES(m_acc_keys.spend_secret_key != currency::null_skey, "tx_service_attachment with TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE: keys uninitialized"); + CHECK_AND_ASSERT_THROW_MES(m_acc_keys.spend_secret_key != currency::null_skey && m_tx_onetime_pubkey != currency::null_pkey, "tx_service_attachment with TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE: keys uninitialized"); bool r = crypto::generate_key_derivation(m_tx_onetime_pubkey, m_acc_keys.spend_secret_key, derivation_local); CHECK_AND_ASSERT_THROW_MES(r, "Failed to generate_key_derivation at TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE"); crypto::chacha_crypt(sa.body, derivation_local); @@ -930,8 +931,8 @@ namespace currency //--------------------------------------------------------------- template - bool decrypt_payload_items(const crypto::key_derivation& derivation, const items_container_t& items_to_decrypt, std::vector& decrypted_att, const account_keys& acc_keys = account_keys(), - const crypto::public_key& tx_onetime_pubkey = crypto::public_key()) + bool decrypt_payload_items(const crypto::key_derivation& derivation, const items_container_t& items_to_decrypt, std::vector& decrypted_att, const account_keys& acc_keys = null_acc_keys, + const crypto::public_key& tx_onetime_pubkey = null_pkey) { decrypt_attach_visitor v(derivation, decrypted_att, acc_keys, tx_onetime_pubkey); for (auto& a : items_to_decrypt) From 331548c9a681710ff900db14c72446849ce58064 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 24 Jun 2021 22:10:09 +0200 Subject: [PATCH 17/83] added isolated items to rpc-structures --- src/wallet/wallet2.cpp | 13 +++++++++---- src/wallet/wallet2.h | 8 +++++--- src/wallet/wallet_public_structs_defs.h | 16 +++++++++++++++- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index d0456a00..b6c054a8 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -715,6 +715,11 @@ void wallet2::prepare_wti_decrypted_attachments(wallet_public::wallet_transfer_i wti.show_sender = handle_2_alternative_types_in_variant_container(decrypted_att, [&](const tx_payer& p) { sender_address = p.acc_addr; return false; /* <- continue? */ } ); if (wti.show_sender) wti.remote_addresses.push_back(currency::get_account_address_as_str(sender_address)); + + for (const auto& item : decrypted_att) + { + wti.service_entries.push_back(item); + } } else { @@ -1238,7 +1243,7 @@ void wallet2::prepare_wti(wallet_public::wallet_transfer_info& wti, uint64_t hei wti.tx_blob_size = static_cast(currency::get_object_blobsize(wti.tx)); wti.tx_hash = currency::get_transaction_hash(tx); load_wallet_transfer_info_flags(wti); - bc_services::extract_market_instructions(wti.srv_attachments, tx.attachment); + bc_services::extract_market_instructions(wti.marketplace_entries, tx.attachment); // escrow transactions, which are built with TX_FLAG_SIGNATURE_MODE_SEPARATE flag actually encrypt attachments // with buyer as a sender, and seller as receiver, despite the fact that for both sides transaction seen as outgoing @@ -4570,7 +4575,7 @@ bool wallet2::extract_offers_from_transfer_entry(size_t i, std::unordered_map diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index afcddc49..d9edd8ab 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -87,6 +87,17 @@ namespace wallet_public #define WALLET_TRANSFER_INFO_FLAGS_HTLC_DEPOSIT static_cast(1 << 0) + struct tx_service_attachment_kv: public tx_service_attachment + { + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(service_id) + KV_SERIALIZE(instruction) + KV_SERIALIZE(body) + KV_SERIALIZE_CONTAINER_POD_AS_BLOB(security) + KV_SERIALIZE(flags) + END_KV_SERIALIZE_MAP() + }; + struct wallet_transfer_info { uint64_t amount; @@ -105,16 +116,18 @@ namespace wallet_public bool is_mining; uint64_t tx_type; wallet_transfer_info_details td; + std::vector service_entries; //not included in streaming serialization uint64_t fee; bool show_sender; std::vector contract; uint16_t extra_flags; + //not included in kv serialization map currency::transaction tx; std::vector selected_indicies; - std::list srv_attachments; + std::list marketplace_entries; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(amount) @@ -136,6 +149,7 @@ namespace wallet_public KV_SERIALIZE(tx_type) KV_SERIALIZE(show_sender) KV_SERIALIZE(contract) + KV_SERIALIZE(service_entries) END_KV_SERIALIZE_MAP() }; From d83f8c3e9e9f74d64301708f390ea732f6fffb1a Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 24 Jun 2021 23:24:38 +0200 Subject: [PATCH 18/83] added test isolate_auditable_and_proof --- src/currency_core/currency_format_utils.cpp | 6 +- src/currency_core/currency_format_utils.h | 2 +- src/simplewallet/simplewallet.cpp | 2 +- src/wallet/wallet2.cpp | 5 +- src/wallet/wallet_public_structs_defs.h | 2 +- .../isolate_auditable_and_proof.cpp | 116 ++++++++++++++++++ .../core_tests/isolate_auditable_and_proof.h | 19 +++ 7 files changed, 145 insertions(+), 7 deletions(-) create mode 100644 tests/core_tests/isolate_auditable_and_proof.cpp create mode 100644 tests/core_tests/isolate_auditable_and_proof.h diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 4e5d717d..27ecdc9d 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -793,7 +793,7 @@ namespace currency } void operator()(tx_service_attachment& sa) { - const std::string orignal_body = sa.body; + const std::string original_body = sa.body; if (sa.flags&TX_SERVICE_ATTACHMENT_DEFLATE_BODY) { zlib_helper::pack(sa.body); @@ -818,7 +818,7 @@ namespace currency { //take hash from derivation and use it as a salt crypto::hash derivation_hash = crypto::cn_fast_hash(&derivation_local, sizeof(derivation_local)); - std::string salted_body = orignal_body; + std::string salted_body = original_body; string_tools::apped_pod_to_strbuff(salted_body, derivation_hash); crypto::hash proof_hash = crypto::cn_fast_hash(salted_body.data(), salted_body.size()); sa.security.push_back(*(crypto::public_key*)&proof_hash); @@ -2950,7 +2950,7 @@ namespace currency return tools::base58::encode_addr(CURRENCY_PUBLIC_ADDRESS_BASE58_PREFIX, t_serializable_object_to_blob(addr)); // new format Zano address (normal) } //----------------------------------------------------------------------- - bool is_address_looks_like_wrapped(const std::string& addr) + bool is_address_like_wrapped(const std::string& addr) { if (addr.length() == 42 && addr.substr(0, 2) == "0x") return true; diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 86952896..9a108417 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -289,7 +289,7 @@ namespace currency bool decrypt_payload_items(bool is_income, const transaction& tx, const account_keys& acc_keys, std::vector& decrypted_items); void encrypt_attachments(transaction& tx, const account_keys& sender_keys, const account_public_address& destination_addr, const keypair& tx_random_key); bool is_derivation_used_to_encrypt(const transaction& tx, const crypto::key_derivation& derivation); - bool is_address_looks_like_wrapped(const std::string& addr); + bool is_address_like_wrapped(const std::string& addr); void load_wallet_transfer_info_flags(tools::wallet_public::wallet_transfer_info& x); uint64_t get_tx_type(const transaction& tx); uint64_t get_tx_type_ex(const transaction& tx, tx_out& htlc_out, txin_htlc& htlc_in); diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 3517e318..654ec78d 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -1218,7 +1218,7 @@ bool simple_wallet::transfer(const std::vector &args_) currency::tx_destination_entry de; de.addr.resize(1); //check if address looks like wrapped address - if (is_address_looks_like_wrapped(local_args[i])) + if (is_address_like_wrapped(local_args[i])) { success_msg_writer(true) << "Address " << local_args[i] << " recognized as wrapped address, creating wrapping transaction..."; //put into service attachment specially encrypted entry which will contain wrap address and network diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index b6c054a8..2f6f0dd7 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -718,7 +718,10 @@ void wallet2::prepare_wti_decrypted_attachments(wallet_public::wallet_transfer_i for (const auto& item : decrypted_att) { - wti.service_entries.push_back(item); + if (item.type() == typeid(currency::tx_service_attachment)) + { + wti.service_entries.push_back(tools::wallet_public::tx_service_attachment_kv(boost::get(item))); + } } } else diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index d9edd8ab..02bc1973 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -87,7 +87,7 @@ namespace wallet_public #define WALLET_TRANSFER_INFO_FLAGS_HTLC_DEPOSIT static_cast(1 << 0) - struct tx_service_attachment_kv: public tx_service_attachment + struct tx_service_attachment_kv: public currency::tx_service_attachment { BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(service_id) diff --git a/tests/core_tests/isolate_auditable_and_proof.cpp b/tests/core_tests/isolate_auditable_and_proof.cpp new file mode 100644 index 00000000..2fb3fa69 --- /dev/null +++ b/tests/core_tests/isolate_auditable_and_proof.cpp @@ -0,0 +1,116 @@ +// Copyright (c) 2014-2021 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "chaingen.h" +#include "escrow_wallet_tests.h" +#include "random_helper.h" +#include "chaingen_helpers.h" +#include "atomic_tests.h" + +using namespace epee; +using namespace crypto; +using namespace currency; + + +isolate_auditable_and_proof::isolate_auditable_and_proof() +{ + REGISTER_CALLBACK_METHOD(isolate_auditable_and_proof, c1); + REGISTER_CALLBACK_METHOD(isolate_auditable_and_proof, configure_core); +} + +bool isolate_auditable_and_proof::generate(std::vector& events) const +{ + random_state_test_restorer::reset_random(0); // to make the test deterministic + m_genesis_timestamp = 1450000000; + test_core_time::adjust(m_genesis_timestamp); + + + epee::debug::get_set_enable_assert(true, true); + + currency::account_base genesis_acc; + genesis_acc.generate(); + m_mining_accunt.generate(); + m_mining_accunt.set_createtime(m_genesis_timestamp); + + + block blk_0 = AUTO_VAL_INIT(blk_0); + generator.construct_genesis_block(blk_0, genesis_acc, test_core_time::get_time()); + events.push_back(blk_0); + DO_CALLBACK(events, "configure_core"); + REWIND_BLOCKS_N(events, blk_0r, blk_0, m_mining_accunt, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 5); + + DO_CALLBACK(events, "c1"); + epee::debug::get_set_enable_assert(true, false); + return true; +} + +bool isolate_auditable_and_proof::configure_core(currency::core& c, size_t ev_index, const std::vector& events) +{ + return true; +} +/************************************************************************/ +/* */ +/************************************************************************/ + +bool isolate_auditable_and_proof::c1(currency::core& c, size_t ev_index, const std::vector& events) +{ + epee::debug::get_set_enable_assert(true, true); + misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler([&](){epee::debug::get_set_enable_assert(true, false); }); + + LOG_PRINT_MAGENTA("Mining Address: " << currency::get_account_address_as_str(m_mining_accunt.get_public_address()), LOG_LEVEL_0); + + currency::account_base auditable_test; + auditable_test.generate(true); + auditable_test.set_createtime(m_genesis_timestamp); + LOG_PRINT_MAGENTA(": " << currency::get_account_address_as_str(auditable_test.get_public_address()), LOG_LEVEL_0); + std::shared_ptr auditable_test_instance = init_playtime_test_wallet(events, c, auditable_test); + + +#define AMOUNT_TO_TRANSFER_LOCAL (TESTS_DEFAULT_FEE*10) + + std::shared_ptr miner_wlt = init_playtime_test_wallet(events, c, m_mining_accunt); + miner_wlt->refresh(); + + + //create transaction that use TX_SERVICE_ATTACHMENT_ENCRYPT_BODY and TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE + { + std::vector extra; + std::vector attachments; + vector dsts; + + currency::tx_destination_entry de; + de.addr.resize(1); + //put into service attachment specially encrypted entry which will contain wrap address and network + tx_service_attachment sa = AUTO_VAL_INIT(sa); + sa.service_id = BC_WRAP_SERVICE_ID; + sa.instruction = BC_WRAP_SERVICE_INSTRUCTION_ERC20; + sa.flags = TX_SERVICE_ATTACHMENT_ENCRYPT_BODY | TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE; + sa.body = "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B"; + extra.push_back(sa); + + currency::account_public_address acc = AUTO_VAL_INIT(acc); + de.addr.front() = auditable_test.get_public_address(); + currency::transaction tx; + miner_wlt->transfer(dsts, 0, 0, miner_wlt->get_core_runtime_config().tx_default_fee, extra, attachments, tx); + } + + bool r = mine_next_pow_blocks_in_playtime(m_mining_accunt.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); + + miner_wlt->refresh(); + auditable_test_instance->refresh(); + + epee::json_rpc::error je; + tools::wallet_rpc_server::connection_context ctx; + tools::wallet_rpc_server miner_wlt_rpc(*auditable_test_instance); + wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::request req = AUTO_VAL_INIT(); + wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::request res = AUTO_VAL_INIT(); + req.count = 100; + req.offset = 0; + miner_wlt_rpc->on_get_recent_txs_and_info(req, res, je, ctx); + std::string ps = epee::serialization::store_t_to_json(res); + + return r; +} + diff --git a/tests/core_tests/isolate_auditable_and_proof.h b/tests/core_tests/isolate_auditable_and_proof.h new file mode 100644 index 00000000..b0df5b8d --- /dev/null +++ b/tests/core_tests/isolate_auditable_and_proof.h @@ -0,0 +1,19 @@ +// Copyright (c) 2014-2021 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#pragma once +#include "chaingen.h" +#include "wallet_tests_basic.h" + + +struct isolate_auditable_and_proof : public wallet_test +{ + isolate_auditable_and_proof(); + bool generate(std::vector& events) const; + virtual bool c1(currency::core& c, size_t ev_index, const std::vector& events)=0; + virtual bool configure_core(currency::core& c, size_t ev_index, const std::vector& events); +protected: + mutable uint64_t m_genesis_timestamp; + mutable currency::account_base m_mining_accunt; +}; From 33b26a68c9230718f92fddbbf89747cebd5fd7d2 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 26 Jun 2021 02:40:41 +0200 Subject: [PATCH 19/83] bunch of fixes over isolate_auditable_and_proof test --- src/currency_core/currency_basic.h | 8 ++++++++ src/wallet/wallet2.cpp | 2 +- src/wallet/wallet_public_structs_defs.h | 13 +------------ tests/core_tests/isolate_auditable_and_proof.cpp | 12 +++++++----- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index 1193bd8a..7dd6a8cd 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -383,6 +383,14 @@ namespace currency FIELD(security) FIELD(flags) END_SERIALIZE() + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(service_id) + KV_SERIALIZE(instruction) + KV_SERIALIZE(body) + KV_SERIALIZE_CONTAINER_POD_AS_BLOB(security) + KV_SERIALIZE(flags) + END_KV_SERIALIZE_MAP() }; // applicable flags for tx_service_attachment::flags, can be combined using bitwise OR diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 2f6f0dd7..5b753b91 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -720,7 +720,7 @@ void wallet2::prepare_wti_decrypted_attachments(wallet_public::wallet_transfer_i { if (item.type() == typeid(currency::tx_service_attachment)) { - wti.service_entries.push_back(tools::wallet_public::tx_service_attachment_kv(boost::get(item))); + wti.service_entries.push_back(boost::get(item)); } } } diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 02bc1973..3b78f2b4 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -87,17 +87,6 @@ namespace wallet_public #define WALLET_TRANSFER_INFO_FLAGS_HTLC_DEPOSIT static_cast(1 << 0) - struct tx_service_attachment_kv: public currency::tx_service_attachment - { - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(service_id) - KV_SERIALIZE(instruction) - KV_SERIALIZE(body) - KV_SERIALIZE_CONTAINER_POD_AS_BLOB(security) - KV_SERIALIZE(flags) - END_KV_SERIALIZE_MAP() - }; - struct wallet_transfer_info { uint64_t amount; @@ -116,7 +105,7 @@ namespace wallet_public bool is_mining; uint64_t tx_type; wallet_transfer_info_details td; - std::vector service_entries; + std::vector service_entries; //not included in streaming serialization uint64_t fee; bool show_sender; diff --git a/tests/core_tests/isolate_auditable_and_proof.cpp b/tests/core_tests/isolate_auditable_and_proof.cpp index 2fb3fa69..b2907824 100644 --- a/tests/core_tests/isolate_auditable_and_proof.cpp +++ b/tests/core_tests/isolate_auditable_and_proof.cpp @@ -6,7 +6,9 @@ #include "escrow_wallet_tests.h" #include "random_helper.h" #include "chaingen_helpers.h" -#include "atomic_tests.h" +#include "isolate_auditable_and_proof.h" +#include "wallet/wrap_service.h" +#include "wallet/wallet_rpc_server.h" using namespace epee; using namespace crypto; @@ -77,7 +79,7 @@ bool isolate_auditable_and_proof::c1(currency::core& c, size_t ev_index, const s { std::vector extra; std::vector attachments; - vector dsts; + std::vector dsts; currency::tx_destination_entry de; de.addr.resize(1); @@ -104,11 +106,11 @@ bool isolate_auditable_and_proof::c1(currency::core& c, size_t ev_index, const s epee::json_rpc::error je; tools::wallet_rpc_server::connection_context ctx; tools::wallet_rpc_server miner_wlt_rpc(*auditable_test_instance); - wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::request req = AUTO_VAL_INIT(); - wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::request res = AUTO_VAL_INIT(); + tools::wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::request req = AUTO_VAL_INIT(req); + tools::wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::response res = AUTO_VAL_INIT(res); req.count = 100; req.offset = 0; - miner_wlt_rpc->on_get_recent_txs_and_info(req, res, je, ctx); + miner_wlt_rpc.on_get_recent_txs_and_info(req, res, je, ctx); std::string ps = epee::serialization::store_t_to_json(res); return r; From 0d7b10eddaa42301b032776ce33fac111343df3e Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sun, 27 Jun 2021 01:24:04 +0200 Subject: [PATCH 20/83] fixed minor bugs, proofs working now --- src/currency_core/currency_format_utils.cpp | 4 ++-- tests/core_tests/chaingen_main.cpp | 3 +++ tests/core_tests/chaingen_tests_list.h | 1 + tests/core_tests/isolate_auditable_and_proof.cpp | 2 +- tests/core_tests/isolate_auditable_and_proof.h | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 27ecdc9d..73bf0200 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -764,7 +764,7 @@ namespace currency const crypto::key_derivation& m_key; encrypt_attach_visitor(bool& was_crypted_entries, const crypto::key_derivation& key, const keypair& onetime_keypair = null_keypair, const account_public_address& destination_addr = null_pub_addr) : - m_was_crypted_entries(was_crypted_entries), m_key(key), m_onetime_keypair(onetime_keypair), m_destination_addr(m_destination_addr) + m_was_crypted_entries(was_crypted_entries), m_key(key), m_onetime_keypair(onetime_keypair), m_destination_addr(destination_addr) {} void operator()(tx_comment& comment) { @@ -870,7 +870,7 @@ namespace currency CHECK_AND_ASSERT_THROW_MES(m_acc_keys.spend_secret_key != currency::null_skey && m_tx_onetime_pubkey != currency::null_pkey, "tx_service_attachment with TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE: keys uninitialized"); bool r = crypto::generate_key_derivation(m_tx_onetime_pubkey, m_acc_keys.spend_secret_key, derivation_local); CHECK_AND_ASSERT_THROW_MES(r, "Failed to generate_key_derivation at TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE"); - crypto::chacha_crypt(sa.body, derivation_local); + crypto::chacha_crypt(local_sa.body, derivation_local); } else diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index 1f21fce7..6cd4425d 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -1029,6 +1029,9 @@ int main(int argc, char* argv[]) GENERATE_AND_PLAY(atomic_test_wrong_redeem_wrong_refund); GENERATE_AND_PLAY(atomic_test_altchain_simple); GENERATE_AND_PLAY(atomic_test_check_hardfork_rules); + + GENERATE_AND_PLAY(isolate_auditable_and_proof); + // GENERATE_AND_PLAY(gen_block_reward); diff --git a/tests/core_tests/chaingen_tests_list.h b/tests/core_tests/chaingen_tests_list.h index 2a419569..9d2e4c54 100644 --- a/tests/core_tests/chaingen_tests_list.h +++ b/tests/core_tests/chaingen_tests_list.h @@ -39,3 +39,4 @@ #include "hard_fork_1.h" #include "hard_fork_2.h" #include "atomic_tests.h" +#include "isolate_auditable_and_proof.h" diff --git a/tests/core_tests/isolate_auditable_and_proof.cpp b/tests/core_tests/isolate_auditable_and_proof.cpp index b2907824..9b602f09 100644 --- a/tests/core_tests/isolate_auditable_and_proof.cpp +++ b/tests/core_tests/isolate_auditable_and_proof.cpp @@ -87,7 +87,7 @@ bool isolate_auditable_and_proof::c1(currency::core& c, size_t ev_index, const s tx_service_attachment sa = AUTO_VAL_INIT(sa); sa.service_id = BC_WRAP_SERVICE_ID; sa.instruction = BC_WRAP_SERVICE_INSTRUCTION_ERC20; - sa.flags = TX_SERVICE_ATTACHMENT_ENCRYPT_BODY | TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE; + sa.flags = TX_SERVICE_ATTACHMENT_ENCRYPT_BODY | TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE| TX_SERVICE_ATTACHMENT_ENCRYPT_ADD_PROOF; sa.body = "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B"; extra.push_back(sa); diff --git a/tests/core_tests/isolate_auditable_and_proof.h b/tests/core_tests/isolate_auditable_and_proof.h index b0df5b8d..361abc27 100644 --- a/tests/core_tests/isolate_auditable_and_proof.h +++ b/tests/core_tests/isolate_auditable_and_proof.h @@ -11,7 +11,7 @@ struct isolate_auditable_and_proof : public wallet_test { isolate_auditable_and_proof(); bool generate(std::vector& events) const; - virtual bool c1(currency::core& c, size_t ev_index, const std::vector& events)=0; + virtual bool c1(currency::core& c, size_t ev_index, const std::vector& events); virtual bool configure_core(currency::core& c, size_t ev_index, const std::vector& events); protected: mutable uint64_t m_genesis_timestamp; From c9b7e5689c95d62dcd01dde1a7077741cb242009 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 28 Jun 2021 00:08:33 +0200 Subject: [PATCH 21/83] fixed last bugs in isolate_auditable_and_proof --- src/currency_core/currency_format_utils.cpp | 4 ++-- tests/core_tests/isolate_auditable_and_proof.cpp | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 73bf0200..d78ec011 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1017,8 +1017,8 @@ namespace currency return true; } - decrypt_payload_items(derivation, tx.extra, decrypted_items, acc_keys, get_tx_pub_key_from_extra(tx)); - decrypt_payload_items(derivation, tx.attachment, decrypted_items, acc_keys, get_tx_pub_key_from_extra(tx)); + decrypt_payload_items(derivation, tx.extra, decrypted_items, is_income ? acc_keys: account_keys(), get_tx_pub_key_from_extra(tx)); + decrypt_payload_items(derivation, tx.attachment, decrypted_items, is_income ? acc_keys : account_keys(), get_tx_pub_key_from_extra(tx)); return true; } diff --git a/tests/core_tests/isolate_auditable_and_proof.cpp b/tests/core_tests/isolate_auditable_and_proof.cpp index 9b602f09..f752b81a 100644 --- a/tests/core_tests/isolate_auditable_and_proof.cpp +++ b/tests/core_tests/isolate_auditable_and_proof.cpp @@ -93,7 +93,9 @@ bool isolate_auditable_and_proof::c1(currency::core& c, size_t ev_index, const s currency::account_public_address acc = AUTO_VAL_INIT(acc); de.addr.front() = auditable_test.get_public_address(); - currency::transaction tx; + de.amount = AMOUNT_TO_TRANSFER_LOCAL; + dsts.push_back(de); + currency::transaction tx = AUTO_VAL_INIT(tx); miner_wlt->transfer(dsts, 0, 0, miner_wlt->get_core_runtime_config().tx_default_fee, extra, attachments, tx); } From e27b8fdf18893eda414984cfb6329964269474ae Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 29 Jun 2021 16:46:03 +0200 Subject: [PATCH 22/83] final fixes in isolate_auditable_and_proof --- tests/core_tests/isolate_auditable_and_proof.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/core_tests/isolate_auditable_and_proof.cpp b/tests/core_tests/isolate_auditable_and_proof.cpp index f752b81a..e3fadbdb 100644 --- a/tests/core_tests/isolate_auditable_and_proof.cpp +++ b/tests/core_tests/isolate_auditable_and_proof.cpp @@ -76,7 +76,7 @@ bool isolate_auditable_and_proof::c1(currency::core& c, size_t ev_index, const s //create transaction that use TX_SERVICE_ATTACHMENT_ENCRYPT_BODY and TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE - { + //{ std::vector extra; std::vector attachments; std::vector dsts; @@ -97,7 +97,7 @@ bool isolate_auditable_and_proof::c1(currency::core& c, size_t ev_index, const s dsts.push_back(de); currency::transaction tx = AUTO_VAL_INIT(tx); miner_wlt->transfer(dsts, 0, 0, miner_wlt->get_core_runtime_config().tx_default_fee, extra, attachments, tx); - } + //} bool r = mine_next_pow_blocks_in_playtime(m_mining_accunt.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); @@ -113,8 +113,13 @@ bool isolate_auditable_and_proof::c1(currency::core& c, size_t ev_index, const s req.count = 100; req.offset = 0; miner_wlt_rpc.on_get_recent_txs_and_info(req, res, je, ctx); - std::string ps = epee::serialization::store_t_to_json(res); + CHECK_AND_ASSERT_MES(res.transfers.size() == 1, false, "res.transfers.size() == 1 failed"); + CHECK_AND_ASSERT_MES(res.transfers[0].service_entries.size(), false, "res.transfers[0].service_entries.size() failed"); + + CHECK_AND_ASSERT_MES(res.transfers[0].service_entries[0].body == sa.body, false, "res.transfers[0].service_entries[0].body == sa.body failed"); + CHECK_AND_ASSERT_MES(res.transfers[0].service_entries[0].service_id == sa.service_id, false, "res.transfers[0].service_entries[0].service_id == sa.service_id failed"); + CHECK_AND_ASSERT_MES(res.transfers[0].service_entries[0].instruction == sa.instruction, false, "res.transfers[0].service_entries[0].instruction == sa.instruction failed"); - return r; + return true; } From 2e5c49300465a848605e22e1b282543d63bab4a1 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 1 Jul 2021 21:05:50 +0200 Subject: [PATCH 23/83] added transfer_internal_index to wallet_transfer_info struct --- src/wallet/wallet2.cpp | 3 ++- src/wallet/wallet_public_structs_defs.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 5b753b91..5801d511 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1662,7 +1662,7 @@ void wallet2::handle_pulled_blocks(size_t& blocks_added, std::atomic& stop //block matched in that number last_matched_index = height; been_matched_block = true; - WLT_LOG_L2("Block " << bl_id << " @ " << height << " is already in wallet's blockchain"); + WLT_LOG_L4("Block " << bl_id << " @ " << height << " is already in wallet's blockchain"); } else { @@ -3207,6 +3207,7 @@ void wallet2::get_recent_transfers_history(std::vector= count) { diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 3b78f2b4..48251797 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -111,6 +111,7 @@ namespace wallet_public bool show_sender; std::vector contract; uint16_t extra_flags; + uint64_t transfer_internal_index; //not included in kv serialization map @@ -139,6 +140,7 @@ namespace wallet_public KV_SERIALIZE(show_sender) KV_SERIALIZE(contract) KV_SERIALIZE(service_entries) + KV_SERIALIZE(transfer_internal_index) END_KV_SERIALIZE_MAP() }; From cabdf494301e15b7d53fc376b77d7e64fc8f34c2 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 1 Jul 2021 23:00:28 +0200 Subject: [PATCH 24/83] added current_height to COMMAND_RPC_GET_RECENT_TXS_AND_INFO response --- src/wallet/wallet_public_structs_defs.h | 5 +++++ src/wallet/wallet_rpc_server.cpp | 2 ++ src/wallet/wallet_rpc_server.h | 8 ++++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 48251797..f93242e3 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -259,6 +259,7 @@ namespace wallet_public uint64_t transfer_entries_count; bool is_whatch_only; std::vector utxo_distribution; + uint64_t current_height; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(address) @@ -267,6 +268,8 @@ namespace wallet_public KV_SERIALIZE(transfer_entries_count) KV_SERIALIZE(is_whatch_only) KV_SERIALIZE(utxo_distribution) + KV_SERIALIZE(current_height) + KV_SERIALIZE_POD_AS_HEX_STRING(last_block_id) END_KV_SERIALIZE_MAP() }; }; @@ -304,6 +307,7 @@ namespace wallet_public uint64_t transfer_entries_count; uint64_t balance; uint64_t unlocked_balance; + uint64_t curent_height; BEGIN_KV_SERIALIZE_MAP() @@ -311,6 +315,7 @@ namespace wallet_public KV_SERIALIZE(transfer_entries_count) KV_SERIALIZE(balance) KV_SERIALIZE(unlocked_balance) + KV_SERIALIZE(curent_height) END_KV_SERIALIZE_MAP() }; diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 71d34fa1..4f581e22 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -208,6 +208,7 @@ namespace tools for (const auto& ent : distribution) res.utxo_distribution.push_back(currency::print_money_brief(ent.first) + ":" + std::to_string(ent.second)); + res.current_height = m_wallet.get_top_block_height(); return true; } catch (std::exception& e) @@ -245,6 +246,7 @@ namespace tools res.pi.balance = m_wallet.balance(res.pi.unlocked_balance); res.pi.transfer_entries_count = m_wallet.get_transfer_entries_count(); res.pi.transfers_count = m_wallet.get_recent_transfers_total_count(); + res.pi.curent_height = m_wallet.get_top_block_height(); } if (req.offset == 0) diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h index 2d94bc52..3c75296e 100644 --- a/src/wallet/wallet_rpc_server.h +++ b/src/wallet/wallet_rpc_server.h @@ -66,10 +66,10 @@ namespace tools MAP_JON_RPC_WE("marketplace_push_update_offer", on_marketplace_push_update_offer, wallet_public::COMMAND_MARKETPLACE_PUSH_UPDATE_OFFER) MAP_JON_RPC_WE("marketplace_cancel_offer", on_marketplace_cancel_offer, wallet_public::COMMAND_MARKETPLACE_CANCEL_OFFER) //HTLC API - MAP_JON_RPC_WE("atomics_create_htlc_proposal", on_create_htlc_proposal, wallet_public::COMMAND_CREATE_HTLC_PROPOSAL) - MAP_JON_RPC_WE("atomics_get_list_of_active_htlc", on_get_list_of_active_htlc, wallet_public::COMMAND_GET_LIST_OF_ACTIVE_HTLC) - MAP_JON_RPC_WE("atomics_redeem_htlc", on_redeem_htlc, wallet_public::COMMAND_REDEEM_HTLC) - MAP_JON_RPC_WE("atomics_check_htlc_redeemed", on_check_htlc_redeemed, wallet_public::COMMAND_CHECK_HTLC_REDEEMED) + MAP_JON_RPC_WE("atomics_create_htlc_proposal", on_create_htlc_proposal, wallet_public::COMMAND_CREATE_HTLC_PROPOSAL) + MAP_JON_RPC_WE("atomics_get_list_of_active_htlc", on_get_list_of_active_htlc, wallet_public::COMMAND_GET_LIST_OF_ACTIVE_HTLC) + MAP_JON_RPC_WE("atomics_redeem_htlc", on_redeem_htlc, wallet_public::COMMAND_REDEEM_HTLC) + MAP_JON_RPC_WE("atomics_check_htlc_redeemed", on_check_htlc_redeemed, wallet_public::COMMAND_CHECK_HTLC_REDEEMED) END_JSON_RPC_MAP() END_URI_MAP2() From 585c01d3aaf0b65c977faf972336452557ebe91f Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 1 Jul 2021 23:47:31 +0200 Subject: [PATCH 25/83] removed forgotten field --- src/wallet/wallet_public_structs_defs.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index f93242e3..4c3061fd 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -269,7 +269,6 @@ namespace wallet_public KV_SERIALIZE(is_whatch_only) KV_SERIALIZE(utxo_distribution) KV_SERIALIZE(current_height) - KV_SERIALIZE_POD_AS_HEX_STRING(last_block_id) END_KV_SERIALIZE_MAP() }; }; From 83dcb88d229fc31074ec878a8f58e5ce345a2782 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sun, 4 Jul 2021 21:08:54 +0200 Subject: [PATCH 26/83] added FORCE_HEADER_ONLY for projects that use header files as external interface --- src/currency_core/account.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/currency_core/account.h b/src/currency_core/account.h index e9674307..37a0c953 100644 --- a/src/currency_core/account.h +++ b/src/currency_core/account.h @@ -16,13 +16,15 @@ #define SEED_PHRASE_V2_WORDS_COUNT 26 +#ifndef FORCE_HEADER_ONLY + #define KV_SERIALIZE_ADDRESS_AS_TEXT_N(varialble, val_name) \ + KV_SERIALIZE_CUSTOM_N(varialble, std::string, currency::transform_addr_to_str, currency::transform_str_to_addr, val_name) -#define KV_SERIALIZE_ADDRESS_AS_TEXT_N(varialble, val_name) \ - KV_SERIALIZE_CUSTOM_N(varialble, std::string, currency::transform_addr_to_str, currency::transform_str_to_addr, val_name) - -#define KV_SERIALIZE_ADDRESS_AS_TEXT(varialble) KV_SERIALIZE_ADDRESS_AS_TEXT_N(varialble, #varialble) - - + #define KV_SERIALIZE_ADDRESS_AS_TEXT(varialble) KV_SERIALIZE_ADDRESS_AS_TEXT_N(varialble, #varialble) +#else + #define KV_SERIALIZE_ADDRESS_AS_TEXT_N(varialble, val_name) + #define KV_SERIALIZE_ADDRESS_AS_TEXT(varialble) +#endif namespace currency { From 232a6d71d0128df159ef0edfca7913a76e4a5432 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 6 Jul 2021 15:40:40 +0200 Subject: [PATCH 27/83] removed annoying < and > symbols --- src/common/crypto_stream_operators.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/crypto_stream_operators.h b/src/common/crypto_stream_operators.h index 0201603b..fa2531de 100644 --- a/src/common/crypto_stream_operators.h +++ b/src/common/crypto_stream_operators.h @@ -15,20 +15,20 @@ bool parse_hash256(const std::string str_hash, crypto::hash& hash); template std::ostream &print_t(std::ostream &o, const T &v) { - return o << "<" << epee::string_tools::pod_to_hex(v) << ">"; + return o << "" << epee::string_tools::pod_to_hex(v) << ""; } template std::ostream &print16(std::ostream &o, const T &v) { - return o << "<" << epee::string_tools::pod_to_hex(v).substr(0, 5) << "..>"; + return o << "" << epee::string_tools::pod_to_hex(v).substr(0, 5) << ".."; } template std::string print16(const T &v) { - return std::string("<") + epee::string_tools::pod_to_hex(v).substr(0, 5) + "..>"; + return std::string("") + epee::string_tools::pod_to_hex(v).substr(0, 5) + ".."; } From 71c9069d27aae50287d73ed8eaf60b23d925f1c0 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 17 Jul 2021 00:05:41 +0200 Subject: [PATCH 28/83] extended wallet transfer API to service_entries option --- src/currency_core/currency_basic.h | 2 +- src/wallet/wallet2.h | 7 ++++--- src/wallet/wallet_public_structs_defs.h | 5 ++++- src/wallet/wallet_rpc_server.cpp | 28 ++++++++++++++++++------- src/wallet/wrap_service.h | 3 ++- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index 7dd6a8cd..dc973a66 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -387,7 +387,7 @@ namespace currency BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(service_id) KV_SERIALIZE(instruction) - KV_SERIALIZE(body) + KV_SERIALIZE_BLOB_AS_HEX_STRING(body) KV_SERIALIZE_CONTAINER_POD_AS_BLOB(security) KV_SERIALIZE(flags) END_KV_SERIALIZE_MAP() diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 4d4d8b92..b1281e08 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -595,12 +595,12 @@ namespace tools void transfer(construct_tx_param& ctp, currency::transaction &tx, bool send_to_network, - std::string* p_unsigned_filename_or_tx_blob_str); + std::string* p_unsigned_filename_or_tx_blob_str = nullptr); void transfer(construct_tx_param& ctp, currency::finalized_tx& result, bool send_to_network, - std::string* p_unsigned_filename_or_tx_blob_str); + std::string* p_unsigned_filename_or_tx_blob_str = nullptr); template @@ -854,6 +854,7 @@ namespace tools uint64_t get_sync_progress(); uint64_t get_wallet_file_size()const; void set_use_deffered_global_outputs(bool use); + construct_tx_param get_default_construct_tx_param_inital(); /* create_htlc_proposal: if htlc_hash == null_hash, then this wallet is originator of the atomic process, and @@ -943,7 +944,7 @@ private: void change_contract_state(wallet_public::escrow_contract_details_basic& contract, uint32_t new_state, const crypto::hash& contract_id, const wallet_public::wallet_transfer_info& wti) const; void change_contract_state(wallet_public::escrow_contract_details_basic& contract, uint32_t new_state, const crypto::hash& contract_id, const std::string& reason = "internal intention") const; - construct_tx_param get_default_construct_tx_param_inital(); + const construct_tx_param& get_default_construct_tx_param(); uint64_t get_tx_expiration_median() const; diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 4c3061fd..0084e418 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -388,16 +388,19 @@ namespace wallet_public std::string comment; bool push_payer; bool hide_receiver; + std::vector service_entries; + bool service_entries_permanent; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(destinations) KV_SERIALIZE(fee) KV_SERIALIZE(mixin) - //KV_SERIALIZE(unlock_time) KV_SERIALIZE(payment_id) KV_SERIALIZE(comment) KV_SERIALIZE(push_payer) KV_SERIALIZE(hide_receiver) + KV_SERIALIZE(service_entries) + KV_SERIALIZE(service_entries_permanent) END_KV_SERIALIZE_MAP() }; diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 4f581e22..13b9834a 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -281,7 +281,18 @@ namespace tools return false; } - std::vector dsts; + construct_tx_param ctp = m_wallet.get_default_construct_tx_param_inital(); + if (req.service_entries_permanent) + { + //put it to extra + ctp.extra.insert(ctp.extra.end(), req.service_entries.begin(), req.service_entries.end()); + } + else + { + //put it to attachments + ctp.attachments.insert(ctp.extra.end(), req.service_entries.begin(), req.service_entries.end()); + } + std::vector& dsts = ctp.dsts; for (auto it = req.destinations.begin(); it != req.destinations.end(); it++) { currency::tx_destination_entry de; @@ -308,8 +319,8 @@ namespace tools } try { - std::vector attachments; - std::vector extra; + std::vector& attachments = ctp.attachments; + std::vector& extra = ctp.extra; if (!payment_id.empty() && !currency::set_payment_id_to_tx(attachments, payment_id)) { er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID; @@ -338,10 +349,11 @@ namespace tools } } - currency::transaction tx; - + currency::finalized_tx result = AUTO_VAL_INIT(result); std::string unsigned_tx_blob_str; - m_wallet.transfer(dsts, req.mixin, 0/*req.unlock_time*/, req.fee, extra, attachments, detail::ssi_digit, tx_dust_policy(DEFAULT_DUST_THRESHOLD), tx, CURRENCY_TO_KEY_OUT_RELAXED, true, 0, true, &unsigned_tx_blob_str); + ctp.fee = req.fee; + ctp.fake_outputs_count = 0; + m_wallet.transfer(ctp, result, true, &unsigned_tx_blob_str); if (m_wallet.is_watch_only()) { res.tx_unsigned_hex = epee::string_tools::buff_to_hex_nodelimer(unsigned_tx_blob_str); // watch-only wallets could not sign and relay transactions @@ -349,8 +361,8 @@ namespace tools } else { - res.tx_hash = epee::string_tools::pod_to_hex(currency::get_transaction_hash(tx)); - res.tx_size = get_object_blobsize(tx); + res.tx_hash = epee::string_tools::pod_to_hex(currency::get_transaction_hash(result.tx)); + res.tx_size = get_object_blobsize(result.tx); } return true; } diff --git a/src/wallet/wrap_service.h b/src/wallet/wrap_service.h index 852d60d7..52b288d4 100644 --- a/src/wallet/wrap_service.h +++ b/src/wallet/wrap_service.h @@ -6,7 +6,8 @@ #define BC_WRAP_SERVICE_ID "W" -#define BC_WRAP_SERVICE_INSTRUCTION_ERC20 "ERC20" //erc20 wrapped operation +#define BC_WRAP_SERVICE_INSTRUCTION_ERC20 "ERC20" //erc20 wrap operation +#define BC_WRAP_SERVICE_INSTRUCTION_UNWRAP "UNWRAP" //erc20 unwrap operation #define BC_WRAP_SERVICE_CUSTODY_WALLET "aZxbJPXzkjCJDpGEVvkMir9B4fRKPo73r2e5D7nLHuVgEBXXQYc2Tk2hHroxVwiCDLDHZu215pgNocUsrchH4HHzWbHzL4nMfPq" \ No newline at end of file From 9d21077b5ecb720c4e44e78372b542efcf5b5dca Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sun, 18 Jul 2021 01:57:45 +0200 Subject: [PATCH 29/83] Added green logs shortcut --- contrib/epee/include/misc_log_ex.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h index e0a58617..1d54b6f9 100644 --- a/contrib/epee/include/misc_log_ex.h +++ b/contrib/epee/include/misc_log_ex.h @@ -183,7 +183,8 @@ DISABLE_VS_WARNINGS(4100) #define LOG_PRINT_CYAN(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_cyan) #define LOG_PRINT_MAGENTA(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_magenta) -#define LOG_PRINT_RED_L0(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_red) +#define LOG_PRINT_RED_L0(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_red) +#define LOG_PRINT_GREEN_L0(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_green) #define LOG_PRINT_L0(mess) LOG_PRINT(mess, LOG_LEVEL_0) #define LOG_PRINT_L1(mess) LOG_PRINT(mess, LOG_LEVEL_1) From fafdfd196a21984888aa5e0d1395995aee282374 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 19 Jul 2021 22:52:59 +0200 Subject: [PATCH 30/83] modified logging in wallet --- contrib/epee/include/misc_log_ex.h | 2 +- src/simplewallet/simplewallet.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h index 1d54b6f9..0b05d313 100644 --- a/contrib/epee/include/misc_log_ex.h +++ b/contrib/epee/include/misc_log_ex.h @@ -184,7 +184,7 @@ DISABLE_VS_WARNINGS(4100) #define LOG_PRINT_MAGENTA(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_magenta) #define LOG_PRINT_RED_L0(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_red) -#define LOG_PRINT_GREEN_L0(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_green) +#define LOG_PRINT_GREEN_L0(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_green) #define LOG_PRINT_L0(mess) LOG_PRINT(mess, LOG_LEVEL_0) #define LOG_PRINT_L1(mess) LOG_PRINT(mess, LOG_LEVEL_1) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 654ec78d..bed7e83c 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -754,7 +754,7 @@ bool print_wti(const tools::wallet_public::wallet_transfer_info& wti) remote_side += remote_side.empty() ? it : (separator + it); } - message_writer(cl) << epee::misc_utils::get_time_str_v2(wti.timestamp) << " " + success_msg_writer(cl) << "[" << wti.transfer_internal_index << "]" << epee::misc_utils::get_time_str_v2(wti.timestamp) << " " << (wti.is_income ? "Received " : "Sent ") << print_money(wti.amount) << "(fee:" << print_money(wti.fee) << ") " << remote_side @@ -768,7 +768,7 @@ bool simple_wallet::list_recent_transfers(const std::vector& args) std::vector recent; uint64_t total = 0; uint64_t last_index = 0; - m_wallet->get_recent_transfers_history(recent, 0, 0, total, last_index, false); + m_wallet->get_recent_transfers_history(recent, std::stoll(args[0]), std::stoll(args[1]), total, last_index, false); m_wallet->get_unconfirmed_transfers(unconfirmed, false); //workaround for missed fee From d387ad91124acaa01eae6f1767cadef339f99a23 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 20 Jul 2021 15:36:47 +0200 Subject: [PATCH 31/83] extended api for wallet --- src/simplewallet/simplewallet.cpp | 2 +- src/wallet/wallet2.cpp | 40 ++++++++++++++++++------- src/wallet/wallet2.h | 2 +- src/wallet/wallet_public_structs_defs.h | 6 ++++ src/wallet/wallet_rpc_server.cpp | 7 ++++- 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index bed7e83c..e83791e5 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -768,7 +768,7 @@ bool simple_wallet::list_recent_transfers(const std::vector& args) std::vector recent; uint64_t total = 0; uint64_t last_index = 0; - m_wallet->get_recent_transfers_history(recent, std::stoll(args[0]), std::stoll(args[1]), total, last_index, false); + m_wallet->get_recent_transfers_history(recent, std::stoll(args[0]), std::stoll(args[1]), total, last_index, false, false); m_wallet->get_unconfirmed_transfers(unconfirmed, false); //workaround for missed fee diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 5801d511..21e49f5d 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3192,29 +3192,49 @@ 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, uint64_t& last_item_index, bool exclude_mining_txs) + +template +bool enum_container(iterator_t it_begin, iterator_t it_end, callback_t cb) +{ + for (iterator_t it = it_begin; it != it_end; it++) + { + if (!cb(*it, it - it_begin)) + return true; + } + return true; +} +//---------------------------------------------------------------------------------------------------- +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, bool start_from_end) { if (!count || offset >= m_transfer_history.size()) return; - for (auto it = m_transfer_history.rbegin() + offset; it != m_transfer_history.rend(); it++) - { + auto cb = [&](wallet_public::wallet_transfer_info& wti, size_t local_offset) { + if (exclude_mining_txs) { - if(currency::is_coinbase(it->tx)) - continue; + if (currency::is_coinbase(wti.tx)) + return true; } - trs.push_back(*it); + trs.push_back(wti); load_wallet_transfer_info_flags(trs.back()); - last_item_index = it - m_transfer_history.rbegin(); + last_item_index = offset + local_offset; trs.back().transfer_internal_index = last_item_index; - + if (trs.size() >= count) { - break; + return false; } - } + return true; + }; + + if(start_from_end) + enum_container(m_transfer_history.rbegin() + offset, m_transfer_history.rend(), cb); + else + enum_container(m_transfer_history.begin() + offset, m_transfer_history.end(), cb); + total = m_transfer_history.size(); + } //---------------------------------------------------------------------------------------------------- bool wallet2::get_transfer_address(const std::string& adr_str, currency::account_public_address& addr, std::string& payment_id) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index b1281e08..10d79bf6 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -509,7 +509,7 @@ 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, uint64_t& last_item_index, bool exclude_mining_txs = false); + 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, bool start_from_end = true); uint64_t get_recent_transfers_total_count(); uint64_t get_transfer_entries_count(); void get_unconfirmed_transfers(std::vector& trs, bool exclude_mining_txs = false); diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 0084e418..d12d1367 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -318,6 +318,10 @@ namespace wallet_public END_KV_SERIALIZE_MAP() }; + +#define ORDER_FROM_BEGIN_TO_END "FROM_BEGIN_TO_END" +#define ORDER_FROM_FROM_END_TO_BEGIN "FROM_END_TO_BEGIN" + struct COMMAND_RPC_GET_RECENT_TXS_AND_INFO { struct request @@ -338,12 +342,14 @@ namespace wallet_public */ bool update_provision_info; bool exclude_mining_txs; + std::string order; // "FROM_BEGIN_TO_END" or "FROM_END_TO_BEGIN" BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(offset) KV_SERIALIZE(count) KV_SERIALIZE(update_provision_info) KV_SERIALIZE(exclude_mining_txs) + KV_SERIALIZE(order) END_KV_SERIALIZE_MAP() }; diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 13b9834a..fdfb6f20 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -252,7 +252,12 @@ namespace tools if (req.offset == 0) 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, res.last_item_index, req.exclude_mining_txs); + bool start_from_end = true; + if (req.order == ORDER_FROM_BEGIN_TO_END) + { + start_from_end = false; + } + m_wallet.get_recent_transfers_history(res.transfers, req.offset, req.count, res.total_transfers, res.last_item_index, req.exclude_mining_txs, start_from_end); return true; } From 17056bdf444d6d69cd89603c9db31ed5cf6614fa Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 21 Jul 2021 00:25:12 +0200 Subject: [PATCH 32/83] More options on wallet API --- src/wallet/wallet2.cpp | 17 +++++++++-------- src/wallet/wallet_public_structs_defs.h | 2 ++ src/wallet/wallet_rpc_server.cpp | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 21e49f5d..10bb0475 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -709,20 +709,21 @@ void wallet2::prepare_wti_decrypted_attachments(wallet_public::wallet_transfer_i } get_payment_id_from_tx(decrypted_att, wti.payment_id); + for (const auto& item : decrypted_att) + { + if (item.type() == typeid(currency::tx_service_attachment)) + { + wti.service_entries.push_back(boost::get(item)); + } + } + + if (wti.is_income) { account_public_address sender_address = AUTO_VAL_INIT(sender_address); wti.show_sender = handle_2_alternative_types_in_variant_container(decrypted_att, [&](const tx_payer& p) { sender_address = p.acc_addr; return false; /* <- continue? */ } ); if (wti.show_sender) wti.remote_addresses.push_back(currency::get_account_address_as_str(sender_address)); - - for (const auto& item : decrypted_att) - { - if (item.type() == typeid(currency::tx_service_attachment)) - { - wti.service_entries.push_back(boost::get(item)); - } - } } else { diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index d12d1367..960516db 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -342,6 +342,7 @@ namespace wallet_public */ bool update_provision_info; bool exclude_mining_txs; + bool exclude_unconfirmed; std::string order; // "FROM_BEGIN_TO_END" or "FROM_END_TO_BEGIN" BEGIN_KV_SERIALIZE_MAP() @@ -349,6 +350,7 @@ namespace wallet_public KV_SERIALIZE(count) KV_SERIALIZE(update_provision_info) KV_SERIALIZE(exclude_mining_txs) + KV_SERIALIZE(exclude_unconfirmed) KV_SERIALIZE(order) END_KV_SERIALIZE_MAP() }; diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index fdfb6f20..aca13701 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -249,7 +249,7 @@ namespace tools res.pi.curent_height = m_wallet.get_top_block_height(); } - if (req.offset == 0) + if (req.offset == 0 && !req.exclude_unconfirmed) m_wallet.get_unconfirmed_transfers(res.transfers, req.exclude_mining_txs); bool start_from_end = true; From b1bb1f2ac134f45f90a8b4ce18a65b949124d3b4 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 22 Jul 2021 00:44:28 +0200 Subject: [PATCH 33/83] upgraded logs --- contrib/epee/include/misc_log_ex.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h index 0b05d313..b8749cd7 100644 --- a/contrib/epee/include/misc_log_ex.h +++ b/contrib/epee/include/misc_log_ex.h @@ -141,8 +141,10 @@ DISABLE_VS_WARNINGS(4100) #define LOG_PRINT_CHANNEL_2_JORNAL(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ {TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, true, log_name);CATCH_ALL_DO_NOTHING();}} -#define LOG_ERROR2(log_name, x) { \ - TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << "[ERROR] Location: " << std::endl << LOCATION_SS << epee::misc_utils::get_callstack() << " Message:" << std::endl << x << std::endl; epee::log_space::log_singletone::do_log_message(ss________.str(), LOG_LEVEL_0, epee::log_space::console_color_red, true, log_name); LOCAL_ASSERT(0); epee::log_space::increase_error_count(LOG_DEFAULT_CHANNEL);CATCH_ALL_DO_NOTHING();} +#define LOG_ERROR2_CB(log_name, x, cb) { \ + TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << "[ERROR] Location: " << std::endl << LOCATION_SS << epee::misc_utils::get_callstack() << " Message:" << std::endl << x << std::endl; epee::log_space::log_singletone::do_log_message(ss________.str(), LOG_LEVEL_0, epee::log_space::console_color_red, true, log_name); LOCAL_ASSERT(0); epee::log_space::increase_error_count(LOG_DEFAULT_CHANNEL); cb(ss________.str()); CATCH_ALL_DO_NOTHING();} + +#define LOG_ERROR2(log_name, x) LOG_ERROR2_CB(log_name, x, epee::log_space::log_stub) #define LOG_FRAME2(log_name, x, y) epee::log_space::log_frame frame(x, y, log_name) @@ -194,6 +196,7 @@ DISABLE_VS_WARNINGS(4100) #define LOG_PRINT_J(mess, level) LOG_PRINT2_JORNAL(LOG_DEFAULT_TARGET, mess, level) #define LOG_ERROR(mess) LOG_ERROR2(LOG_DEFAULT_TARGET, mess) +#define LOG_ERROR_CB(mess, cb) LOG_ERROR2_CB(LOG_DEFAULT_TARGET, mess, cb) #define LOG_FRAME(mess, level) LOG_FRAME2(LOG_DEFAULT_TARGET, mess, level) #define LOG_VALUE(mess, level) LOG_VALUE2(LOG_DEFAULT_TARGET, mess, level) #define LOG_ARRAY(mess, level) LOG_ARRAY2(LOG_DEFAULT_TARGET, mess, level) @@ -334,7 +337,8 @@ namespace log_space /* */ /************************************************************************/ #define CONSOLE_DEFAULT_STREAM std::cout - + + inline void log_stub(const std::string& /**/) {} struct delete_ptr { From 84d4af7c18ba4a077e6a36b2e92ee75e482b95fc Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 26 Jul 2021 16:17:13 +0200 Subject: [PATCH 34/83] fixed correct auditable address --- src/wallet/wrap_service.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wrap_service.h b/src/wallet/wrap_service.h index 52b288d4..0ca52d15 100644 --- a/src/wallet/wrap_service.h +++ b/src/wallet/wrap_service.h @@ -10,4 +10,4 @@ #define BC_WRAP_SERVICE_INSTRUCTION_UNWRAP "UNWRAP" //erc20 unwrap operation -#define BC_WRAP_SERVICE_CUSTODY_WALLET "aZxbJPXzkjCJDpGEVvkMir9B4fRKPo73r2e5D7nLHuVgEBXXQYc2Tk2hHroxVwiCDLDHZu215pgNocUsrchH4HHzWbHzL4nMfPq" \ No newline at end of file +#define BC_WRAP_SERVICE_CUSTODY_WALLET "aZxaszi4TaDCUqRCmqe23HASryshQNHmBSFnUN1pY8VsRfss2ZSMGBpLhdFtHgKmFr353NneaYRT6CpSz7zA3EC9bocQcq7m9nP" \ No newline at end of file From 4c01aec842911b069551e9b9c58d3c37e757814b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 27 Jul 2021 22:45:06 +0200 Subject: [PATCH 35/83] fixed bug in list_recent_transfers --- src/simplewallet/simplewallet.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index e83791e5..c72242d3 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -192,7 +192,7 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("balance", boost::bind(&simple_wallet::show_balance, this, _1), "Show current wallet balance"); m_cmd_binder.set_handler("incoming_transfers", boost::bind(&simple_wallet::show_incoming_transfers, this, _1), "incoming_transfers [available|unavailable] - Show incoming transfers - all of them or filter them by availability"); m_cmd_binder.set_handler("incoming_counts", boost::bind(&simple_wallet::show_incoming_transfers_counts, this, _1), "incoming_transfers counts"); - m_cmd_binder.set_handler("list_recent_transfers", boost::bind(&simple_wallet::list_recent_transfers, this, _1), "list_recent_transfers - Show recent maximum 1000 transfers"); + m_cmd_binder.set_handler("list_recent_transfers", boost::bind(&simple_wallet::list_recent_transfers, this, _1), "list_recent_transfers [offset] [count] - Show recent maximum 1000 transfers, offset default = 0, count default = 100 "); m_cmd_binder.set_handler("export_recent_transfers", boost::bind(&simple_wallet::export_recent_transfers, this, _1), "list_recent_transfers_tx - Write recent transfer in json to wallet_recent_transfers.txt"); m_cmd_binder.set_handler("list_outputs", boost::bind(&simple_wallet::list_outputs, this, _1), "list_outputs [spent|unspent] - Lists all the outputs that have ever been sent to this wallet if called without arguments, otherwise it lists only the spent or unspent outputs"); m_cmd_binder.set_handler("dump_transfers", boost::bind(&simple_wallet::dump_trunsfers, this, _1), "dump_transfers - Write transfers in json to dump_transfers.txt"); @@ -766,9 +766,15 @@ bool simple_wallet::list_recent_transfers(const std::vector& args) { std::vector unconfirmed; std::vector recent; + uint64_t offset = 0; + if (args.size() > 0) + offset = std::stoll(args[0]); + uint64_t count = 1000; + if (args.size() > 1) + count = std::stoll(args[1]); uint64_t total = 0; uint64_t last_index = 0; - m_wallet->get_recent_transfers_history(recent, std::stoll(args[0]), std::stoll(args[1]), total, last_index, false, false); + m_wallet->get_recent_transfers_history(recent, offset, count, total, last_index, false, false); m_wallet->get_unconfirmed_transfers(unconfirmed, false); //workaround for missed fee From da7756c73aa2544455e438a8ce7ea8c697b5bf23 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 29 Jul 2021 22:32:46 +0200 Subject: [PATCH 36/83] improved json rpc lib and logging lib --- contrib/epee/include/misc_log_ex.h | 36 +++++++++++++------ .../include/storages/http_abstract_invoke.h | 21 ++++++++++- tests/performance_tests/main.cpp | 12 +++++++ 3 files changed, 57 insertions(+), 12 deletions(-) diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h index b8749cd7..d7599ed2 100644 --- a/contrib/epee/include/misc_log_ex.h +++ b/contrib/epee/include/misc_log_ex.h @@ -132,11 +132,11 @@ DISABLE_VS_WARNINGS(4100) #define LOG_PRINT_CHANNEL_NO_POSTFIX2(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ {TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x; epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);CATCH_ALL_DO_NOTHING();}} -#define LOG_PRINT_CHANNEL2(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ - {TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);CATCH_ALL_DO_NOTHING();}} +#define LOG_PRINT_CHANNEL2_CB(log_channel, log_name, x, y, cb) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ + {TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);cb(ss________.str());CATCH_ALL_DO_NOTHING();}} -#define LOG_PRINT_CHANNEL_COLOR2(log_channel, log_name, x, y, color) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ - {TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, color, false, log_name);CATCH_ALL_DO_NOTHING();}} +#define LOG_PRINT_CHANNEL_COLOR2_CB(log_channel, log_name, x, y, color, cb) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ + {TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, color, false, log_name); cb(ss________.str());CATCH_ALL_DO_NOTHING();}} #define LOG_PRINT_CHANNEL_2_JORNAL(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ {TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, true, log_name);CATCH_ALL_DO_NOTHING();}} @@ -145,6 +145,8 @@ DISABLE_VS_WARNINGS(4100) TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << "[ERROR] Location: " << std::endl << LOCATION_SS << epee::misc_utils::get_callstack() << " Message:" << std::endl << x << std::endl; epee::log_space::log_singletone::do_log_message(ss________.str(), LOG_LEVEL_0, epee::log_space::console_color_red, true, log_name); LOCAL_ASSERT(0); epee::log_space::increase_error_count(LOG_DEFAULT_CHANNEL); cb(ss________.str()); CATCH_ALL_DO_NOTHING();} #define LOG_ERROR2(log_name, x) LOG_ERROR2_CB(log_name, x, epee::log_space::log_stub) +#define LOG_PRINT_CHANNEL2(log_channel, log_name, x, y) LOG_PRINT_CHANNEL2_CB(log_channel, log_name, x, y, epee::log_space::log_stub) +#define LOG_PRINT_CHANNEL_COLOR2(log_channel, log_name, x, y, color) LOG_PRINT_CHANNEL_COLOR2_CB(log_channel, log_name, x, y, color, epee::log_space::log_stub) #define LOG_FRAME2(log_name, x, y) epee::log_space::log_frame frame(x, y, log_name) @@ -165,7 +167,9 @@ DISABLE_VS_WARNINGS(4100) #define LOG_PRINT_NO_PREFIX_NO_POSTFIX2(log_name, x, y) LOG_PRINT_CHANNEL_NO_PREFIX_NO_POSTFIX2(LOG_DEFAULT_CHANNEL, log_name, x, y) #define LOG_PRINT_NO_POSTFIX2(log_name, x, y) LOG_PRINT_CHANNEL_NO_POSTFIX2(LOG_DEFAULT_CHANNEL, log_name, x, y) #define LOG_PRINT2(log_name, x, y) LOG_PRINT_CHANNEL2(LOG_DEFAULT_CHANNEL, log_name, x, y) +#define LOG_PRINT2_CB(log_name, x, y, cb) LOG_PRINT_CHANNEL2_CB(LOG_DEFAULT_CHANNEL, log_name, x, y, cb) #define LOG_PRINT_COLOR2(log_name, x, y, color) LOG_PRINT_CHANNEL_COLOR2(LOG_DEFAULT_CHANNEL, log_name, x, y, color) +#define LOG_PRINT_COLOR2_CB(log_name, x, y, color, cb) LOG_PRINT_CHANNEL_COLOR2_CB(LOG_DEFAULT_CHANNEL, log_name, x, y, color, cb) #define LOG_PRINT2_JORNAL(log_name, x, y) LOG_PRINT_CHANNEL_2_JORNAL(LOG_DEFAULT_CHANNEL, log_name, x, y) #ifndef LOG_DEFAULT_TARGET @@ -175,15 +179,25 @@ DISABLE_VS_WARNINGS(4100) #define LOG_PRINT_NO_POSTFIX(mess, level) LOG_PRINT_NO_POSTFIX2(LOG_DEFAULT_TARGET, mess, level) #define LOG_PRINT_NO_PREFIX(mess, level) LOG_PRINT_NO_PREFIX2(LOG_DEFAULT_TARGET, mess, level) #define LOG_PRINT_NO_PREFIX_NO_POSTFIX(mess, level) LOG_PRINT_NO_PREFIX_NO_POSTFIX2(LOG_DEFAULT_TARGET, mess, level) -#define LOG_PRINT(mess, level) LOG_PRINT2(LOG_DEFAULT_TARGET, mess, level) +#define LOG_PRINT(mess, level) LOG_PRINT2(LOG_DEFAULT_TARGET, mess, level) +#define LOG_PRINT_CB(mess, level, cb) LOG_PRINT2_CB(LOG_DEFAULT_TARGET, mess, level, cb) +#define LOG_PRINT_COLOR_CB(mess, level, color, cb) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, color, cb) + +#define LOG_COLOR_RED epee::log_space::console_color_red +#define LOG_COLOR_GREEN epee::log_space::console_color_green +#define LOG_COLOR_BLUE epee::log_space::console_color_blue +#define LOG_COLOR_YELLOW epee::log_space::console_color_yellow +#define LOG_COLOR_CYAN epee::log_space::console_color_cyan +#define LOG_COLOR_MAGENTA epee::log_space::console_color_magenta + #define LOG_PRINT_COLOR(mess, level, color) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, color) -#define LOG_PRINT_RED(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_red) -#define LOG_PRINT_GREEN(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_green) -#define LOG_PRINT_BLUE(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_blue) -#define LOG_PRINT_YELLOW(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_yellow) -#define LOG_PRINT_CYAN(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_cyan) -#define LOG_PRINT_MAGENTA(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_magenta) +#define LOG_PRINT_RED(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, LOG_COLOR_RED) +#define LOG_PRINT_GREEN(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, LOG_COLOR_GREEN) +#define LOG_PRINT_BLUE(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, LOG_COLOR_BLUE) +#define LOG_PRINT_YELLOW(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, LOG_COLOR_YELLOW) +#define LOG_PRINT_CYAN(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, LOG_COLOR_CYAN) +#define LOG_PRINT_MAGENTA(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, ) #define LOG_PRINT_RED_L0(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_red) #define LOG_PRINT_GREEN_L0(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_green) diff --git a/contrib/epee/include/storages/http_abstract_invoke.h b/contrib/epee/include/storages/http_abstract_invoke.h index 5305c543..0b6ef8e3 100644 --- a/contrib/epee/include/storages/http_abstract_invoke.h +++ b/contrib/epee/include/storages/http_abstract_invoke.h @@ -94,9 +94,28 @@ namespace epee return serialization::load_t_from_binary(result_struct, pri->m_body); } + + template + bool invoke_http_json_rpc(const std::string& url, const std::string& method_name, const t_request& out_struct, t_response& result_struct, t_transport& transport, epee::json_rpc::error& err, unsigned int timeout = 5000, const std::string& http_method = "GET", const std::string& req_id = "0") + { + epee::json_rpc::request req_t = AUTO_VAL_INIT(req_t); + req_t.jsonrpc = "2.0"; + req_t.id = req_id; + req_t.method = method_name; + req_t.params = out_struct; + epee::json_rpc::response resp_t = AUTO_VAL_INIT(resp_t); + if (!epee::net_utils::invoke_http_json_remote_command2(url, req_t, resp_t, transport, timeout, http_method)) + { + return false; + } + err = resp_t.error; + result_struct = resp_t.result; + return true; + } + template bool invoke_http_json_rpc(const std::string& url, const std::string& method_name, const t_request& out_struct, t_response& result_struct, t_transport& transport, unsigned int timeout = 5000, const std::string& http_method = "GET", const std::string& req_id = "0") - { + { epee::json_rpc::request req_t = AUTO_VAL_INIT(req_t); req_t.jsonrpc = "2.0"; req_t.id = req_id; diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index df60b58e..c3f0a77a 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -33,8 +33,20 @@ int main(int argc, char** argv) epee::log_space::log_singletone::get_default_log_file().c_str(), epee::log_space::log_singletone::get_default_log_folder().c_str()); + + std::string buf1 = tools::get_varint_data(CURRENCY_PUBLIC_ADDRESS_BASE58_PREFIX); + std::string buf2 = tools::get_varint_data(CURRENCY_PUBLIC_INTEG_ADDRESS_BASE58_PREFIX); + std::string buf3 = tools::get_varint_data(CURRENCY_PUBLIC_INTEG_ADDRESS_V2_BASE58_PREFIX); + std::string buf4 = tools::get_varint_data(CURRENCY_PUBLIC_AUDITABLE_ADDRESS_BASE58_PREFIX); + std::string buf5 = tools::get_varint_data(CURRENCY_PUBLIC_AUDITABLE_INTEG_ADDRESS_BASE58_PREFIX); + std::cout << "Buf1: " << epee::string_tools::buff_to_hex_nodelimer(buf1) << ENDL; + std::cout << "Buf2: " << epee::string_tools::buff_to_hex_nodelimer(buf2) << ENDL; + std::cout << "Buf3: " << epee::string_tools::buff_to_hex_nodelimer(buf3) << ENDL; + std::cout << "Buf4: " << epee::string_tools::buff_to_hex_nodelimer(buf4) << ENDL; + std::cout << "Buf5: " << epee::string_tools::buff_to_hex_nodelimer(buf5) << ENDL; + do_htlc_hash_tests(); //run_serialization_performance_test(); //return 1; From 8d4f032d05f54a58273514406fdb8570323b4274 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 29 Jul 2021 22:35:36 +0200 Subject: [PATCH 37/83] forgoten magenta --- contrib/epee/include/misc_log_ex.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h index d7599ed2..64c2973d 100644 --- a/contrib/epee/include/misc_log_ex.h +++ b/contrib/epee/include/misc_log_ex.h @@ -197,7 +197,7 @@ DISABLE_VS_WARNINGS(4100) #define LOG_PRINT_BLUE(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, LOG_COLOR_BLUE) #define LOG_PRINT_YELLOW(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, LOG_COLOR_YELLOW) #define LOG_PRINT_CYAN(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, LOG_COLOR_CYAN) -#define LOG_PRINT_MAGENTA(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, ) +#define LOG_PRINT_MAGENTA(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, LOG_COLOR_MAGENTA) #define LOG_PRINT_RED_L0(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_red) #define LOG_PRINT_GREEN_L0(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_green) From bf43b41bddc5a9382769b8e748cda11ed9d6b046 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 29 Jul 2021 22:40:42 +0200 Subject: [PATCH 38/83] forgoten LOG_PRINT_COLOR2_CB --- contrib/epee/include/misc_log_ex.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h index 64c2973d..0b957a5f 100644 --- a/contrib/epee/include/misc_log_ex.h +++ b/contrib/epee/include/misc_log_ex.h @@ -182,7 +182,7 @@ DISABLE_VS_WARNINGS(4100) #define LOG_PRINT(mess, level) LOG_PRINT2(LOG_DEFAULT_TARGET, mess, level) #define LOG_PRINT_CB(mess, level, cb) LOG_PRINT2_CB(LOG_DEFAULT_TARGET, mess, level, cb) -#define LOG_PRINT_COLOR_CB(mess, level, color, cb) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, color, cb) +#define LOG_PRINT_COLOR_CB(mess, level, color, cb) LOG_PRINT_COLOR2_CB(LOG_DEFAULT_TARGET, mess, level, color, cb) #define LOG_COLOR_RED epee::log_space::console_color_red #define LOG_COLOR_GREEN epee::log_space::console_color_green From 0d3682efdfda283509b66161c1f5c202c06e8aef Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 7 Aug 2021 22:01:00 +0200 Subject: [PATCH 39/83] address validation for wrap --- src/wallet/wallets_manager.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index eb101997..0d3c9f6b 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1753,7 +1753,11 @@ std::string wallets_manager::get_offers_ex(const bc_services::core_offers_filter std::string wallets_manager::validate_address(const std::string& addr_str, std::string& payment_id) { currency::account_public_address acc = AUTO_VAL_INIT(acc); - if (currency::get_account_address_and_payment_id_from_str(acc, payment_id, addr_str)) + if (is_address_like_wrapped(addr_str)) + { + return API_RETURN_CODE_TRUE; + } + else if (currency::get_account_address_and_payment_id_from_str(acc, payment_id, addr_str)) return API_RETURN_CODE_TRUE; else return API_RETURN_CODE_FALSE; From 0f40aba1e690bd02fd03c02476a68254bedf9860 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 7 Aug 2021 22:16:12 +0200 Subject: [PATCH 40/83] fixed missing namespace --- src/wallet/wallets_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 0d3c9f6b..4dbba747 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1753,7 +1753,7 @@ std::string wallets_manager::get_offers_ex(const bc_services::core_offers_filter std::string wallets_manager::validate_address(const std::string& addr_str, std::string& payment_id) { currency::account_public_address acc = AUTO_VAL_INIT(acc); - if (is_address_like_wrapped(addr_str)) + if (currency::is_address_like_wrapped(addr_str)) { return API_RETURN_CODE_TRUE; } From abb9bb62804aaaf7fbab9b274d0399846d8b29b4 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 17 Aug 2021 12:12:20 +0200 Subject: [PATCH 41/83] added wrap address support in mobile wallet --- src/wallet/plain_wallet_api.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 4b8a8fd6..b2f31850 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -367,15 +367,30 @@ namespace plain_wallet currency::account_public_address apa = AUTO_VAL_INIT(apa); currency::payment_id_t pid = AUTO_VAL_INIT(pid); bool valid = false; - if(currency::get_account_address_and_payment_id_from_str(apa, pid, addr)) + bool wrap = false; + while (true) { - valid = true; + if (currency::is_address_like_wrapped(addr)) + { + wrap = true; + valid = true; + break; + } + + if (currency::get_account_address_and_payment_id_from_str(apa, pid, addr)) + { + valid = true; + } + break; } + //lazy to make struct for it std::stringstream res; res << "{ \"valid\": " << (valid?"true":"false") << ", \"auditable\": " << (apa.is_auditable() ? "true" : "false") - << ",\"payment_id\": " << (pid.size() ? "true" : "false") << "}"; + << ",\"payment_id\": " << (pid.size() ? "true" : "false") + << ",\"wrap\": " << (wrap ? "true" : "false") + << "}"; return res.str(); } From 13e59ffafbe83dc70c2cd7df16db6b951e8b797e Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 24 Jun 2021 00:57:38 +0200 Subject: [PATCH 42/83] implemented basic suppoer of wrapping in wallet(service commands) + inital support in simplewallet --- src/currency_core/currency_basic.h | 10 ++- src/currency_core/currency_format_utils.cpp | 90 ++++++++++++++++++--- src/currency_core/currency_format_utils.h | 1 + src/simplewallet/simplewallet.cpp | 32 +++++++- src/wallet/wrap_service.h | 12 +++ 5 files changed, 129 insertions(+), 16 deletions(-) create mode 100644 src/wallet/wrap_service.h diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index 274a2f25..29aa7483 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -386,8 +386,14 @@ namespace currency }; // applicable flags for tx_service_attachment::flags, can be combined using bitwise OR -#define TX_SERVICE_ATTACHMENT_ENCRYPT_BODY static_cast(1 << 0) -#define TX_SERVICE_ATTACHMENT_DEFLATE_BODY static_cast(1 << 1) +#define TX_SERVICE_ATTACHMENT_ENCRYPT_BODY static_cast(1 << 0) +#define TX_SERVICE_ATTACHMENT_DEFLATE_BODY static_cast(1 << 1) + +// with this flag enabled body encrypted/decrypted with the key created as a derivation from onetime key and "spend keys" of receiver +#define TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE static_cast(1 << 2) +// add proof of content, without revealing secrete +#define TX_SERVICE_ATTACHMENT_ENCRYPT_ADD_PROOF static_cast(1 << 3) + //, diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 7c014f2a..0d877864 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -759,8 +759,12 @@ namespace currency struct encrypt_attach_visitor : public boost::static_visitor { bool& m_was_crypted_entries; + const keypair& m_onetime_keypair; + const account_public_address& m_destination_addr; const crypto::key_derivation& m_key; - encrypt_attach_visitor(bool& was_crypted_entries, const crypto::key_derivation& key) :m_was_crypted_entries(was_crypted_entries), m_key(key) + + encrypt_attach_visitor(bool& was_crypted_entries, const crypto::key_derivation& key, const keypair& onetime_keypair = keypair(), const account_public_address& destination_addr = account_public_address()) : + m_was_crypted_entries(was_crypted_entries), m_key(key), m_onetime_keypair(onetime_keypair), m_destination_addr(m_destination_addr) {} void operator()(tx_comment& comment) { @@ -789,6 +793,7 @@ namespace currency } void operator()(tx_service_attachment& sa) { + const std::string orignal_body = sa.body; if (sa.flags&TX_SERVICE_ATTACHMENT_DEFLATE_BODY) { zlib_helper::pack(sa.body); @@ -796,7 +801,27 @@ namespace currency if (sa.flags&TX_SERVICE_ATTACHMENT_ENCRYPT_BODY) { - crypto::chacha_crypt(sa.body, m_key); + crypto::key_derivation derivation_local = m_key; + if (sa.flags&TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE) + { + CHECK_AND_ASSERT_THROW_MES(m_destination_addr.spend_public_key != currency::null_pkey && m_onetime_keypair.sec != currency::null_skey, "tx_service_attachment with TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE: keys uninitialized"); + //encrypt with "spend keys" only, to prevent auditable watchers decrypt it + bool r = crypto::generate_key_derivation(m_destination_addr.spend_public_key, m_onetime_keypair.sec, derivation_local); + crypto::chacha_crypt(sa.body, derivation_local); + } + else + { + crypto::chacha_crypt(sa.body, derivation_local); + } + if (sa.flags&TX_SERVICE_ATTACHMENT_ENCRYPT_ADD_PROOF) + { + //take hash from derivation and use it as a salt + crypto::hash derivation_hash = crypto::cn_fast_hash(&derivation_local, sizeof(derivation_local)); + std::string salted_body = orignal_body; + string_tools::apped_pod_to_strbuff(salted_body, derivation_hash); + crypto::hash proof_hash = crypto::cn_fast_hash(salted_body.data(), salted_body.size()); + sa.security.push_back(*(crypto::public_key*)&proof_hash); + } m_was_crypted_entries = true; } } @@ -808,12 +833,18 @@ namespace currency struct decrypt_attach_visitor : public boost::static_visitor { + const account_keys& m_acc_keys; + const crypto::public_key& m_tx_onetime_pubkey; const crypto::key_derivation& rkey; std::vector& rdecrypted_att; decrypt_attach_visitor(const crypto::key_derivation& key, - std::vector& decrypted_att) : + std::vector& decrypted_att, + const account_keys& acc_keys = account_keys(), + const crypto::public_key& tx_onetime_pubkey = crypto::public_key()) : rkey(key), - rdecrypted_att(decrypted_att) + rdecrypted_att(decrypted_att), + m_acc_keys(acc_keys), + m_tx_onetime_pubkey(tx_onetime_pubkey) {} void operator()(const tx_comment& comment) { @@ -825,15 +856,44 @@ namespace currency void operator()(const tx_service_attachment& sa) { tx_service_attachment local_sa = sa; + crypto::key_derivation derivation_local = rkey; if (sa.flags&TX_SERVICE_ATTACHMENT_ENCRYPT_BODY) { - crypto::chacha_crypt(local_sa.body, rkey); + if (sa.flags&TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE) + { + if (m_acc_keys.spend_secret_key == null_skey) + { + //this watch only wallet, decrypting supposed to be impossible + return; + } + CHECK_AND_ASSERT_THROW_MES(m_acc_keys.spend_secret_key != currency::null_skey, "tx_service_attachment with TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE: keys uninitialized"); + bool r = crypto::generate_key_derivation(m_tx_onetime_pubkey, m_acc_keys.spend_secret_key, derivation_local); + CHECK_AND_ASSERT_THROW_MES(r, "Failed to generate_key_derivation at TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE"); + crypto::chacha_crypt(sa.body, derivation_local); + + } + else + { + crypto::chacha_crypt(local_sa.body, derivation_local); + } } if (sa.flags&TX_SERVICE_ATTACHMENT_DEFLATE_BODY) { zlib_helper::unpack(local_sa.body); } + + if (sa.flags&TX_SERVICE_ATTACHMENT_ENCRYPT_BODY && sa.flags&TX_SERVICE_ATTACHMENT_ENCRYPT_ADD_PROOF) + { + CHECK_AND_ASSERT_MES(sa.security.size() == 1, void(), "Unexpected key in tx_service_attachment with TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE"); + //take hash from derivation and use it as a salt + crypto::hash derivation_hash = crypto::cn_fast_hash(&derivation_local, sizeof(derivation_local)); + std::string salted_body = local_sa.body; + string_tools::apped_pod_to_strbuff(salted_body, derivation_hash); + crypto::hash proof_hash = crypto::cn_fast_hash(salted_body.data(), salted_body.size()); + CHECK_AND_ASSERT_MES(*(crypto::public_key*)&proof_hash == sa.security.front(), void(), "Proof hash missmatch on decrypting with TX_SERVICE_ATTACHMENT_ENCRYPT_ADD_PROOF"); + } + rdecrypted_att.push_back(local_sa); } @@ -870,9 +930,10 @@ namespace currency //--------------------------------------------------------------- template - bool decrypt_payload_items(const crypto::key_derivation& derivation, const items_container_t& items_to_decrypt, std::vector& decrypted_att) + bool decrypt_payload_items(const crypto::key_derivation& derivation, const items_container_t& items_to_decrypt, std::vector& decrypted_att, const account_keys& acc_keys = account_keys(), + const crypto::public_key& tx_onetime_pubkey = crypto::public_key()) { - decrypt_attach_visitor v(derivation, decrypted_att); + decrypt_attach_visitor v(derivation, decrypted_att, acc_keys, tx_onetime_pubkey); for (auto& a : items_to_decrypt) boost::apply_visitor(v, a); @@ -955,8 +1016,8 @@ namespace currency return true; } - decrypt_payload_items(derivation, tx.extra, decrypted_items); - decrypt_payload_items(derivation, tx.attachment, decrypted_items); + decrypt_payload_items(derivation, tx.extra, decrypted_items, acc_keys, get_tx_pub_key_from_extra(tx)); + decrypt_payload_items(derivation, tx.attachment, decrypted_items, acc_keys, get_tx_pub_key_from_extra(tx)); return true; } @@ -969,11 +1030,11 @@ namespace currency bool was_attachment_crypted_entries = false; bool was_extra_crypted_entries = false; - encrypt_attach_visitor v(was_attachment_crypted_entries, derivation); + encrypt_attach_visitor v(was_attachment_crypted_entries, derivation, tx_random_key, destination_addr); for (auto& a : tx.attachment) boost::apply_visitor(v, a); - encrypt_attach_visitor v2(was_extra_crypted_entries, derivation); + encrypt_attach_visitor v2(was_extra_crypted_entries, derivation, tx_random_key, destination_addr); for (auto& a : tx.extra) boost::apply_visitor(v2, a); @@ -2888,6 +2949,13 @@ namespace currency return tools::base58::encode_addr(CURRENCY_PUBLIC_ADDRESS_BASE58_PREFIX, t_serializable_object_to_blob(addr)); // new format Zano address (normal) } //----------------------------------------------------------------------- + bool is_address_looks_like_wrapped(const std::string& addr) + { + if (addr.length() == 42 && addr.substr(0, 2) == "0x") + return true; + else return false; + } + //----------------------------------------------------------------------- std::string get_account_address_and_payment_id_as_str(const account_public_address& addr, const payment_id_t& payment_id) { if (addr.flags == 0) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 6474307d..86952896 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -289,6 +289,7 @@ namespace currency bool decrypt_payload_items(bool is_income, const transaction& tx, const account_keys& acc_keys, std::vector& decrypted_items); void encrypt_attachments(transaction& tx, const account_keys& sender_keys, const account_public_address& destination_addr, const keypair& tx_random_key); bool is_derivation_used_to_encrypt(const transaction& tx, const crypto::key_derivation& derivation); + bool is_address_looks_like_wrapped(const std::string& addr); void load_wallet_transfer_info_flags(tools::wallet_public::wallet_transfer_info& x); uint64_t get_tx_type(const transaction& tx); uint64_t get_tx_type_ex(const transaction& tx, tx_out& htlc_out, txin_htlc& htlc_in); diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 8656eb2c..3517e318 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -20,6 +20,7 @@ #include "wallet/wallet_rpc_server.h" #include "version.h" #include "string_coding.h" +#include "wallet/wrap_service.h" #include @@ -1208,13 +1209,32 @@ bool simple_wallet::transfer(const std::vector &args_) return true; } + std::vector extra; vector dsts; + bool wrapped_transaction = false; for (size_t i = 0; i < local_args.size(); i += 2) { std::string integrated_payment_id; currency::tx_destination_entry de; de.addr.resize(1); - if(!(de.addr.size() == 1 && m_wallet->get_transfer_address(local_args[i], de.addr.front(), integrated_payment_id))) + //check if address looks like wrapped address + if (is_address_looks_like_wrapped(local_args[i])) + { + success_msg_writer(true) << "Address " << local_args[i] << " recognized as wrapped address, creating wrapping transaction..."; + //put into service attachment specially encrypted entry which will contain wrap address and network + tx_service_attachment sa = AUTO_VAL_INIT(sa); + sa.service_id = BC_WRAP_SERVICE_ID; + sa.instruction = BC_WRAP_SERVICE_INSTRUCTION_ERC20; + sa.flags = TX_SERVICE_ATTACHMENT_ENCRYPT_BODY | TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE; + sa.body = local_args[i]; + extra.push_back(sa); + + currency::account_public_address acc = AUTO_VAL_INIT(acc); + currency::get_account_address_from_str(acc, BC_WRAP_SERVICE_CUSTODY_WALLET); + de.addr.front() = acc; + wrapped_transaction = true; + //encrypt body with a special way + }else if(!(de.addr.size() == 1 && m_wallet->get_transfer_address(local_args[i], de.addr.front(), integrated_payment_id))) { fail_msg_writer() << "wrong address: " << local_args[i]; return true; @@ -1258,13 +1278,19 @@ bool simple_wallet::transfer(const std::vector &args_) try { currency::transaction tx; - std::vector extra; m_wallet->transfer(dsts, fake_outs_count, 0, m_wallet->get_core_runtime_config().tx_default_fee, extra, attachments, tx); if (!m_wallet->is_watch_only()) - success_msg_writer(true) << "Money successfully sent, transaction " << get_transaction_hash(tx) << ", " << get_object_blobsize(tx) << " bytes"; + { + if(wrapped_transaction) + success_msg_writer(true) << "Money successfully sent to wZano custody wallet, transaction " << get_transaction_hash(tx) << ", " << get_object_blobsize(tx) << " bytes"; + else + success_msg_writer(true) << "Money successfully sent, transaction " << get_transaction_hash(tx) << ", " << get_object_blobsize(tx) << " bytes"; + } else + { success_msg_writer(true) << "Transaction prepared for signing and saved into \"zano_tx_unsigned\" file, use full wallet to sign transfer and then use \"submit_transfer\" on this wallet to broadcast the transaction to the network"; + } } catch (const tools::error::daemon_busy&) { diff --git a/src/wallet/wrap_service.h b/src/wallet/wrap_service.h new file mode 100644 index 00000000..852d60d7 --- /dev/null +++ b/src/wallet/wrap_service.h @@ -0,0 +1,12 @@ +// Copyright (c) 2014-2018 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#pragma once + +#define BC_WRAP_SERVICE_ID "W" + +#define BC_WRAP_SERVICE_INSTRUCTION_ERC20 "ERC20" //erc20 wrapped operation + + +#define BC_WRAP_SERVICE_CUSTODY_WALLET "aZxbJPXzkjCJDpGEVvkMir9B4fRKPo73r2e5D7nLHuVgEBXXQYc2Tk2hHroxVwiCDLDHZu215pgNocUsrchH4HHzWbHzL4nMfPq" \ No newline at end of file From 42712aa8d72f498873290c1e66203d3b3881c6af Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 24 Jun 2021 20:34:13 +0200 Subject: [PATCH 43/83] fixed default initialization for decrypt/encrypt visitors --- src/currency_core/account.h | 1 + src/currency_core/currency_basic.h | 1 + src/currency_core/currency_format_utils.cpp | 13 +++++++------ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/currency_core/account.h b/src/currency_core/account.h index 305b02e3..e9674307 100644 --- a/src/currency_core/account.h +++ b/src/currency_core/account.h @@ -97,6 +97,7 @@ namespace currency std::vector m_keys_seed_binary; }; + const static account_keys null_acc_keys = AUTO_VAL_INIT(null_acc_keys); std::string transform_addr_to_str(const account_public_address& addr); account_public_address transform_str_to_addr(const std::string& str); diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index 29aa7483..1193bd8a 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -696,6 +696,7 @@ namespace currency return k; } }; + const static keypair null_keypair = AUTO_VAL_INIT(null_keypair); //--------------------------------------------------------------- //PoS //based from ppcoin/novacoin approach diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 0d877864..4e5d717d 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -763,7 +763,7 @@ namespace currency const account_public_address& m_destination_addr; const crypto::key_derivation& m_key; - encrypt_attach_visitor(bool& was_crypted_entries, const crypto::key_derivation& key, const keypair& onetime_keypair = keypair(), const account_public_address& destination_addr = account_public_address()) : + encrypt_attach_visitor(bool& was_crypted_entries, const crypto::key_derivation& key, const keypair& onetime_keypair = null_keypair, const account_public_address& destination_addr = null_pub_addr) : m_was_crypted_entries(was_crypted_entries), m_key(key), m_onetime_keypair(onetime_keypair), m_destination_addr(m_destination_addr) {} void operator()(tx_comment& comment) @@ -807,6 +807,7 @@ namespace currency CHECK_AND_ASSERT_THROW_MES(m_destination_addr.spend_public_key != currency::null_pkey && m_onetime_keypair.sec != currency::null_skey, "tx_service_attachment with TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE: keys uninitialized"); //encrypt with "spend keys" only, to prevent auditable watchers decrypt it bool r = crypto::generate_key_derivation(m_destination_addr.spend_public_key, m_onetime_keypair.sec, derivation_local); + CHECK_AND_ASSERT_THROW_MES(r, "tx_service_attachment with TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE: Failed to make derivation"); crypto::chacha_crypt(sa.body, derivation_local); } else @@ -839,8 +840,8 @@ namespace currency std::vector& rdecrypted_att; decrypt_attach_visitor(const crypto::key_derivation& key, std::vector& decrypted_att, - const account_keys& acc_keys = account_keys(), - const crypto::public_key& tx_onetime_pubkey = crypto::public_key()) : + const account_keys& acc_keys = null_acc_keys, + const crypto::public_key& tx_onetime_pubkey = null_pkey) : rkey(key), rdecrypted_att(decrypted_att), m_acc_keys(acc_keys), @@ -866,7 +867,7 @@ namespace currency //this watch only wallet, decrypting supposed to be impossible return; } - CHECK_AND_ASSERT_THROW_MES(m_acc_keys.spend_secret_key != currency::null_skey, "tx_service_attachment with TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE: keys uninitialized"); + CHECK_AND_ASSERT_THROW_MES(m_acc_keys.spend_secret_key != currency::null_skey && m_tx_onetime_pubkey != currency::null_pkey, "tx_service_attachment with TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE: keys uninitialized"); bool r = crypto::generate_key_derivation(m_tx_onetime_pubkey, m_acc_keys.spend_secret_key, derivation_local); CHECK_AND_ASSERT_THROW_MES(r, "Failed to generate_key_derivation at TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE"); crypto::chacha_crypt(sa.body, derivation_local); @@ -930,8 +931,8 @@ namespace currency //--------------------------------------------------------------- template - bool decrypt_payload_items(const crypto::key_derivation& derivation, const items_container_t& items_to_decrypt, std::vector& decrypted_att, const account_keys& acc_keys = account_keys(), - const crypto::public_key& tx_onetime_pubkey = crypto::public_key()) + bool decrypt_payload_items(const crypto::key_derivation& derivation, const items_container_t& items_to_decrypt, std::vector& decrypted_att, const account_keys& acc_keys = null_acc_keys, + const crypto::public_key& tx_onetime_pubkey = null_pkey) { decrypt_attach_visitor v(derivation, decrypted_att, acc_keys, tx_onetime_pubkey); for (auto& a : items_to_decrypt) From faa956a95927e25a2d72921c94163e2e12b1e602 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 24 Jun 2021 22:10:09 +0200 Subject: [PATCH 44/83] added isolated items to rpc-structures --- src/wallet/wallet2.cpp | 13 +++++++++---- src/wallet/wallet2.h | 8 +++++--- src/wallet/wallet_public_structs_defs.h | 16 +++++++++++++++- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index d0456a00..b6c054a8 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -715,6 +715,11 @@ void wallet2::prepare_wti_decrypted_attachments(wallet_public::wallet_transfer_i wti.show_sender = handle_2_alternative_types_in_variant_container(decrypted_att, [&](const tx_payer& p) { sender_address = p.acc_addr; return false; /* <- continue? */ } ); if (wti.show_sender) wti.remote_addresses.push_back(currency::get_account_address_as_str(sender_address)); + + for (const auto& item : decrypted_att) + { + wti.service_entries.push_back(item); + } } else { @@ -1238,7 +1243,7 @@ void wallet2::prepare_wti(wallet_public::wallet_transfer_info& wti, uint64_t hei wti.tx_blob_size = static_cast(currency::get_object_blobsize(wti.tx)); wti.tx_hash = currency::get_transaction_hash(tx); load_wallet_transfer_info_flags(wti); - bc_services::extract_market_instructions(wti.srv_attachments, tx.attachment); + bc_services::extract_market_instructions(wti.marketplace_entries, tx.attachment); // escrow transactions, which are built with TX_FLAG_SIGNATURE_MODE_SEPARATE flag actually encrypt attachments // with buyer as a sender, and seller as receiver, despite the fact that for both sides transaction seen as outgoing @@ -4570,7 +4575,7 @@ bool wallet2::extract_offers_from_transfer_entry(size_t i, std::unordered_map diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index afcddc49..d9edd8ab 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -87,6 +87,17 @@ namespace wallet_public #define WALLET_TRANSFER_INFO_FLAGS_HTLC_DEPOSIT static_cast(1 << 0) + struct tx_service_attachment_kv: public tx_service_attachment + { + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(service_id) + KV_SERIALIZE(instruction) + KV_SERIALIZE(body) + KV_SERIALIZE_CONTAINER_POD_AS_BLOB(security) + KV_SERIALIZE(flags) + END_KV_SERIALIZE_MAP() + }; + struct wallet_transfer_info { uint64_t amount; @@ -105,16 +116,18 @@ namespace wallet_public bool is_mining; uint64_t tx_type; wallet_transfer_info_details td; + std::vector service_entries; //not included in streaming serialization uint64_t fee; bool show_sender; std::vector contract; uint16_t extra_flags; + //not included in kv serialization map currency::transaction tx; std::vector selected_indicies; - std::list srv_attachments; + std::list marketplace_entries; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(amount) @@ -136,6 +149,7 @@ namespace wallet_public KV_SERIALIZE(tx_type) KV_SERIALIZE(show_sender) KV_SERIALIZE(contract) + KV_SERIALIZE(service_entries) END_KV_SERIALIZE_MAP() }; From 479f2029a0b00ff28ef654276287bef02e00d265 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 24 Jun 2021 23:24:38 +0200 Subject: [PATCH 45/83] added test isolate_auditable_and_proof --- src/currency_core/currency_format_utils.cpp | 6 +- src/currency_core/currency_format_utils.h | 2 +- src/simplewallet/simplewallet.cpp | 2 +- src/wallet/wallet2.cpp | 5 +- src/wallet/wallet_public_structs_defs.h | 2 +- .../isolate_auditable_and_proof.cpp | 116 ++++++++++++++++++ .../core_tests/isolate_auditable_and_proof.h | 19 +++ 7 files changed, 145 insertions(+), 7 deletions(-) create mode 100644 tests/core_tests/isolate_auditable_and_proof.cpp create mode 100644 tests/core_tests/isolate_auditable_and_proof.h diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 4e5d717d..27ecdc9d 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -793,7 +793,7 @@ namespace currency } void operator()(tx_service_attachment& sa) { - const std::string orignal_body = sa.body; + const std::string original_body = sa.body; if (sa.flags&TX_SERVICE_ATTACHMENT_DEFLATE_BODY) { zlib_helper::pack(sa.body); @@ -818,7 +818,7 @@ namespace currency { //take hash from derivation and use it as a salt crypto::hash derivation_hash = crypto::cn_fast_hash(&derivation_local, sizeof(derivation_local)); - std::string salted_body = orignal_body; + std::string salted_body = original_body; string_tools::apped_pod_to_strbuff(salted_body, derivation_hash); crypto::hash proof_hash = crypto::cn_fast_hash(salted_body.data(), salted_body.size()); sa.security.push_back(*(crypto::public_key*)&proof_hash); @@ -2950,7 +2950,7 @@ namespace currency return tools::base58::encode_addr(CURRENCY_PUBLIC_ADDRESS_BASE58_PREFIX, t_serializable_object_to_blob(addr)); // new format Zano address (normal) } //----------------------------------------------------------------------- - bool is_address_looks_like_wrapped(const std::string& addr) + bool is_address_like_wrapped(const std::string& addr) { if (addr.length() == 42 && addr.substr(0, 2) == "0x") return true; diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 86952896..9a108417 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -289,7 +289,7 @@ namespace currency bool decrypt_payload_items(bool is_income, const transaction& tx, const account_keys& acc_keys, std::vector& decrypted_items); void encrypt_attachments(transaction& tx, const account_keys& sender_keys, const account_public_address& destination_addr, const keypair& tx_random_key); bool is_derivation_used_to_encrypt(const transaction& tx, const crypto::key_derivation& derivation); - bool is_address_looks_like_wrapped(const std::string& addr); + bool is_address_like_wrapped(const std::string& addr); void load_wallet_transfer_info_flags(tools::wallet_public::wallet_transfer_info& x); uint64_t get_tx_type(const transaction& tx); uint64_t get_tx_type_ex(const transaction& tx, tx_out& htlc_out, txin_htlc& htlc_in); diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 3517e318..654ec78d 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -1218,7 +1218,7 @@ bool simple_wallet::transfer(const std::vector &args_) currency::tx_destination_entry de; de.addr.resize(1); //check if address looks like wrapped address - if (is_address_looks_like_wrapped(local_args[i])) + if (is_address_like_wrapped(local_args[i])) { success_msg_writer(true) << "Address " << local_args[i] << " recognized as wrapped address, creating wrapping transaction..."; //put into service attachment specially encrypted entry which will contain wrap address and network diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index b6c054a8..2f6f0dd7 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -718,7 +718,10 @@ void wallet2::prepare_wti_decrypted_attachments(wallet_public::wallet_transfer_i for (const auto& item : decrypted_att) { - wti.service_entries.push_back(item); + if (item.type() == typeid(currency::tx_service_attachment)) + { + wti.service_entries.push_back(tools::wallet_public::tx_service_attachment_kv(boost::get(item))); + } } } else diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index d9edd8ab..02bc1973 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -87,7 +87,7 @@ namespace wallet_public #define WALLET_TRANSFER_INFO_FLAGS_HTLC_DEPOSIT static_cast(1 << 0) - struct tx_service_attachment_kv: public tx_service_attachment + struct tx_service_attachment_kv: public currency::tx_service_attachment { BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(service_id) diff --git a/tests/core_tests/isolate_auditable_and_proof.cpp b/tests/core_tests/isolate_auditable_and_proof.cpp new file mode 100644 index 00000000..2fb3fa69 --- /dev/null +++ b/tests/core_tests/isolate_auditable_and_proof.cpp @@ -0,0 +1,116 @@ +// Copyright (c) 2014-2021 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "chaingen.h" +#include "escrow_wallet_tests.h" +#include "random_helper.h" +#include "chaingen_helpers.h" +#include "atomic_tests.h" + +using namespace epee; +using namespace crypto; +using namespace currency; + + +isolate_auditable_and_proof::isolate_auditable_and_proof() +{ + REGISTER_CALLBACK_METHOD(isolate_auditable_and_proof, c1); + REGISTER_CALLBACK_METHOD(isolate_auditable_and_proof, configure_core); +} + +bool isolate_auditable_and_proof::generate(std::vector& events) const +{ + random_state_test_restorer::reset_random(0); // to make the test deterministic + m_genesis_timestamp = 1450000000; + test_core_time::adjust(m_genesis_timestamp); + + + epee::debug::get_set_enable_assert(true, true); + + currency::account_base genesis_acc; + genesis_acc.generate(); + m_mining_accunt.generate(); + m_mining_accunt.set_createtime(m_genesis_timestamp); + + + block blk_0 = AUTO_VAL_INIT(blk_0); + generator.construct_genesis_block(blk_0, genesis_acc, test_core_time::get_time()); + events.push_back(blk_0); + DO_CALLBACK(events, "configure_core"); + REWIND_BLOCKS_N(events, blk_0r, blk_0, m_mining_accunt, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 5); + + DO_CALLBACK(events, "c1"); + epee::debug::get_set_enable_assert(true, false); + return true; +} + +bool isolate_auditable_and_proof::configure_core(currency::core& c, size_t ev_index, const std::vector& events) +{ + return true; +} +/************************************************************************/ +/* */ +/************************************************************************/ + +bool isolate_auditable_and_proof::c1(currency::core& c, size_t ev_index, const std::vector& events) +{ + epee::debug::get_set_enable_assert(true, true); + misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler([&](){epee::debug::get_set_enable_assert(true, false); }); + + LOG_PRINT_MAGENTA("Mining Address: " << currency::get_account_address_as_str(m_mining_accunt.get_public_address()), LOG_LEVEL_0); + + currency::account_base auditable_test; + auditable_test.generate(true); + auditable_test.set_createtime(m_genesis_timestamp); + LOG_PRINT_MAGENTA(": " << currency::get_account_address_as_str(auditable_test.get_public_address()), LOG_LEVEL_0); + std::shared_ptr auditable_test_instance = init_playtime_test_wallet(events, c, auditable_test); + + +#define AMOUNT_TO_TRANSFER_LOCAL (TESTS_DEFAULT_FEE*10) + + std::shared_ptr miner_wlt = init_playtime_test_wallet(events, c, m_mining_accunt); + miner_wlt->refresh(); + + + //create transaction that use TX_SERVICE_ATTACHMENT_ENCRYPT_BODY and TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE + { + std::vector extra; + std::vector attachments; + vector dsts; + + currency::tx_destination_entry de; + de.addr.resize(1); + //put into service attachment specially encrypted entry which will contain wrap address and network + tx_service_attachment sa = AUTO_VAL_INIT(sa); + sa.service_id = BC_WRAP_SERVICE_ID; + sa.instruction = BC_WRAP_SERVICE_INSTRUCTION_ERC20; + sa.flags = TX_SERVICE_ATTACHMENT_ENCRYPT_BODY | TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE; + sa.body = "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B"; + extra.push_back(sa); + + currency::account_public_address acc = AUTO_VAL_INIT(acc); + de.addr.front() = auditable_test.get_public_address(); + currency::transaction tx; + miner_wlt->transfer(dsts, 0, 0, miner_wlt->get_core_runtime_config().tx_default_fee, extra, attachments, tx); + } + + bool r = mine_next_pow_blocks_in_playtime(m_mining_accunt.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); + + miner_wlt->refresh(); + auditable_test_instance->refresh(); + + epee::json_rpc::error je; + tools::wallet_rpc_server::connection_context ctx; + tools::wallet_rpc_server miner_wlt_rpc(*auditable_test_instance); + wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::request req = AUTO_VAL_INIT(); + wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::request res = AUTO_VAL_INIT(); + req.count = 100; + req.offset = 0; + miner_wlt_rpc->on_get_recent_txs_and_info(req, res, je, ctx); + std::string ps = epee::serialization::store_t_to_json(res); + + return r; +} + diff --git a/tests/core_tests/isolate_auditable_and_proof.h b/tests/core_tests/isolate_auditable_and_proof.h new file mode 100644 index 00000000..b0df5b8d --- /dev/null +++ b/tests/core_tests/isolate_auditable_and_proof.h @@ -0,0 +1,19 @@ +// Copyright (c) 2014-2021 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#pragma once +#include "chaingen.h" +#include "wallet_tests_basic.h" + + +struct isolate_auditable_and_proof : public wallet_test +{ + isolate_auditable_and_proof(); + bool generate(std::vector& events) const; + virtual bool c1(currency::core& c, size_t ev_index, const std::vector& events)=0; + virtual bool configure_core(currency::core& c, size_t ev_index, const std::vector& events); +protected: + mutable uint64_t m_genesis_timestamp; + mutable currency::account_base m_mining_accunt; +}; From 11ef684b944bd347de014da022f03f1d6c34a37b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 26 Jun 2021 02:40:41 +0200 Subject: [PATCH 46/83] bunch of fixes over isolate_auditable_and_proof test --- src/currency_core/currency_basic.h | 8 ++++++++ src/wallet/wallet2.cpp | 2 +- src/wallet/wallet_public_structs_defs.h | 13 +------------ tests/core_tests/isolate_auditable_and_proof.cpp | 12 +++++++----- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index 1193bd8a..7dd6a8cd 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -383,6 +383,14 @@ namespace currency FIELD(security) FIELD(flags) END_SERIALIZE() + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(service_id) + KV_SERIALIZE(instruction) + KV_SERIALIZE(body) + KV_SERIALIZE_CONTAINER_POD_AS_BLOB(security) + KV_SERIALIZE(flags) + END_KV_SERIALIZE_MAP() }; // applicable flags for tx_service_attachment::flags, can be combined using bitwise OR diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 2f6f0dd7..5b753b91 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -720,7 +720,7 @@ void wallet2::prepare_wti_decrypted_attachments(wallet_public::wallet_transfer_i { if (item.type() == typeid(currency::tx_service_attachment)) { - wti.service_entries.push_back(tools::wallet_public::tx_service_attachment_kv(boost::get(item))); + wti.service_entries.push_back(boost::get(item)); } } } diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 02bc1973..3b78f2b4 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -87,17 +87,6 @@ namespace wallet_public #define WALLET_TRANSFER_INFO_FLAGS_HTLC_DEPOSIT static_cast(1 << 0) - struct tx_service_attachment_kv: public currency::tx_service_attachment - { - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(service_id) - KV_SERIALIZE(instruction) - KV_SERIALIZE(body) - KV_SERIALIZE_CONTAINER_POD_AS_BLOB(security) - KV_SERIALIZE(flags) - END_KV_SERIALIZE_MAP() - }; - struct wallet_transfer_info { uint64_t amount; @@ -116,7 +105,7 @@ namespace wallet_public bool is_mining; uint64_t tx_type; wallet_transfer_info_details td; - std::vector service_entries; + std::vector service_entries; //not included in streaming serialization uint64_t fee; bool show_sender; diff --git a/tests/core_tests/isolate_auditable_and_proof.cpp b/tests/core_tests/isolate_auditable_and_proof.cpp index 2fb3fa69..b2907824 100644 --- a/tests/core_tests/isolate_auditable_and_proof.cpp +++ b/tests/core_tests/isolate_auditable_and_proof.cpp @@ -6,7 +6,9 @@ #include "escrow_wallet_tests.h" #include "random_helper.h" #include "chaingen_helpers.h" -#include "atomic_tests.h" +#include "isolate_auditable_and_proof.h" +#include "wallet/wrap_service.h" +#include "wallet/wallet_rpc_server.h" using namespace epee; using namespace crypto; @@ -77,7 +79,7 @@ bool isolate_auditable_and_proof::c1(currency::core& c, size_t ev_index, const s { std::vector extra; std::vector attachments; - vector dsts; + std::vector dsts; currency::tx_destination_entry de; de.addr.resize(1); @@ -104,11 +106,11 @@ bool isolate_auditable_and_proof::c1(currency::core& c, size_t ev_index, const s epee::json_rpc::error je; tools::wallet_rpc_server::connection_context ctx; tools::wallet_rpc_server miner_wlt_rpc(*auditable_test_instance); - wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::request req = AUTO_VAL_INIT(); - wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::request res = AUTO_VAL_INIT(); + tools::wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::request req = AUTO_VAL_INIT(req); + tools::wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::response res = AUTO_VAL_INIT(res); req.count = 100; req.offset = 0; - miner_wlt_rpc->on_get_recent_txs_and_info(req, res, je, ctx); + miner_wlt_rpc.on_get_recent_txs_and_info(req, res, je, ctx); std::string ps = epee::serialization::store_t_to_json(res); return r; From d49882fbc03353004ad538a45cbffc5db6575a90 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sun, 27 Jun 2021 01:24:04 +0200 Subject: [PATCH 47/83] fixed minor bugs, proofs working now --- src/currency_core/currency_format_utils.cpp | 4 ++-- tests/core_tests/chaingen_main.cpp | 3 +++ tests/core_tests/chaingen_tests_list.h | 1 + tests/core_tests/isolate_auditable_and_proof.cpp | 2 +- tests/core_tests/isolate_auditable_and_proof.h | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 27ecdc9d..73bf0200 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -764,7 +764,7 @@ namespace currency const crypto::key_derivation& m_key; encrypt_attach_visitor(bool& was_crypted_entries, const crypto::key_derivation& key, const keypair& onetime_keypair = null_keypair, const account_public_address& destination_addr = null_pub_addr) : - m_was_crypted_entries(was_crypted_entries), m_key(key), m_onetime_keypair(onetime_keypair), m_destination_addr(m_destination_addr) + m_was_crypted_entries(was_crypted_entries), m_key(key), m_onetime_keypair(onetime_keypair), m_destination_addr(destination_addr) {} void operator()(tx_comment& comment) { @@ -870,7 +870,7 @@ namespace currency CHECK_AND_ASSERT_THROW_MES(m_acc_keys.spend_secret_key != currency::null_skey && m_tx_onetime_pubkey != currency::null_pkey, "tx_service_attachment with TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE: keys uninitialized"); bool r = crypto::generate_key_derivation(m_tx_onetime_pubkey, m_acc_keys.spend_secret_key, derivation_local); CHECK_AND_ASSERT_THROW_MES(r, "Failed to generate_key_derivation at TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE"); - crypto::chacha_crypt(sa.body, derivation_local); + crypto::chacha_crypt(local_sa.body, derivation_local); } else diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index 1f21fce7..6cd4425d 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -1029,6 +1029,9 @@ int main(int argc, char* argv[]) GENERATE_AND_PLAY(atomic_test_wrong_redeem_wrong_refund); GENERATE_AND_PLAY(atomic_test_altchain_simple); GENERATE_AND_PLAY(atomic_test_check_hardfork_rules); + + GENERATE_AND_PLAY(isolate_auditable_and_proof); + // GENERATE_AND_PLAY(gen_block_reward); diff --git a/tests/core_tests/chaingen_tests_list.h b/tests/core_tests/chaingen_tests_list.h index 2a419569..9d2e4c54 100644 --- a/tests/core_tests/chaingen_tests_list.h +++ b/tests/core_tests/chaingen_tests_list.h @@ -39,3 +39,4 @@ #include "hard_fork_1.h" #include "hard_fork_2.h" #include "atomic_tests.h" +#include "isolate_auditable_and_proof.h" diff --git a/tests/core_tests/isolate_auditable_and_proof.cpp b/tests/core_tests/isolate_auditable_and_proof.cpp index b2907824..9b602f09 100644 --- a/tests/core_tests/isolate_auditable_and_proof.cpp +++ b/tests/core_tests/isolate_auditable_and_proof.cpp @@ -87,7 +87,7 @@ bool isolate_auditable_and_proof::c1(currency::core& c, size_t ev_index, const s tx_service_attachment sa = AUTO_VAL_INIT(sa); sa.service_id = BC_WRAP_SERVICE_ID; sa.instruction = BC_WRAP_SERVICE_INSTRUCTION_ERC20; - sa.flags = TX_SERVICE_ATTACHMENT_ENCRYPT_BODY | TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE; + sa.flags = TX_SERVICE_ATTACHMENT_ENCRYPT_BODY | TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE| TX_SERVICE_ATTACHMENT_ENCRYPT_ADD_PROOF; sa.body = "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B"; extra.push_back(sa); diff --git a/tests/core_tests/isolate_auditable_and_proof.h b/tests/core_tests/isolate_auditable_and_proof.h index b0df5b8d..361abc27 100644 --- a/tests/core_tests/isolate_auditable_and_proof.h +++ b/tests/core_tests/isolate_auditable_and_proof.h @@ -11,7 +11,7 @@ struct isolate_auditable_and_proof : public wallet_test { isolate_auditable_and_proof(); bool generate(std::vector& events) const; - virtual bool c1(currency::core& c, size_t ev_index, const std::vector& events)=0; + virtual bool c1(currency::core& c, size_t ev_index, const std::vector& events); virtual bool configure_core(currency::core& c, size_t ev_index, const std::vector& events); protected: mutable uint64_t m_genesis_timestamp; From 69500c83be473a0dc463d98c0925bd18e50dd304 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 28 Jun 2021 00:08:33 +0200 Subject: [PATCH 48/83] fixed last bugs in isolate_auditable_and_proof --- src/currency_core/currency_format_utils.cpp | 4 ++-- tests/core_tests/isolate_auditable_and_proof.cpp | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 73bf0200..d78ec011 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1017,8 +1017,8 @@ namespace currency return true; } - decrypt_payload_items(derivation, tx.extra, decrypted_items, acc_keys, get_tx_pub_key_from_extra(tx)); - decrypt_payload_items(derivation, tx.attachment, decrypted_items, acc_keys, get_tx_pub_key_from_extra(tx)); + decrypt_payload_items(derivation, tx.extra, decrypted_items, is_income ? acc_keys: account_keys(), get_tx_pub_key_from_extra(tx)); + decrypt_payload_items(derivation, tx.attachment, decrypted_items, is_income ? acc_keys : account_keys(), get_tx_pub_key_from_extra(tx)); return true; } diff --git a/tests/core_tests/isolate_auditable_and_proof.cpp b/tests/core_tests/isolate_auditable_and_proof.cpp index 9b602f09..f752b81a 100644 --- a/tests/core_tests/isolate_auditable_and_proof.cpp +++ b/tests/core_tests/isolate_auditable_and_proof.cpp @@ -93,7 +93,9 @@ bool isolate_auditable_and_proof::c1(currency::core& c, size_t ev_index, const s currency::account_public_address acc = AUTO_VAL_INIT(acc); de.addr.front() = auditable_test.get_public_address(); - currency::transaction tx; + de.amount = AMOUNT_TO_TRANSFER_LOCAL; + dsts.push_back(de); + currency::transaction tx = AUTO_VAL_INIT(tx); miner_wlt->transfer(dsts, 0, 0, miner_wlt->get_core_runtime_config().tx_default_fee, extra, attachments, tx); } From c6fa1c6c29a3de6c730af74d9148f32c6384168b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 29 Jun 2021 16:46:03 +0200 Subject: [PATCH 49/83] final fixes in isolate_auditable_and_proof --- tests/core_tests/isolate_auditable_and_proof.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/core_tests/isolate_auditable_and_proof.cpp b/tests/core_tests/isolate_auditable_and_proof.cpp index f752b81a..e3fadbdb 100644 --- a/tests/core_tests/isolate_auditable_and_proof.cpp +++ b/tests/core_tests/isolate_auditable_and_proof.cpp @@ -76,7 +76,7 @@ bool isolate_auditable_and_proof::c1(currency::core& c, size_t ev_index, const s //create transaction that use TX_SERVICE_ATTACHMENT_ENCRYPT_BODY and TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE - { + //{ std::vector extra; std::vector attachments; std::vector dsts; @@ -97,7 +97,7 @@ bool isolate_auditable_and_proof::c1(currency::core& c, size_t ev_index, const s dsts.push_back(de); currency::transaction tx = AUTO_VAL_INIT(tx); miner_wlt->transfer(dsts, 0, 0, miner_wlt->get_core_runtime_config().tx_default_fee, extra, attachments, tx); - } + //} bool r = mine_next_pow_blocks_in_playtime(m_mining_accunt.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); @@ -113,8 +113,13 @@ bool isolate_auditable_and_proof::c1(currency::core& c, size_t ev_index, const s req.count = 100; req.offset = 0; miner_wlt_rpc.on_get_recent_txs_and_info(req, res, je, ctx); - std::string ps = epee::serialization::store_t_to_json(res); + CHECK_AND_ASSERT_MES(res.transfers.size() == 1, false, "res.transfers.size() == 1 failed"); + CHECK_AND_ASSERT_MES(res.transfers[0].service_entries.size(), false, "res.transfers[0].service_entries.size() failed"); + + CHECK_AND_ASSERT_MES(res.transfers[0].service_entries[0].body == sa.body, false, "res.transfers[0].service_entries[0].body == sa.body failed"); + CHECK_AND_ASSERT_MES(res.transfers[0].service_entries[0].service_id == sa.service_id, false, "res.transfers[0].service_entries[0].service_id == sa.service_id failed"); + CHECK_AND_ASSERT_MES(res.transfers[0].service_entries[0].instruction == sa.instruction, false, "res.transfers[0].service_entries[0].instruction == sa.instruction failed"); - return r; + return true; } From 82a72293685a48924e96a8c312e1ad6c4d323666 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 1 Jul 2021 21:05:50 +0200 Subject: [PATCH 50/83] added transfer_internal_index to wallet_transfer_info struct --- src/wallet/wallet2.cpp | 3 ++- src/wallet/wallet_public_structs_defs.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 5b753b91..5801d511 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1662,7 +1662,7 @@ void wallet2::handle_pulled_blocks(size_t& blocks_added, std::atomic& stop //block matched in that number last_matched_index = height; been_matched_block = true; - WLT_LOG_L2("Block " << bl_id << " @ " << height << " is already in wallet's blockchain"); + WLT_LOG_L4("Block " << bl_id << " @ " << height << " is already in wallet's blockchain"); } else { @@ -3207,6 +3207,7 @@ void wallet2::get_recent_transfers_history(std::vector= count) { diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 3b78f2b4..48251797 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -111,6 +111,7 @@ namespace wallet_public bool show_sender; std::vector contract; uint16_t extra_flags; + uint64_t transfer_internal_index; //not included in kv serialization map @@ -139,6 +140,7 @@ namespace wallet_public KV_SERIALIZE(show_sender) KV_SERIALIZE(contract) KV_SERIALIZE(service_entries) + KV_SERIALIZE(transfer_internal_index) END_KV_SERIALIZE_MAP() }; From d2bb634a7dda966f87ee1092e8374a6aef284cc0 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 1 Jul 2021 23:00:28 +0200 Subject: [PATCH 51/83] added current_height to COMMAND_RPC_GET_RECENT_TXS_AND_INFO response --- src/wallet/wallet_public_structs_defs.h | 5 +++++ src/wallet/wallet_rpc_server.cpp | 2 ++ src/wallet/wallet_rpc_server.h | 8 ++++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 48251797..f93242e3 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -259,6 +259,7 @@ namespace wallet_public uint64_t transfer_entries_count; bool is_whatch_only; std::vector utxo_distribution; + uint64_t current_height; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(address) @@ -267,6 +268,8 @@ namespace wallet_public KV_SERIALIZE(transfer_entries_count) KV_SERIALIZE(is_whatch_only) KV_SERIALIZE(utxo_distribution) + KV_SERIALIZE(current_height) + KV_SERIALIZE_POD_AS_HEX_STRING(last_block_id) END_KV_SERIALIZE_MAP() }; }; @@ -304,6 +307,7 @@ namespace wallet_public uint64_t transfer_entries_count; uint64_t balance; uint64_t unlocked_balance; + uint64_t curent_height; BEGIN_KV_SERIALIZE_MAP() @@ -311,6 +315,7 @@ namespace wallet_public KV_SERIALIZE(transfer_entries_count) KV_SERIALIZE(balance) KV_SERIALIZE(unlocked_balance) + KV_SERIALIZE(curent_height) END_KV_SERIALIZE_MAP() }; diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 71d34fa1..4f581e22 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -208,6 +208,7 @@ namespace tools for (const auto& ent : distribution) res.utxo_distribution.push_back(currency::print_money_brief(ent.first) + ":" + std::to_string(ent.second)); + res.current_height = m_wallet.get_top_block_height(); return true; } catch (std::exception& e) @@ -245,6 +246,7 @@ namespace tools res.pi.balance = m_wallet.balance(res.pi.unlocked_balance); res.pi.transfer_entries_count = m_wallet.get_transfer_entries_count(); res.pi.transfers_count = m_wallet.get_recent_transfers_total_count(); + res.pi.curent_height = m_wallet.get_top_block_height(); } if (req.offset == 0) diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h index 2d94bc52..3c75296e 100644 --- a/src/wallet/wallet_rpc_server.h +++ b/src/wallet/wallet_rpc_server.h @@ -66,10 +66,10 @@ namespace tools MAP_JON_RPC_WE("marketplace_push_update_offer", on_marketplace_push_update_offer, wallet_public::COMMAND_MARKETPLACE_PUSH_UPDATE_OFFER) MAP_JON_RPC_WE("marketplace_cancel_offer", on_marketplace_cancel_offer, wallet_public::COMMAND_MARKETPLACE_CANCEL_OFFER) //HTLC API - MAP_JON_RPC_WE("atomics_create_htlc_proposal", on_create_htlc_proposal, wallet_public::COMMAND_CREATE_HTLC_PROPOSAL) - MAP_JON_RPC_WE("atomics_get_list_of_active_htlc", on_get_list_of_active_htlc, wallet_public::COMMAND_GET_LIST_OF_ACTIVE_HTLC) - MAP_JON_RPC_WE("atomics_redeem_htlc", on_redeem_htlc, wallet_public::COMMAND_REDEEM_HTLC) - MAP_JON_RPC_WE("atomics_check_htlc_redeemed", on_check_htlc_redeemed, wallet_public::COMMAND_CHECK_HTLC_REDEEMED) + MAP_JON_RPC_WE("atomics_create_htlc_proposal", on_create_htlc_proposal, wallet_public::COMMAND_CREATE_HTLC_PROPOSAL) + MAP_JON_RPC_WE("atomics_get_list_of_active_htlc", on_get_list_of_active_htlc, wallet_public::COMMAND_GET_LIST_OF_ACTIVE_HTLC) + MAP_JON_RPC_WE("atomics_redeem_htlc", on_redeem_htlc, wallet_public::COMMAND_REDEEM_HTLC) + MAP_JON_RPC_WE("atomics_check_htlc_redeemed", on_check_htlc_redeemed, wallet_public::COMMAND_CHECK_HTLC_REDEEMED) END_JSON_RPC_MAP() END_URI_MAP2() From e9b4b216ccd9ef2ee54a119581db7991aa8d0dbd Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 1 Jul 2021 23:47:31 +0200 Subject: [PATCH 52/83] removed forgotten field --- src/wallet/wallet_public_structs_defs.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index f93242e3..4c3061fd 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -269,7 +269,6 @@ namespace wallet_public KV_SERIALIZE(is_whatch_only) KV_SERIALIZE(utxo_distribution) KV_SERIALIZE(current_height) - KV_SERIALIZE_POD_AS_HEX_STRING(last_block_id) END_KV_SERIALIZE_MAP() }; }; From b48dada17fc96bd1ac73e616dbcde40d324ba56b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sun, 4 Jul 2021 21:08:54 +0200 Subject: [PATCH 53/83] added FORCE_HEADER_ONLY for projects that use header files as external interface --- src/currency_core/account.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/currency_core/account.h b/src/currency_core/account.h index e9674307..37a0c953 100644 --- a/src/currency_core/account.h +++ b/src/currency_core/account.h @@ -16,13 +16,15 @@ #define SEED_PHRASE_V2_WORDS_COUNT 26 +#ifndef FORCE_HEADER_ONLY + #define KV_SERIALIZE_ADDRESS_AS_TEXT_N(varialble, val_name) \ + KV_SERIALIZE_CUSTOM_N(varialble, std::string, currency::transform_addr_to_str, currency::transform_str_to_addr, val_name) -#define KV_SERIALIZE_ADDRESS_AS_TEXT_N(varialble, val_name) \ - KV_SERIALIZE_CUSTOM_N(varialble, std::string, currency::transform_addr_to_str, currency::transform_str_to_addr, val_name) - -#define KV_SERIALIZE_ADDRESS_AS_TEXT(varialble) KV_SERIALIZE_ADDRESS_AS_TEXT_N(varialble, #varialble) - - + #define KV_SERIALIZE_ADDRESS_AS_TEXT(varialble) KV_SERIALIZE_ADDRESS_AS_TEXT_N(varialble, #varialble) +#else + #define KV_SERIALIZE_ADDRESS_AS_TEXT_N(varialble, val_name) + #define KV_SERIALIZE_ADDRESS_AS_TEXT(varialble) +#endif namespace currency { From 2151f8f53ec790d1247ad7a6bc9dd638fc62e73a Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 6 Jul 2021 15:40:40 +0200 Subject: [PATCH 54/83] removed annoying < and > symbols --- src/common/crypto_stream_operators.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/crypto_stream_operators.h b/src/common/crypto_stream_operators.h index 0201603b..fa2531de 100644 --- a/src/common/crypto_stream_operators.h +++ b/src/common/crypto_stream_operators.h @@ -15,20 +15,20 @@ bool parse_hash256(const std::string str_hash, crypto::hash& hash); template std::ostream &print_t(std::ostream &o, const T &v) { - return o << "<" << epee::string_tools::pod_to_hex(v) << ">"; + return o << "" << epee::string_tools::pod_to_hex(v) << ""; } template std::ostream &print16(std::ostream &o, const T &v) { - return o << "<" << epee::string_tools::pod_to_hex(v).substr(0, 5) << "..>"; + return o << "" << epee::string_tools::pod_to_hex(v).substr(0, 5) << ".."; } template std::string print16(const T &v) { - return std::string("<") + epee::string_tools::pod_to_hex(v).substr(0, 5) + "..>"; + return std::string("") + epee::string_tools::pod_to_hex(v).substr(0, 5) + ".."; } From 84f0119948d53f0d00b8513564521e916fb24bc7 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 17 Jul 2021 00:05:41 +0200 Subject: [PATCH 55/83] extended wallet transfer API to service_entries option --- src/currency_core/currency_basic.h | 2 +- src/wallet/wallet2.h | 7 ++++--- src/wallet/wallet_public_structs_defs.h | 5 ++++- src/wallet/wallet_rpc_server.cpp | 28 ++++++++++++++++++------- src/wallet/wrap_service.h | 3 ++- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index 7dd6a8cd..dc973a66 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -387,7 +387,7 @@ namespace currency BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(service_id) KV_SERIALIZE(instruction) - KV_SERIALIZE(body) + KV_SERIALIZE_BLOB_AS_HEX_STRING(body) KV_SERIALIZE_CONTAINER_POD_AS_BLOB(security) KV_SERIALIZE(flags) END_KV_SERIALIZE_MAP() diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 4d4d8b92..b1281e08 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -595,12 +595,12 @@ namespace tools void transfer(construct_tx_param& ctp, currency::transaction &tx, bool send_to_network, - std::string* p_unsigned_filename_or_tx_blob_str); + std::string* p_unsigned_filename_or_tx_blob_str = nullptr); void transfer(construct_tx_param& ctp, currency::finalized_tx& result, bool send_to_network, - std::string* p_unsigned_filename_or_tx_blob_str); + std::string* p_unsigned_filename_or_tx_blob_str = nullptr); template @@ -854,6 +854,7 @@ namespace tools uint64_t get_sync_progress(); uint64_t get_wallet_file_size()const; void set_use_deffered_global_outputs(bool use); + construct_tx_param get_default_construct_tx_param_inital(); /* create_htlc_proposal: if htlc_hash == null_hash, then this wallet is originator of the atomic process, and @@ -943,7 +944,7 @@ private: void change_contract_state(wallet_public::escrow_contract_details_basic& contract, uint32_t new_state, const crypto::hash& contract_id, const wallet_public::wallet_transfer_info& wti) const; void change_contract_state(wallet_public::escrow_contract_details_basic& contract, uint32_t new_state, const crypto::hash& contract_id, const std::string& reason = "internal intention") const; - construct_tx_param get_default_construct_tx_param_inital(); + const construct_tx_param& get_default_construct_tx_param(); uint64_t get_tx_expiration_median() const; diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 4c3061fd..0084e418 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -388,16 +388,19 @@ namespace wallet_public std::string comment; bool push_payer; bool hide_receiver; + std::vector service_entries; + bool service_entries_permanent; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(destinations) KV_SERIALIZE(fee) KV_SERIALIZE(mixin) - //KV_SERIALIZE(unlock_time) KV_SERIALIZE(payment_id) KV_SERIALIZE(comment) KV_SERIALIZE(push_payer) KV_SERIALIZE(hide_receiver) + KV_SERIALIZE(service_entries) + KV_SERIALIZE(service_entries_permanent) END_KV_SERIALIZE_MAP() }; diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 4f581e22..13b9834a 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -281,7 +281,18 @@ namespace tools return false; } - std::vector dsts; + construct_tx_param ctp = m_wallet.get_default_construct_tx_param_inital(); + if (req.service_entries_permanent) + { + //put it to extra + ctp.extra.insert(ctp.extra.end(), req.service_entries.begin(), req.service_entries.end()); + } + else + { + //put it to attachments + ctp.attachments.insert(ctp.extra.end(), req.service_entries.begin(), req.service_entries.end()); + } + std::vector& dsts = ctp.dsts; for (auto it = req.destinations.begin(); it != req.destinations.end(); it++) { currency::tx_destination_entry de; @@ -308,8 +319,8 @@ namespace tools } try { - std::vector attachments; - std::vector extra; + std::vector& attachments = ctp.attachments; + std::vector& extra = ctp.extra; if (!payment_id.empty() && !currency::set_payment_id_to_tx(attachments, payment_id)) { er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID; @@ -338,10 +349,11 @@ namespace tools } } - currency::transaction tx; - + currency::finalized_tx result = AUTO_VAL_INIT(result); std::string unsigned_tx_blob_str; - m_wallet.transfer(dsts, req.mixin, 0/*req.unlock_time*/, req.fee, extra, attachments, detail::ssi_digit, tx_dust_policy(DEFAULT_DUST_THRESHOLD), tx, CURRENCY_TO_KEY_OUT_RELAXED, true, 0, true, &unsigned_tx_blob_str); + ctp.fee = req.fee; + ctp.fake_outputs_count = 0; + m_wallet.transfer(ctp, result, true, &unsigned_tx_blob_str); if (m_wallet.is_watch_only()) { res.tx_unsigned_hex = epee::string_tools::buff_to_hex_nodelimer(unsigned_tx_blob_str); // watch-only wallets could not sign and relay transactions @@ -349,8 +361,8 @@ namespace tools } else { - res.tx_hash = epee::string_tools::pod_to_hex(currency::get_transaction_hash(tx)); - res.tx_size = get_object_blobsize(tx); + res.tx_hash = epee::string_tools::pod_to_hex(currency::get_transaction_hash(result.tx)); + res.tx_size = get_object_blobsize(result.tx); } return true; } diff --git a/src/wallet/wrap_service.h b/src/wallet/wrap_service.h index 852d60d7..52b288d4 100644 --- a/src/wallet/wrap_service.h +++ b/src/wallet/wrap_service.h @@ -6,7 +6,8 @@ #define BC_WRAP_SERVICE_ID "W" -#define BC_WRAP_SERVICE_INSTRUCTION_ERC20 "ERC20" //erc20 wrapped operation +#define BC_WRAP_SERVICE_INSTRUCTION_ERC20 "ERC20" //erc20 wrap operation +#define BC_WRAP_SERVICE_INSTRUCTION_UNWRAP "UNWRAP" //erc20 unwrap operation #define BC_WRAP_SERVICE_CUSTODY_WALLET "aZxbJPXzkjCJDpGEVvkMir9B4fRKPo73r2e5D7nLHuVgEBXXQYc2Tk2hHroxVwiCDLDHZu215pgNocUsrchH4HHzWbHzL4nMfPq" \ No newline at end of file From 4584b5fedef9276aab62c472e881e13612fafebe Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sun, 18 Jul 2021 01:57:45 +0200 Subject: [PATCH 56/83] Added green logs shortcut --- contrib/epee/include/misc_log_ex.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h index e0a58617..1d54b6f9 100644 --- a/contrib/epee/include/misc_log_ex.h +++ b/contrib/epee/include/misc_log_ex.h @@ -183,7 +183,8 @@ DISABLE_VS_WARNINGS(4100) #define LOG_PRINT_CYAN(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_cyan) #define LOG_PRINT_MAGENTA(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_magenta) -#define LOG_PRINT_RED_L0(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_red) +#define LOG_PRINT_RED_L0(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_red) +#define LOG_PRINT_GREEN_L0(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_green) #define LOG_PRINT_L0(mess) LOG_PRINT(mess, LOG_LEVEL_0) #define LOG_PRINT_L1(mess) LOG_PRINT(mess, LOG_LEVEL_1) From 7886f7cd3dcc453b0c4a759ecdc923dcff8dc726 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 19 Jul 2021 22:52:59 +0200 Subject: [PATCH 57/83] modified logging in wallet --- contrib/epee/include/misc_log_ex.h | 2 +- src/simplewallet/simplewallet.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h index 1d54b6f9..0b05d313 100644 --- a/contrib/epee/include/misc_log_ex.h +++ b/contrib/epee/include/misc_log_ex.h @@ -184,7 +184,7 @@ DISABLE_VS_WARNINGS(4100) #define LOG_PRINT_MAGENTA(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_magenta) #define LOG_PRINT_RED_L0(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_red) -#define LOG_PRINT_GREEN_L0(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_green) +#define LOG_PRINT_GREEN_L0(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_green) #define LOG_PRINT_L0(mess) LOG_PRINT(mess, LOG_LEVEL_0) #define LOG_PRINT_L1(mess) LOG_PRINT(mess, LOG_LEVEL_1) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 654ec78d..bed7e83c 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -754,7 +754,7 @@ bool print_wti(const tools::wallet_public::wallet_transfer_info& wti) remote_side += remote_side.empty() ? it : (separator + it); } - message_writer(cl) << epee::misc_utils::get_time_str_v2(wti.timestamp) << " " + success_msg_writer(cl) << "[" << wti.transfer_internal_index << "]" << epee::misc_utils::get_time_str_v2(wti.timestamp) << " " << (wti.is_income ? "Received " : "Sent ") << print_money(wti.amount) << "(fee:" << print_money(wti.fee) << ") " << remote_side @@ -768,7 +768,7 @@ bool simple_wallet::list_recent_transfers(const std::vector& args) std::vector recent; uint64_t total = 0; uint64_t last_index = 0; - m_wallet->get_recent_transfers_history(recent, 0, 0, total, last_index, false); + m_wallet->get_recent_transfers_history(recent, std::stoll(args[0]), std::stoll(args[1]), total, last_index, false); m_wallet->get_unconfirmed_transfers(unconfirmed, false); //workaround for missed fee From c0621eb2f2a602ed5ec124ebb1b7ae06d62eddef Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 20 Jul 2021 15:36:47 +0200 Subject: [PATCH 58/83] extended api for wallet --- src/simplewallet/simplewallet.cpp | 2 +- src/wallet/wallet2.cpp | 40 ++++++++++++++++++------- src/wallet/wallet2.h | 2 +- src/wallet/wallet_public_structs_defs.h | 6 ++++ src/wallet/wallet_rpc_server.cpp | 7 ++++- 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index bed7e83c..e83791e5 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -768,7 +768,7 @@ bool simple_wallet::list_recent_transfers(const std::vector& args) std::vector recent; uint64_t total = 0; uint64_t last_index = 0; - m_wallet->get_recent_transfers_history(recent, std::stoll(args[0]), std::stoll(args[1]), total, last_index, false); + m_wallet->get_recent_transfers_history(recent, std::stoll(args[0]), std::stoll(args[1]), total, last_index, false, false); m_wallet->get_unconfirmed_transfers(unconfirmed, false); //workaround for missed fee diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 5801d511..21e49f5d 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3192,29 +3192,49 @@ 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, uint64_t& last_item_index, bool exclude_mining_txs) + +template +bool enum_container(iterator_t it_begin, iterator_t it_end, callback_t cb) +{ + for (iterator_t it = it_begin; it != it_end; it++) + { + if (!cb(*it, it - it_begin)) + return true; + } + return true; +} +//---------------------------------------------------------------------------------------------------- +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, bool start_from_end) { if (!count || offset >= m_transfer_history.size()) return; - for (auto it = m_transfer_history.rbegin() + offset; it != m_transfer_history.rend(); it++) - { + auto cb = [&](wallet_public::wallet_transfer_info& wti, size_t local_offset) { + if (exclude_mining_txs) { - if(currency::is_coinbase(it->tx)) - continue; + if (currency::is_coinbase(wti.tx)) + return true; } - trs.push_back(*it); + trs.push_back(wti); load_wallet_transfer_info_flags(trs.back()); - last_item_index = it - m_transfer_history.rbegin(); + last_item_index = offset + local_offset; trs.back().transfer_internal_index = last_item_index; - + if (trs.size() >= count) { - break; + return false; } - } + return true; + }; + + if(start_from_end) + enum_container(m_transfer_history.rbegin() + offset, m_transfer_history.rend(), cb); + else + enum_container(m_transfer_history.begin() + offset, m_transfer_history.end(), cb); + total = m_transfer_history.size(); + } //---------------------------------------------------------------------------------------------------- bool wallet2::get_transfer_address(const std::string& adr_str, currency::account_public_address& addr, std::string& payment_id) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index b1281e08..10d79bf6 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -509,7 +509,7 @@ 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, uint64_t& last_item_index, bool exclude_mining_txs = false); + 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, bool start_from_end = true); uint64_t get_recent_transfers_total_count(); uint64_t get_transfer_entries_count(); void get_unconfirmed_transfers(std::vector& trs, bool exclude_mining_txs = false); diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 0084e418..d12d1367 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -318,6 +318,10 @@ namespace wallet_public END_KV_SERIALIZE_MAP() }; + +#define ORDER_FROM_BEGIN_TO_END "FROM_BEGIN_TO_END" +#define ORDER_FROM_FROM_END_TO_BEGIN "FROM_END_TO_BEGIN" + struct COMMAND_RPC_GET_RECENT_TXS_AND_INFO { struct request @@ -338,12 +342,14 @@ namespace wallet_public */ bool update_provision_info; bool exclude_mining_txs; + std::string order; // "FROM_BEGIN_TO_END" or "FROM_END_TO_BEGIN" BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(offset) KV_SERIALIZE(count) KV_SERIALIZE(update_provision_info) KV_SERIALIZE(exclude_mining_txs) + KV_SERIALIZE(order) END_KV_SERIALIZE_MAP() }; diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 13b9834a..fdfb6f20 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -252,7 +252,12 @@ namespace tools if (req.offset == 0) 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, res.last_item_index, req.exclude_mining_txs); + bool start_from_end = true; + if (req.order == ORDER_FROM_BEGIN_TO_END) + { + start_from_end = false; + } + m_wallet.get_recent_transfers_history(res.transfers, req.offset, req.count, res.total_transfers, res.last_item_index, req.exclude_mining_txs, start_from_end); return true; } From 9936ef63cfe916e52a55824bcfd2f29abab45ef6 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 21 Jul 2021 00:25:12 +0200 Subject: [PATCH 59/83] More options on wallet API --- src/wallet/wallet2.cpp | 17 +++++++++-------- src/wallet/wallet_public_structs_defs.h | 2 ++ src/wallet/wallet_rpc_server.cpp | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 21e49f5d..10bb0475 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -709,20 +709,21 @@ void wallet2::prepare_wti_decrypted_attachments(wallet_public::wallet_transfer_i } get_payment_id_from_tx(decrypted_att, wti.payment_id); + for (const auto& item : decrypted_att) + { + if (item.type() == typeid(currency::tx_service_attachment)) + { + wti.service_entries.push_back(boost::get(item)); + } + } + + if (wti.is_income) { account_public_address sender_address = AUTO_VAL_INIT(sender_address); wti.show_sender = handle_2_alternative_types_in_variant_container(decrypted_att, [&](const tx_payer& p) { sender_address = p.acc_addr; return false; /* <- continue? */ } ); if (wti.show_sender) wti.remote_addresses.push_back(currency::get_account_address_as_str(sender_address)); - - for (const auto& item : decrypted_att) - { - if (item.type() == typeid(currency::tx_service_attachment)) - { - wti.service_entries.push_back(boost::get(item)); - } - } } else { diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index d12d1367..960516db 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -342,6 +342,7 @@ namespace wallet_public */ bool update_provision_info; bool exclude_mining_txs; + bool exclude_unconfirmed; std::string order; // "FROM_BEGIN_TO_END" or "FROM_END_TO_BEGIN" BEGIN_KV_SERIALIZE_MAP() @@ -349,6 +350,7 @@ namespace wallet_public KV_SERIALIZE(count) KV_SERIALIZE(update_provision_info) KV_SERIALIZE(exclude_mining_txs) + KV_SERIALIZE(exclude_unconfirmed) KV_SERIALIZE(order) END_KV_SERIALIZE_MAP() }; diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index fdfb6f20..aca13701 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -249,7 +249,7 @@ namespace tools res.pi.curent_height = m_wallet.get_top_block_height(); } - if (req.offset == 0) + if (req.offset == 0 && !req.exclude_unconfirmed) m_wallet.get_unconfirmed_transfers(res.transfers, req.exclude_mining_txs); bool start_from_end = true; From 038a5a4a07444ce8313622bb363d6848846d43bc Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 22 Jul 2021 00:44:28 +0200 Subject: [PATCH 60/83] upgraded logs --- contrib/epee/include/misc_log_ex.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h index 0b05d313..b8749cd7 100644 --- a/contrib/epee/include/misc_log_ex.h +++ b/contrib/epee/include/misc_log_ex.h @@ -141,8 +141,10 @@ DISABLE_VS_WARNINGS(4100) #define LOG_PRINT_CHANNEL_2_JORNAL(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ {TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, true, log_name);CATCH_ALL_DO_NOTHING();}} -#define LOG_ERROR2(log_name, x) { \ - TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << "[ERROR] Location: " << std::endl << LOCATION_SS << epee::misc_utils::get_callstack() << " Message:" << std::endl << x << std::endl; epee::log_space::log_singletone::do_log_message(ss________.str(), LOG_LEVEL_0, epee::log_space::console_color_red, true, log_name); LOCAL_ASSERT(0); epee::log_space::increase_error_count(LOG_DEFAULT_CHANNEL);CATCH_ALL_DO_NOTHING();} +#define LOG_ERROR2_CB(log_name, x, cb) { \ + TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << "[ERROR] Location: " << std::endl << LOCATION_SS << epee::misc_utils::get_callstack() << " Message:" << std::endl << x << std::endl; epee::log_space::log_singletone::do_log_message(ss________.str(), LOG_LEVEL_0, epee::log_space::console_color_red, true, log_name); LOCAL_ASSERT(0); epee::log_space::increase_error_count(LOG_DEFAULT_CHANNEL); cb(ss________.str()); CATCH_ALL_DO_NOTHING();} + +#define LOG_ERROR2(log_name, x) LOG_ERROR2_CB(log_name, x, epee::log_space::log_stub) #define LOG_FRAME2(log_name, x, y) epee::log_space::log_frame frame(x, y, log_name) @@ -194,6 +196,7 @@ DISABLE_VS_WARNINGS(4100) #define LOG_PRINT_J(mess, level) LOG_PRINT2_JORNAL(LOG_DEFAULT_TARGET, mess, level) #define LOG_ERROR(mess) LOG_ERROR2(LOG_DEFAULT_TARGET, mess) +#define LOG_ERROR_CB(mess, cb) LOG_ERROR2_CB(LOG_DEFAULT_TARGET, mess, cb) #define LOG_FRAME(mess, level) LOG_FRAME2(LOG_DEFAULT_TARGET, mess, level) #define LOG_VALUE(mess, level) LOG_VALUE2(LOG_DEFAULT_TARGET, mess, level) #define LOG_ARRAY(mess, level) LOG_ARRAY2(LOG_DEFAULT_TARGET, mess, level) @@ -334,7 +337,8 @@ namespace log_space /* */ /************************************************************************/ #define CONSOLE_DEFAULT_STREAM std::cout - + + inline void log_stub(const std::string& /**/) {} struct delete_ptr { From 04083afc87df7059a50923d17caa902ab9c969c2 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 26 Jul 2021 16:17:13 +0200 Subject: [PATCH 61/83] fixed correct auditable address --- src/wallet/wrap_service.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wrap_service.h b/src/wallet/wrap_service.h index 52b288d4..0ca52d15 100644 --- a/src/wallet/wrap_service.h +++ b/src/wallet/wrap_service.h @@ -10,4 +10,4 @@ #define BC_WRAP_SERVICE_INSTRUCTION_UNWRAP "UNWRAP" //erc20 unwrap operation -#define BC_WRAP_SERVICE_CUSTODY_WALLET "aZxbJPXzkjCJDpGEVvkMir9B4fRKPo73r2e5D7nLHuVgEBXXQYc2Tk2hHroxVwiCDLDHZu215pgNocUsrchH4HHzWbHzL4nMfPq" \ No newline at end of file +#define BC_WRAP_SERVICE_CUSTODY_WALLET "aZxaszi4TaDCUqRCmqe23HASryshQNHmBSFnUN1pY8VsRfss2ZSMGBpLhdFtHgKmFr353NneaYRT6CpSz7zA3EC9bocQcq7m9nP" \ No newline at end of file From 553eee55cad308352ba937c84cef913fe71b1262 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 27 Jul 2021 22:45:06 +0200 Subject: [PATCH 62/83] fixed bug in list_recent_transfers --- src/simplewallet/simplewallet.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index e83791e5..c72242d3 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -192,7 +192,7 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("balance", boost::bind(&simple_wallet::show_balance, this, _1), "Show current wallet balance"); m_cmd_binder.set_handler("incoming_transfers", boost::bind(&simple_wallet::show_incoming_transfers, this, _1), "incoming_transfers [available|unavailable] - Show incoming transfers - all of them or filter them by availability"); m_cmd_binder.set_handler("incoming_counts", boost::bind(&simple_wallet::show_incoming_transfers_counts, this, _1), "incoming_transfers counts"); - m_cmd_binder.set_handler("list_recent_transfers", boost::bind(&simple_wallet::list_recent_transfers, this, _1), "list_recent_transfers - Show recent maximum 1000 transfers"); + m_cmd_binder.set_handler("list_recent_transfers", boost::bind(&simple_wallet::list_recent_transfers, this, _1), "list_recent_transfers [offset] [count] - Show recent maximum 1000 transfers, offset default = 0, count default = 100 "); m_cmd_binder.set_handler("export_recent_transfers", boost::bind(&simple_wallet::export_recent_transfers, this, _1), "list_recent_transfers_tx - Write recent transfer in json to wallet_recent_transfers.txt"); m_cmd_binder.set_handler("list_outputs", boost::bind(&simple_wallet::list_outputs, this, _1), "list_outputs [spent|unspent] - Lists all the outputs that have ever been sent to this wallet if called without arguments, otherwise it lists only the spent or unspent outputs"); m_cmd_binder.set_handler("dump_transfers", boost::bind(&simple_wallet::dump_trunsfers, this, _1), "dump_transfers - Write transfers in json to dump_transfers.txt"); @@ -766,9 +766,15 @@ bool simple_wallet::list_recent_transfers(const std::vector& args) { std::vector unconfirmed; std::vector recent; + uint64_t offset = 0; + if (args.size() > 0) + offset = std::stoll(args[0]); + uint64_t count = 1000; + if (args.size() > 1) + count = std::stoll(args[1]); uint64_t total = 0; uint64_t last_index = 0; - m_wallet->get_recent_transfers_history(recent, std::stoll(args[0]), std::stoll(args[1]), total, last_index, false, false); + m_wallet->get_recent_transfers_history(recent, offset, count, total, last_index, false, false); m_wallet->get_unconfirmed_transfers(unconfirmed, false); //workaround for missed fee From a14cda2db60fc8f69890bcbb3a6b854e3f2ca9b0 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 29 Jul 2021 22:32:46 +0200 Subject: [PATCH 63/83] improved json rpc lib and logging lib --- contrib/epee/include/misc_log_ex.h | 36 +++++++++++++------ .../include/storages/http_abstract_invoke.h | 21 ++++++++++- tests/performance_tests/main.cpp | 12 +++++++ 3 files changed, 57 insertions(+), 12 deletions(-) diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h index b8749cd7..d7599ed2 100644 --- a/contrib/epee/include/misc_log_ex.h +++ b/contrib/epee/include/misc_log_ex.h @@ -132,11 +132,11 @@ DISABLE_VS_WARNINGS(4100) #define LOG_PRINT_CHANNEL_NO_POSTFIX2(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ {TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x; epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);CATCH_ALL_DO_NOTHING();}} -#define LOG_PRINT_CHANNEL2(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ - {TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);CATCH_ALL_DO_NOTHING();}} +#define LOG_PRINT_CHANNEL2_CB(log_channel, log_name, x, y, cb) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ + {TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);cb(ss________.str());CATCH_ALL_DO_NOTHING();}} -#define LOG_PRINT_CHANNEL_COLOR2(log_channel, log_name, x, y, color) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ - {TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, color, false, log_name);CATCH_ALL_DO_NOTHING();}} +#define LOG_PRINT_CHANNEL_COLOR2_CB(log_channel, log_name, x, y, color, cb) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ + {TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, color, false, log_name); cb(ss________.str());CATCH_ALL_DO_NOTHING();}} #define LOG_PRINT_CHANNEL_2_JORNAL(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ {TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, true, log_name);CATCH_ALL_DO_NOTHING();}} @@ -145,6 +145,8 @@ DISABLE_VS_WARNINGS(4100) TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << "[ERROR] Location: " << std::endl << LOCATION_SS << epee::misc_utils::get_callstack() << " Message:" << std::endl << x << std::endl; epee::log_space::log_singletone::do_log_message(ss________.str(), LOG_LEVEL_0, epee::log_space::console_color_red, true, log_name); LOCAL_ASSERT(0); epee::log_space::increase_error_count(LOG_DEFAULT_CHANNEL); cb(ss________.str()); CATCH_ALL_DO_NOTHING();} #define LOG_ERROR2(log_name, x) LOG_ERROR2_CB(log_name, x, epee::log_space::log_stub) +#define LOG_PRINT_CHANNEL2(log_channel, log_name, x, y) LOG_PRINT_CHANNEL2_CB(log_channel, log_name, x, y, epee::log_space::log_stub) +#define LOG_PRINT_CHANNEL_COLOR2(log_channel, log_name, x, y, color) LOG_PRINT_CHANNEL_COLOR2_CB(log_channel, log_name, x, y, color, epee::log_space::log_stub) #define LOG_FRAME2(log_name, x, y) epee::log_space::log_frame frame(x, y, log_name) @@ -165,7 +167,9 @@ DISABLE_VS_WARNINGS(4100) #define LOG_PRINT_NO_PREFIX_NO_POSTFIX2(log_name, x, y) LOG_PRINT_CHANNEL_NO_PREFIX_NO_POSTFIX2(LOG_DEFAULT_CHANNEL, log_name, x, y) #define LOG_PRINT_NO_POSTFIX2(log_name, x, y) LOG_PRINT_CHANNEL_NO_POSTFIX2(LOG_DEFAULT_CHANNEL, log_name, x, y) #define LOG_PRINT2(log_name, x, y) LOG_PRINT_CHANNEL2(LOG_DEFAULT_CHANNEL, log_name, x, y) +#define LOG_PRINT2_CB(log_name, x, y, cb) LOG_PRINT_CHANNEL2_CB(LOG_DEFAULT_CHANNEL, log_name, x, y, cb) #define LOG_PRINT_COLOR2(log_name, x, y, color) LOG_PRINT_CHANNEL_COLOR2(LOG_DEFAULT_CHANNEL, log_name, x, y, color) +#define LOG_PRINT_COLOR2_CB(log_name, x, y, color, cb) LOG_PRINT_CHANNEL_COLOR2_CB(LOG_DEFAULT_CHANNEL, log_name, x, y, color, cb) #define LOG_PRINT2_JORNAL(log_name, x, y) LOG_PRINT_CHANNEL_2_JORNAL(LOG_DEFAULT_CHANNEL, log_name, x, y) #ifndef LOG_DEFAULT_TARGET @@ -175,15 +179,25 @@ DISABLE_VS_WARNINGS(4100) #define LOG_PRINT_NO_POSTFIX(mess, level) LOG_PRINT_NO_POSTFIX2(LOG_DEFAULT_TARGET, mess, level) #define LOG_PRINT_NO_PREFIX(mess, level) LOG_PRINT_NO_PREFIX2(LOG_DEFAULT_TARGET, mess, level) #define LOG_PRINT_NO_PREFIX_NO_POSTFIX(mess, level) LOG_PRINT_NO_PREFIX_NO_POSTFIX2(LOG_DEFAULT_TARGET, mess, level) -#define LOG_PRINT(mess, level) LOG_PRINT2(LOG_DEFAULT_TARGET, mess, level) +#define LOG_PRINT(mess, level) LOG_PRINT2(LOG_DEFAULT_TARGET, mess, level) +#define LOG_PRINT_CB(mess, level, cb) LOG_PRINT2_CB(LOG_DEFAULT_TARGET, mess, level, cb) +#define LOG_PRINT_COLOR_CB(mess, level, color, cb) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, color, cb) + +#define LOG_COLOR_RED epee::log_space::console_color_red +#define LOG_COLOR_GREEN epee::log_space::console_color_green +#define LOG_COLOR_BLUE epee::log_space::console_color_blue +#define LOG_COLOR_YELLOW epee::log_space::console_color_yellow +#define LOG_COLOR_CYAN epee::log_space::console_color_cyan +#define LOG_COLOR_MAGENTA epee::log_space::console_color_magenta + #define LOG_PRINT_COLOR(mess, level, color) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, color) -#define LOG_PRINT_RED(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_red) -#define LOG_PRINT_GREEN(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_green) -#define LOG_PRINT_BLUE(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_blue) -#define LOG_PRINT_YELLOW(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_yellow) -#define LOG_PRINT_CYAN(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_cyan) -#define LOG_PRINT_MAGENTA(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_magenta) +#define LOG_PRINT_RED(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, LOG_COLOR_RED) +#define LOG_PRINT_GREEN(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, LOG_COLOR_GREEN) +#define LOG_PRINT_BLUE(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, LOG_COLOR_BLUE) +#define LOG_PRINT_YELLOW(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, LOG_COLOR_YELLOW) +#define LOG_PRINT_CYAN(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, LOG_COLOR_CYAN) +#define LOG_PRINT_MAGENTA(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, ) #define LOG_PRINT_RED_L0(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_red) #define LOG_PRINT_GREEN_L0(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_green) diff --git a/contrib/epee/include/storages/http_abstract_invoke.h b/contrib/epee/include/storages/http_abstract_invoke.h index 5305c543..0b6ef8e3 100644 --- a/contrib/epee/include/storages/http_abstract_invoke.h +++ b/contrib/epee/include/storages/http_abstract_invoke.h @@ -94,9 +94,28 @@ namespace epee return serialization::load_t_from_binary(result_struct, pri->m_body); } + + template + bool invoke_http_json_rpc(const std::string& url, const std::string& method_name, const t_request& out_struct, t_response& result_struct, t_transport& transport, epee::json_rpc::error& err, unsigned int timeout = 5000, const std::string& http_method = "GET", const std::string& req_id = "0") + { + epee::json_rpc::request req_t = AUTO_VAL_INIT(req_t); + req_t.jsonrpc = "2.0"; + req_t.id = req_id; + req_t.method = method_name; + req_t.params = out_struct; + epee::json_rpc::response resp_t = AUTO_VAL_INIT(resp_t); + if (!epee::net_utils::invoke_http_json_remote_command2(url, req_t, resp_t, transport, timeout, http_method)) + { + return false; + } + err = resp_t.error; + result_struct = resp_t.result; + return true; + } + template bool invoke_http_json_rpc(const std::string& url, const std::string& method_name, const t_request& out_struct, t_response& result_struct, t_transport& transport, unsigned int timeout = 5000, const std::string& http_method = "GET", const std::string& req_id = "0") - { + { epee::json_rpc::request req_t = AUTO_VAL_INIT(req_t); req_t.jsonrpc = "2.0"; req_t.id = req_id; diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index df60b58e..c3f0a77a 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -33,8 +33,20 @@ int main(int argc, char** argv) epee::log_space::log_singletone::get_default_log_file().c_str(), epee::log_space::log_singletone::get_default_log_folder().c_str()); + + std::string buf1 = tools::get_varint_data(CURRENCY_PUBLIC_ADDRESS_BASE58_PREFIX); + std::string buf2 = tools::get_varint_data(CURRENCY_PUBLIC_INTEG_ADDRESS_BASE58_PREFIX); + std::string buf3 = tools::get_varint_data(CURRENCY_PUBLIC_INTEG_ADDRESS_V2_BASE58_PREFIX); + std::string buf4 = tools::get_varint_data(CURRENCY_PUBLIC_AUDITABLE_ADDRESS_BASE58_PREFIX); + std::string buf5 = tools::get_varint_data(CURRENCY_PUBLIC_AUDITABLE_INTEG_ADDRESS_BASE58_PREFIX); + std::cout << "Buf1: " << epee::string_tools::buff_to_hex_nodelimer(buf1) << ENDL; + std::cout << "Buf2: " << epee::string_tools::buff_to_hex_nodelimer(buf2) << ENDL; + std::cout << "Buf3: " << epee::string_tools::buff_to_hex_nodelimer(buf3) << ENDL; + std::cout << "Buf4: " << epee::string_tools::buff_to_hex_nodelimer(buf4) << ENDL; + std::cout << "Buf5: " << epee::string_tools::buff_to_hex_nodelimer(buf5) << ENDL; + do_htlc_hash_tests(); //run_serialization_performance_test(); //return 1; From 11ef353281a0ed13b29f522f100460e73477539d Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 29 Jul 2021 22:35:36 +0200 Subject: [PATCH 64/83] forgoten magenta --- contrib/epee/include/misc_log_ex.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h index d7599ed2..64c2973d 100644 --- a/contrib/epee/include/misc_log_ex.h +++ b/contrib/epee/include/misc_log_ex.h @@ -197,7 +197,7 @@ DISABLE_VS_WARNINGS(4100) #define LOG_PRINT_BLUE(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, LOG_COLOR_BLUE) #define LOG_PRINT_YELLOW(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, LOG_COLOR_YELLOW) #define LOG_PRINT_CYAN(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, LOG_COLOR_CYAN) -#define LOG_PRINT_MAGENTA(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, ) +#define LOG_PRINT_MAGENTA(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, LOG_COLOR_MAGENTA) #define LOG_PRINT_RED_L0(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_red) #define LOG_PRINT_GREEN_L0(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_green) From 3222d51490a83c4d2dcddd045ff17cf38acc9749 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 29 Jul 2021 22:40:42 +0200 Subject: [PATCH 65/83] forgoten LOG_PRINT_COLOR2_CB --- contrib/epee/include/misc_log_ex.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h index 64c2973d..0b957a5f 100644 --- a/contrib/epee/include/misc_log_ex.h +++ b/contrib/epee/include/misc_log_ex.h @@ -182,7 +182,7 @@ DISABLE_VS_WARNINGS(4100) #define LOG_PRINT(mess, level) LOG_PRINT2(LOG_DEFAULT_TARGET, mess, level) #define LOG_PRINT_CB(mess, level, cb) LOG_PRINT2_CB(LOG_DEFAULT_TARGET, mess, level, cb) -#define LOG_PRINT_COLOR_CB(mess, level, color, cb) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, color, cb) +#define LOG_PRINT_COLOR_CB(mess, level, color, cb) LOG_PRINT_COLOR2_CB(LOG_DEFAULT_TARGET, mess, level, color, cb) #define LOG_COLOR_RED epee::log_space::console_color_red #define LOG_COLOR_GREEN epee::log_space::console_color_green From 2efc46ed0998c092e5afb2dabd68cc967042c503 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 7 Aug 2021 22:01:00 +0200 Subject: [PATCH 66/83] address validation for wrap --- src/wallet/wallets_manager.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index eb101997..0d3c9f6b 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1753,7 +1753,11 @@ std::string wallets_manager::get_offers_ex(const bc_services::core_offers_filter std::string wallets_manager::validate_address(const std::string& addr_str, std::string& payment_id) { currency::account_public_address acc = AUTO_VAL_INIT(acc); - if (currency::get_account_address_and_payment_id_from_str(acc, payment_id, addr_str)) + if (is_address_like_wrapped(addr_str)) + { + return API_RETURN_CODE_TRUE; + } + else if (currency::get_account_address_and_payment_id_from_str(acc, payment_id, addr_str)) return API_RETURN_CODE_TRUE; else return API_RETURN_CODE_FALSE; From cb1be3e31c54f7513f611ad41e002863ce76751b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 7 Aug 2021 22:16:12 +0200 Subject: [PATCH 67/83] fixed missing namespace --- src/wallet/wallets_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 0d3c9f6b..4dbba747 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1753,7 +1753,7 @@ std::string wallets_manager::get_offers_ex(const bc_services::core_offers_filter std::string wallets_manager::validate_address(const std::string& addr_str, std::string& payment_id) { currency::account_public_address acc = AUTO_VAL_INIT(acc); - if (is_address_like_wrapped(addr_str)) + if (currency::is_address_like_wrapped(addr_str)) { return API_RETURN_CODE_TRUE; } From 2ed87ff148f6613b39b068d0e7035844fe5ac021 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 17 Aug 2021 12:12:20 +0200 Subject: [PATCH 68/83] added wrap address support in mobile wallet --- src/wallet/plain_wallet_api.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 4b8a8fd6..b2f31850 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -367,15 +367,30 @@ namespace plain_wallet currency::account_public_address apa = AUTO_VAL_INIT(apa); currency::payment_id_t pid = AUTO_VAL_INIT(pid); bool valid = false; - if(currency::get_account_address_and_payment_id_from_str(apa, pid, addr)) + bool wrap = false; + while (true) { - valid = true; + if (currency::is_address_like_wrapped(addr)) + { + wrap = true; + valid = true; + break; + } + + if (currency::get_account_address_and_payment_id_from_str(apa, pid, addr)) + { + valid = true; + } + break; } + //lazy to make struct for it std::stringstream res; res << "{ \"valid\": " << (valid?"true":"false") << ", \"auditable\": " << (apa.is_auditable() ? "true" : "false") - << ",\"payment_id\": " << (pid.size() ? "true" : "false") << "}"; + << ",\"payment_id\": " << (pid.size() ? "true" : "false") + << ",\"wrap\": " << (wrap ? "true" : "false") + << "}"; return res.str(); } From 580f354c1c7a8629a55755f13b64d8c2b4d939bc Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 21 Aug 2021 08:14:57 +0200 Subject: [PATCH 69/83] added wrap support to plain_wallet --- src/wallet/wallet_rpc_server.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index aca13701..dd11b4ba 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -16,6 +16,7 @@ using namespace epee; #include "crypto/hash.h" #include "wallet_rpc_server_error_codes.h" #include "wallet_helpers.h" +#include "wrap_service.h" #define WALLET_RPC_BEGIN_TRY_ENTRY() try { #define WALLET_RPC_CATCH_TRY_ENTRY() } \ @@ -303,7 +304,24 @@ namespace tools currency::tx_destination_entry de; de.addr.resize(1); std::string embedded_payment_id; - if(!m_wallet.get_transfer_address(it->address, de.addr.back(), embedded_payment_id)) + //check if address looks like wrapped address + if (currency::is_address_like_wrapped(it->address)) + { + LOG_PRINT_L0("Address " << it->address << " recognized as wrapped address, creating wrapping transaction..."); + //put into service attachment specially encrypted entry which will contain wrap address and network + currency::tx_service_attachment sa = AUTO_VAL_INIT(sa); + sa.service_id = BC_WRAP_SERVICE_ID; + sa.instruction = BC_WRAP_SERVICE_INSTRUCTION_ERC20; + sa.flags = TX_SERVICE_ATTACHMENT_ENCRYPT_BODY | TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE; + sa.body = it->address; + ctp.extra.push_back(sa); + + currency::account_public_address acc = AUTO_VAL_INIT(acc); + currency::get_account_address_from_str(acc, BC_WRAP_SERVICE_CUSTODY_WALLET); + de.addr.front() = acc; + //encrypt body with a special way + } + else if(!m_wallet.get_transfer_address(it->address, de.addr.back(), embedded_payment_id)) { er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS; er.message = std::string("WALLET_RPC_ERROR_CODE_WRONG_ADDRESS: ") + it->address; From 69eb2dc38aaa20fcf1b0b815554c05bc877db7ed Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 21 Aug 2021 19:51:01 +0200 Subject: [PATCH 70/83] added wrap address detection support in UI --- src/common/error_codes.h | 1 + src/wallet/wallets_manager.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/error_codes.h b/src/common/error_codes.h index 648bd6fd..7b77fec3 100644 --- a/src/common/error_codes.h +++ b/src/common/error_codes.h @@ -40,3 +40,4 @@ #define API_RETURN_CODE_TX_IS_TOO_BIG "TX_IS_TOO_BIG" #define API_RETURN_CODE_TX_REJECTED "TX_REJECTED" #define API_RETURN_CODE_HTLC_ORIGIN_HASH_MISSMATCHED "HTLC_ORIGIN_HASH_MISSMATCHED" +#define API_RETURN_CODE_WRAP "WRAP" \ No newline at end of file diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 4dbba747..6d8d6456 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1755,7 +1755,7 @@ std::string wallets_manager::validate_address(const std::string& addr_str, std:: currency::account_public_address acc = AUTO_VAL_INIT(acc); if (currency::is_address_like_wrapped(addr_str)) { - return API_RETURN_CODE_TRUE; + return API_RETURN_CODE_WRAP; } else if (currency::get_account_address_and_payment_id_from_str(acc, payment_id, addr_str)) return API_RETURN_CODE_TRUE; From 9447de6c963bdc6c08e68938ebb304823bb00482 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 25 Aug 2021 20:39:33 +0200 Subject: [PATCH 71/83] added proper handling of wrpa transactions in simplewallet --- src/common/general_purpose_commands_defs.h | 40 ++++++++++++ src/simplewallet/simplewallet.cpp | 74 +++++++++++++++++++--- src/simplewallet/simplewallet.h | 1 + 3 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 src/common/general_purpose_commands_defs.h diff --git a/src/common/general_purpose_commands_defs.h b/src/common/general_purpose_commands_defs.h new file mode 100644 index 00000000..f9da9968 --- /dev/null +++ b/src/common/general_purpose_commands_defs.h @@ -0,0 +1,40 @@ +// Copyright (c) 2014-2018 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#pragma once +#include "serialization/keyvalue_hexemizer.h" +#include "currency_core/currency_basic.h" +#include "storages/portable_storage_base.h" +#include "currency_core/basic_api_response_codes.h" +#include "common/error_codes.h" +namespace currency +{ + //----------------------------------------------- + + + struct tx_cost_struct + { + std::string usd_needed_for_erc20; + std::string zano_needed_for_erc20; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(usd_needed_for_erc20) + KV_SERIALIZE(zano_needed_for_erc20) + END_KV_SERIALIZE_MAP() + }; + + struct rpc_get_wrap_info_response + { + std::string unwraped_coins_left; + tx_cost_struct tx_cost; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(unwraped_coins_left) + KV_SERIALIZE(tx_cost) + END_KV_SERIALIZE_MAP() + }; + + +} + diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index c72242d3..5ca38d56 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -21,7 +21,7 @@ #include "version.h" #include "string_coding.h" #include "wallet/wrap_service.h" - +#include "common/general_purpose_commands_defs.h" #include #if defined(WIN32) @@ -1176,6 +1176,52 @@ bool simple_wallet::show_wallet_bcheight(const std::vector& args) return true; } //---------------------------------------------------------------------------------------------------- +bool simple_wallet::validate_wrap_status(uint64_t amount) +{ + //check if amount is fit erc20 fees and amount left in circulation + epee::net_utils::http::http_simple_client http_client; + + currency::void_struct req = AUTO_VAL_INIT(req); + currency::rpc_get_wrap_info_response res = AUTO_VAL_INIT(res); + bool r = epee::net_utils::invoke_http_json_remote_command2("http://wrapped.zano.org/api/get_wrap_info", req, res, http_client, 10000); + if (!r) + { + fail_msg_writer() << "Failed to request wrap status from server, check internet connection"; + return false; + } + //check if amount is bigger then erc20 fee + uint64_t zano_needed_for_wrap = std::stoll(res.tx_cost.zano_needed_for_erc20); + if (amount <= zano_needed_for_wrap) + { + fail_msg_writer() << "Too small amount to cover ERC20 fee. ERC20 cost is: " + << print_money(zano_needed_for_wrap) << " Zano" << + "($" << res.tx_cost.usd_needed_for_erc20 << ")"; + return false; + } + uint64_t unwrapped_coins_left = std::stoll(res.unwraped_coins_left); + if (amount > unwrapped_coins_left) + { + fail_msg_writer() << "Amount is bigger than ERC20 tokens left available: " + << print_money(unwrapped_coins_left) << " wZano"; + return false; + } + + success_msg_writer(false) << "You'll receive estimate " << print_money(amount - zano_needed_for_wrap) << " wZano (" << print_money(zano_needed_for_wrap)<< " Zano will be used to cover ERC20 fee)"; + success_msg_writer(false) << "Proceed? (yes/no)"; + while (true) + { + std::string user_response; + std::getline(std::cin, user_response); + if (user_response == "yes" || user_response == "y") + return true; + else if (user_response == "no" || user_response == "n") + return false; + else { + success_msg_writer(false) << "Wrong response, can be \"yes\" or \"no\""; + } + } +} +//---------------------------------------------------------------------------------------------------- bool simple_wallet::transfer(const std::vector &args_) { if (!try_connect_to_daemon()) @@ -1223,10 +1269,26 @@ bool simple_wallet::transfer(const std::vector &args_) std::string integrated_payment_id; currency::tx_destination_entry de; de.addr.resize(1); + + bool ok = currency::parse_amount(de.amount, local_args[i + 1]); + if (!ok || 0 == de.amount) + { + fail_msg_writer() << "amount is wrong: " << local_args[i] << ' ' << local_args[i + 1] << + ", expected number from 0 to " << print_money(std::numeric_limits::max()); + return true; + } + //check if address looks like wrapped address if (is_address_like_wrapped(local_args[i])) { - success_msg_writer(true) << "Address " << local_args[i] << " recognized as wrapped address, creating wrapping transaction..."; + + success_msg_writer(false) << "Address " << local_args[i] << " recognized as wrapped address, creating wrapping transaction."; + success_msg_writer(false) << "This transaction will create wZano (\"Wrapped Zano\") which will be sent to the specified address on the Ethereum network."; + + if (!validate_wrap_status(de.amount)) + { + return true; + } //put into service attachment specially encrypted entry which will contain wrap address and network tx_service_attachment sa = AUTO_VAL_INIT(sa); sa.service_id = BC_WRAP_SERVICE_ID; @@ -1252,14 +1314,6 @@ bool simple_wallet::transfer(const std::vector &args_) return true; } - bool ok = currency::parse_amount(de.amount, local_args[i + 1]); - if(!ok || 0 == de.amount) - { - fail_msg_writer() << "amount is wrong: " << local_args[i] << ' ' << local_args[i + 1] << - ", expected number from 0 to " << print_money(std::numeric_limits::max()); - return true; - } - if (integrated_payment_id.size() != 0) { if (payment_id.size() != 0) diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 156da7c8..35f99128 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -86,6 +86,7 @@ namespace currency bool sign_transfer(const std::vector &args); bool submit_transfer(const std::vector &args); bool sweep_below(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); bool get_transfer_address(const std::string& adr_str, currency::account_public_address& addr); From 506bf42632d8c2dace3c06bdb90c2cc9c20afa2e Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 25 Aug 2021 22:43:08 +0200 Subject: [PATCH 72/83] added send wrapped transaction to desktop UI --- src/simplewallet/simplewallet.cpp | 9 +++++++++ src/wallet/wallet_rpc_server.cpp | 11 ++++++++++- src/wallet/wallets_manager.cpp | 33 +++++++++++++++++++++++++------ 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index c72242d3..72d08b14 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -1226,6 +1226,11 @@ bool simple_wallet::transfer(const std::vector &args_) //check if address looks like wrapped address if (is_address_like_wrapped(local_args[i])) { + if (wrapped_transaction) + { + fail_msg_writer() << "Second wrap entry not allowed in one tx"; + return true; + } success_msg_writer(true) << "Address " << local_args[i] << " recognized as wrapped address, creating wrapping transaction..."; //put into service attachment specially encrypted entry which will contain wrap address and network tx_service_attachment sa = AUTO_VAL_INIT(sa); @@ -1273,6 +1278,10 @@ bool simple_wallet::transfer(const std::vector &args_) dsts.push_back(de); } + if (wrapped_transaction) + { + currency::create_and_add_tx_payer_to_container_from_address(extra, m_wallet->get_account().get_keys().account_address, m_wallet->get_top_block_height(), m_wallet->get_core_runtime_config()); + } std::vector attachments; if (!payment_id.empty() && !set_payment_id_to_tx(attachments, payment_id)) diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index dd11b4ba..24c43f66 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -298,6 +298,7 @@ namespace tools //put it to attachments ctp.attachments.insert(ctp.extra.end(), req.service_entries.begin(), req.service_entries.end()); } + bool wrap = false; std::vector& dsts = ctp.dsts; for (auto it = req.destinations.begin(); it != req.destinations.end(); it++) { @@ -307,6 +308,13 @@ namespace tools //check if address looks like wrapped address if (currency::is_address_like_wrapped(it->address)) { + if (wrap) { + LOG_ERROR("More then one entries in transactions"); + er.code = WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT; + er.message = "Second wrap entry not supported in transactions"; + return false; + + } LOG_PRINT_L0("Address " << it->address << " recognized as wrapped address, creating wrapping transaction..."); //put into service attachment specially encrypted entry which will contain wrap address and network currency::tx_service_attachment sa = AUTO_VAL_INIT(sa); @@ -319,6 +327,7 @@ namespace tools currency::account_public_address acc = AUTO_VAL_INIT(acc); currency::get_account_address_from_str(acc, BC_WRAP_SERVICE_CUSTODY_WALLET); de.addr.front() = acc; + wrap = true; //encrypt body with a special way } else if(!m_wallet.get_transfer_address(it->address, de.addr.back(), embedded_payment_id)) @@ -358,7 +367,7 @@ namespace tools attachments.push_back(comment); } - if (req.push_payer) + if (req.push_payer | wrap) { currency::create_and_add_tx_payer_to_container_from_address(extra, m_wallet.get_account().get_keys().account_address, m_wallet.get_top_block_height(), m_wallet.get_core_runtime_config()); } diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 6d8d6456..86856d90 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -17,6 +17,7 @@ #include "core_default_rpc_proxy.h" #include "common/db_backend_selector.h" #include "common/pre_download.h" +#include "wallet/wrap_service.h" #define GET_WALLET_OPT_BY_ID(wallet_id, name) \ SHARED_CRITICAL_REGION_LOCAL(m_wallets_lock); \ @@ -1323,6 +1324,10 @@ std::string wallets_manager::transfer(size_t wallet_id, const view::transfer_par return API_RETURN_CODE_BAD_ARG_EMPTY_DESTINATIONS; uint64_t fee = tp.fee; + //payment_id + std::vector attachments; + std::vector extra; + bool wrap = false; // if (!currency::parse_amount(fee, tp.fee)) // return API_RETURN_CODE_BAD_ARG_WRONG_FEE; @@ -1331,12 +1336,30 @@ std::string wallets_manager::transfer(size_t wallet_id, const view::transfer_par { dsts.push_back(currency::tx_destination_entry()); dsts.back().addr.resize(1); + currency::tx_destination_entry& de = dsts.back(); std::string embedded_payment_id; - if (!tools::get_transfer_address(d.address, dsts.back().addr.back(), embedded_payment_id, m_rpc_proxy.get())) + if (currency::is_address_like_wrapped(d.address)) + { + CHECK_AND_ASSERT_MES(!wrap, API_RETURN_CODE_BAD_ARG, "Second wrap entry in one tx not allowed"); + LOG_PRINT_L0("Address " << d.address << " recognized as wrapped address, creating wrapping transaction..."); + //put into service attachment specially encrypted entry which will contain wrap address and network + currency::tx_service_attachment sa = AUTO_VAL_INIT(sa); + sa.service_id = BC_WRAP_SERVICE_ID; + sa.instruction = BC_WRAP_SERVICE_INSTRUCTION_ERC20; + sa.flags = TX_SERVICE_ATTACHMENT_ENCRYPT_BODY | TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE; + sa.body = d.address; + extra.push_back(sa); + + currency::account_public_address acc = AUTO_VAL_INIT(acc); + currency::get_account_address_from_str(acc, BC_WRAP_SERVICE_CUSTODY_WALLET); + de.addr.front() = acc; + wrap = true; + } + else if (!tools::get_transfer_address(d.address, dsts.back().addr.back(), embedded_payment_id, m_rpc_proxy.get())) { return API_RETURN_CODE_BAD_ARG_INVALID_ADDRESS; } - if(!currency::parse_amount(dsts.back().amount, d.amount)) + else if(!currency::parse_amount(dsts.back().amount, d.amount)) { return API_RETURN_CODE_BAD_ARG_WRONG_AMOUNT; } @@ -1347,9 +1370,7 @@ std::string wallets_manager::transfer(size_t wallet_id, const view::transfer_par payment_id = embedded_payment_id; } } - //payment_id - std::vector attachments; - std::vector extra; + if (payment_id.size()) { if (!currency::is_payment_id_size_ok(payment_id)) @@ -1381,7 +1402,7 @@ std::string wallets_manager::transfer(size_t wallet_id, const view::transfer_par tc.comment = tp.comment; extra.push_back(tc); } - if (tp.push_payer) + if (tp.push_payer || wrap) { currency::create_and_add_tx_payer_to_container_from_address(extra, w->get()->get_account().get_keys().account_address, w->get()->get_top_block_height(), w->get()->get_core_runtime_config()); } From 8a0bbf785456503fe12649540cc793f8960935b2 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 26 Aug 2021 15:03:42 +0200 Subject: [PATCH 73/83] Fixed bug with amount parsing --- src/wallet/wallets_manager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 86856d90..ce29590e 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1359,7 +1359,9 @@ std::string wallets_manager::transfer(size_t wallet_id, const view::transfer_par { return API_RETURN_CODE_BAD_ARG_INVALID_ADDRESS; } - else if(!currency::parse_amount(dsts.back().amount, d.amount)) + + + if(!currency::parse_amount(dsts.back().amount, d.amount)) { return API_RETURN_CODE_BAD_ARG_WRONG_AMOUNT; } From d7d955c67e87d1d8d81f6a3ecdc4edaf5c5c2570 Mon Sep 17 00:00:00 2001 From: zano build machine Date: Thu, 26 Aug 2021 16:04:42 +0300 Subject: [PATCH 74/83] === build number: 124 -> 125 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index cfee72bd..af5e45d6 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "1" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 124 +#define PROJECT_VERSION_BUILD_NO 125 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 48b4b78e6a094ddd60ecbec5446d71716e7313a2 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 27 Aug 2021 08:38:17 +0200 Subject: [PATCH 75/83] moved UI to wrap --- 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 0d3831a3..9614d4e5 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 0d3831a3e4c13ab3016aca26d40d01f9e87c7282 +Subproject commit 9614d4e5f758d3d5ea305ea0c5417ede5863c306 From c44972102e9c560e61711b662a0857d67423a464 Mon Sep 17 00:00:00 2001 From: zano build machine Date: Fri, 27 Aug 2021 09:40:20 +0300 Subject: [PATCH 76/83] === build number: 125 -> 126 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index af5e45d6..4034021d 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "1" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 125 +#define PROJECT_VERSION_BUILD_NO 126 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 1e0a58097ac20ed659c6cd825afa26ac168cfbad Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 27 Aug 2021 20:16:59 +0200 Subject: [PATCH 77/83] moved layout to latest commit with fixes --- 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 9614d4e5..62be79e2 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 9614d4e5f758d3d5ea305ea0c5417ede5863c306 +Subproject commit 62be79e2acf4b39f30e88a32d1cd0438fb278c1d From 067d7ff1b2f1e52d7e26d374747ad17ec2c30f58 Mon Sep 17 00:00:00 2001 From: zano build machine Date: Fri, 27 Aug 2021 21:17:44 +0300 Subject: [PATCH 78/83] === build number: 126 -> 127 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 4034021d..b7c74bc7 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "1" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 126 +#define PROJECT_VERSION_BUILD_NO 127 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From cc985ca710b03920fc90fe0f7d1787246945a0fa Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 28 Aug 2021 10:39:26 +0200 Subject: [PATCH 79/83] moved layout to latest commit with fixes: forgotten html --- 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 62be79e2..fd506b56 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 62be79e2acf4b39f30e88a32d1cd0438fb278c1d +Subproject commit fd506b5669624c8deeab901347228c400d9dc89d From 49c05b7158f2a78a1c2c573c6f60b21c1429a8a8 Mon Sep 17 00:00:00 2001 From: zano build machine Date: Sat, 28 Aug 2021 11:42:01 +0300 Subject: [PATCH 80/83] === build number: 127 -> 128 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index b7c74bc7..0b5627f2 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "1" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 127 +#define PROJECT_VERSION_BUILD_NO 128 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 9202483ee1d0304b4d6ef865488c35b66a9da62d Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 2 Sep 2021 20:09:35 +0300 Subject: [PATCH 81/83] switched to production custody wallet --- src/wallet/wrap_service.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wrap_service.h b/src/wallet/wrap_service.h index 0ca52d15..cefbfe6f 100644 --- a/src/wallet/wrap_service.h +++ b/src/wallet/wrap_service.h @@ -10,4 +10,4 @@ #define BC_WRAP_SERVICE_INSTRUCTION_UNWRAP "UNWRAP" //erc20 unwrap operation -#define BC_WRAP_SERVICE_CUSTODY_WALLET "aZxaszi4TaDCUqRCmqe23HASryshQNHmBSFnUN1pY8VsRfss2ZSMGBpLhdFtHgKmFr353NneaYRT6CpSz7zA3EC9bocQcq7m9nP" \ No newline at end of file +#define BC_WRAP_SERVICE_CUSTODY_WALLET "aZxb34VSFPwPJMHReeD4FEhrkUtCgZPQ3aXpMkgFuw6sdSWtph298W55Tn68pkRVFKEx2Kq7rKxyuSqntY8BDrRm8fxyMzVjyYj" \ No newline at end of file From d98fea3a62b698de9aac33a79d9bc77f966c7344 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 6 Sep 2021 23:49:05 +0300 Subject: [PATCH 82/83] removed sender address in wrap operations --- src/wallet/wallet_rpc_server.cpp | 2 +- src/wallet/wallets_manager.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 24c43f66..159427c6 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -367,7 +367,7 @@ namespace tools attachments.push_back(comment); } - if (req.push_payer | wrap) + if (req.push_payer ) { currency::create_and_add_tx_payer_to_container_from_address(extra, m_wallet.get_account().get_keys().account_address, m_wallet.get_top_block_height(), m_wallet.get_core_runtime_config()); } diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index ce29590e..e49ff164 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1404,7 +1404,7 @@ std::string wallets_manager::transfer(size_t wallet_id, const view::transfer_par tc.comment = tp.comment; extra.push_back(tc); } - if (tp.push_payer || wrap) + if (tp.push_payer) { currency::create_and_add_tx_payer_to_container_from_address(extra, w->get()->get_account().get_keys().account_address, w->get()->get_top_block_height(), w->get()->get_core_runtime_config()); } From fd34430f081175cb56306ed8d5c40313f5190b41 Mon Sep 17 00:00:00 2001 From: zano build machine Date: Tue, 7 Sep 2021 10:50:20 +0300 Subject: [PATCH 83/83] === build number: 124 -> 125 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index cfee72bd..af5e45d6 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "1" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 124 +#define PROJECT_VERSION_BUILD_NO 125 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]"