From b41d87a05159f58d61dfc12ec9eba376158a0fde Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 27 May 2021 13:19:20 +0200 Subject: [PATCH 01/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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 580f354c1c7a8629a55755f13b64d8c2b4d939bc Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 21 Aug 2021 08:14:57 +0200 Subject: [PATCH 15/16] 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 16/16] 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;