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() diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h index e0a58617..0b957a5f 100644 --- a/contrib/epee/include/misc_log_ex.h +++ b/contrib/epee/include/misc_log_ex.h @@ -132,17 +132,21 @@ 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();}} -#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_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) @@ -163,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 @@ -173,17 +179,28 @@ 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_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 +#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, 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_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) #define LOG_PRINT_L0(mess) LOG_PRINT(mess, LOG_LEVEL_0) #define LOG_PRINT_L1(mess) LOG_PRINT(mess, LOG_LEVEL_1) @@ -193,6 +210,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) @@ -333,7 +351,8 @@ namespace log_space /* */ /************************************************************************/ #define CONSOLE_DEFAULT_STREAM std::cout - + + inline void log_stub(const std::string& /**/) {} struct delete_ptr { 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); 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; } }; 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/src/common/boost_serialization_helper.h b/src/common/boost_serialization_helper.h index 2ba8a52c..5ad68a05 100644 --- a/src/common/boost_serialization_helper.h +++ b/src/common/boost_serialization_helper.h @@ -12,6 +12,7 @@ + #define CHECK_PROJECT_NAME() std::string project_name = CURRENCY_NAME; ar & project_name; if(!(project_name == CURRENCY_NAME) ) {throw std::runtime_error(std::string("wrong storage file: project name in file: ") + project_name + ", expected: " + CURRENCY_NAME );} 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) + ".."; } 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/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/currency_core/account.h b/src/currency_core/account.h index 305b02e3..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 { @@ -97,6 +99,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 274a2f25..dc973a66 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -383,11 +383,25 @@ namespace currency FIELD(security) FIELD(flags) END_SERIALIZE() + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(service_id) + KV_SERIALIZE(instruction) + KV_SERIALIZE_BLOB_AS_HEX_STRING(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 -#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) + //, @@ -690,6 +704,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_config.h b/src/currency_core/currency_config.h index 1b658a69..bda8f652 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 @@ -223,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 153 +#else #define WALLET_FILE_SERIALIZATION_VERSION (CURRENCY_FORMATION_VERSION+69) - +#endif #define CURRENT_MEMPOOL_ARCHIVE_VER (CURRENCY_FORMATION_VERSION+31) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 7c014f2a..d78ec011 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 = 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(destination_addr) {} void operator()(tx_comment& comment) { @@ -789,6 +793,7 @@ namespace currency } void operator()(tx_service_attachment& sa) { + const std::string original_body = sa.body; if (sa.flags&TX_SERVICE_ATTACHMENT_DEFLATE_BODY) { zlib_helper::pack(sa.body); @@ -796,7 +801,28 @@ 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); + 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 + { + 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 = 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); + } m_was_crypted_entries = true; } } @@ -808,12 +834,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 = null_acc_keys, + const crypto::public_key& tx_onetime_pubkey = null_pkey) : 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 +857,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 && 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(local_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 +931,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 = null_acc_keys, + const crypto::public_key& tx_onetime_pubkey = null_pkey) { - 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 +1017,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, 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; } @@ -969,11 +1031,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 +2950,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_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..9a108417 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_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/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 0d3831a3..fd506b56 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 0d3831a3e4c13ab3016aca26d40d01f9e87c7282 +Subproject commit fd506b5669624c8deeab901347228c400d9dc89d diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 8656eb2c..5ca38d56 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -20,7 +20,8 @@ #include "wallet/wallet_rpc_server.h" #include "version.h" #include "string_coding.h" - +#include "wallet/wrap_service.h" +#include "common/general_purpose_commands_defs.h" #include #if defined(WIN32) @@ -191,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"); @@ -753,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 @@ -765,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, 0, 0, total, last_index, 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 @@ -1169,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()) @@ -1208,13 +1261,48 @@ 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))) + + 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(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; + 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; @@ -1226,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) @@ -1258,13 +1338,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/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); diff --git a/src/version.h.in b/src/version.h.in index cfee72bd..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 124 +#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 "]" 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(); } diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index d0456a00..f8cc2fb6 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -709,6 +709,15 @@ 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); @@ -1238,7 +1247,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 @@ -1654,7 +1663,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 { @@ -2660,18 +2669,25 @@ 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) { // old WALLET_FILE_BINARY_HEADER_VERSION version means no encryption 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 + 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); + WLT_LOG_L0("Detected format: WALLET_FILE_BINARY_HEADER_VERSION_2(need_to_resync=" << need_to_resync << ")"); + } + else + { + WLT_LOG_L0("Unknown wallet body version(" << wbh.m_ver << "), resync initiated."); + need_to_resync = true; } @@ -2679,7 +2695,17 @@ 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("[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() << ")"); if (need_to_resync) @@ -2688,9 +2714,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)); } //---------------------------------------------------------------------------------------------------- @@ -2721,7 +2744,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_2; std::string header_buff((const char*)&wbh, sizeof(wbh)); uint64_t ts = m_core_runtime_config.get_core_time(); @@ -2752,8 +2775,10 @@ void wallet2::store(const std::wstring& path_to_save, const std::string& passwor data_file.flush(); data_file.close(); + 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_L1("Stored successfully to temporary file " << tmp_file_path.string()); + 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 @@ -2782,7 +2807,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 { @@ -3184,28 +3211,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) @@ -4570,7 +4618,7 @@ bool wallet2::extract_offers_from_transfer_entry(size_t i, std::unordered_map& 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); @@ -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 @@ -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: " << ver, 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; } @@ -854,6 +860,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 +950,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; @@ -1056,10 +1063,9 @@ private: } // namespace tools BOOST_CLASS_VERSION(tools::wallet2, WALLET_FILE_SERIALIZATION_VERSION) -BOOST_CLASS_VERSION(tools::wallet_public::wallet_transfer_info, 9) +BOOST_CLASS_VERSION(tools::wallet_public::wallet_transfer_info, 10) BOOST_CLASS_VERSION(tools::wallet2::transfer_details, 3) - namespace boost { namespace serialization @@ -1141,8 +1147,11 @@ namespace boost a & x.comment; a & x.contract; a & x.selected_indicies; - a & x.srv_attachments; + a & x.marketplace_entries; a & x.unlock_time; + if (ver < 10) + return; + a & x.service_entries; } template diff --git a/src/wallet/wallet_chain_shortener.cpp b/src/wallet/wallet_chain_shortener.cpp index 9d30cb5f..e353c1a6 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; 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/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index afcddc49..960516db 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -105,16 +105,19 @@ 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; + uint64_t transfer_internal_index; + //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 +139,8 @@ namespace wallet_public KV_SERIALIZE(tx_type) KV_SERIALIZE(show_sender) KV_SERIALIZE(contract) + KV_SERIALIZE(service_entries) + KV_SERIALIZE(transfer_internal_index) END_KV_SERIALIZE_MAP() }; @@ -254,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) @@ -262,6 +268,7 @@ namespace wallet_public KV_SERIALIZE(transfer_entries_count) KV_SERIALIZE(is_whatch_only) KV_SERIALIZE(utxo_distribution) + KV_SERIALIZE(current_height) END_KV_SERIALIZE_MAP() }; }; @@ -299,6 +306,7 @@ namespace wallet_public uint64_t transfer_entries_count; uint64_t balance; uint64_t unlocked_balance; + uint64_t curent_height; BEGIN_KV_SERIALIZE_MAP() @@ -306,9 +314,14 @@ namespace wallet_public KV_SERIALIZE(transfer_entries_count) KV_SERIALIZE(balance) KV_SERIALIZE(unlocked_balance) + KV_SERIALIZE(curent_height) 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 @@ -329,12 +342,16 @@ 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() KV_SERIALIZE(offset) KV_SERIALIZE(count) KV_SERIALIZE(update_provision_info) KV_SERIALIZE(exclude_mining_txs) + KV_SERIALIZE(exclude_unconfirmed) + KV_SERIALIZE(order) END_KV_SERIALIZE_MAP() }; @@ -379,16 +396,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 71d34fa1..159427c6 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() } \ @@ -208,6 +209,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,12 +247,18 @@ 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) + if (req.offset == 0 && !req.exclude_unconfirmed) 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; } @@ -279,13 +287,50 @@ 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()); + } + bool wrap = false; + std::vector& dsts = ctp.dsts; for (auto it = req.destinations.begin(); it != req.destinations.end(); it++) { 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)) + { + 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); + 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; + wrap = true; + //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; @@ -306,8 +351,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; @@ -322,7 +367,7 @@ namespace tools attachments.push_back(comment); } - if (req.push_payer) + 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()); } @@ -336,10 +381,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 @@ -347,8 +393,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/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() diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index eb101997..e49ff164 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,11 +1336,31 @@ 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)) { return API_RETURN_CODE_BAD_ARG_WRONG_AMOUNT; @@ -1347,9 +1372,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)) @@ -1753,7 +1776,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 (currency::is_address_like_wrapped(addr_str)) + { + 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; else return API_RETURN_CODE_FALSE; diff --git a/src/wallet/wrap_service.h b/src/wallet/wrap_service.h new file mode 100644 index 00000000..cefbfe6f --- /dev/null +++ b/src/wallet/wrap_service.h @@ -0,0 +1,13 @@ +// 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 wrap operation +#define BC_WRAP_SERVICE_INSTRUCTION_UNWRAP "UNWRAP" //erc20 unwrap operation + + +#define BC_WRAP_SERVICE_CUSTODY_WALLET "aZxb34VSFPwPJMHReeD4FEhrkUtCgZPQ3aXpMkgFuw6sdSWtph298W55Tn68pkRVFKEx2Kq7rKxyuSqntY8BDrRm8fxyMzVjyYj" \ No newline at end of file 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 new file mode 100644 index 00000000..e3fadbdb --- /dev/null +++ b/tests/core_tests/isolate_auditable_and_proof.cpp @@ -0,0 +1,125 @@ +// 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 "isolate_auditable_and_proof.h" +#include "wallet/wrap_service.h" +#include "wallet/wallet_rpc_server.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; + std::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| TX_SERVICE_ATTACHMENT_ENCRYPT_ADD_PROOF; + sa.body = "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B"; + extra.push_back(sa); + + currency::account_public_address acc = AUTO_VAL_INIT(acc); + de.addr.front() = auditable_test.get_public_address(); + 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); + //} + + 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); + 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); + 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 true; +} + 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..361abc27 --- /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); + 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; +}; diff --git a/tests/functional_tests/plain_wallet_tests.cpp b/tests/functional_tests/plain_wallet_tests.cpp index f6efe29f..f1f9f36b 100644 --- a/tests/functional_tests/plain_wallet_tests.cpp +++ b/tests/functional_tests/plain_wallet_tests.cpp @@ -40,11 +40,19 @@ 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"); + res = plain_wallet::close_wallet(0); - 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 "; 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;