diff --git a/CMakeLists.txt b/CMakeLists.txt index dae368fd..63b500de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,11 +13,19 @@ set(VERSION "1.0") # cmake_policy(SET CMP0020 OLD) # endif() -if(CMAKE_SYSTEM_NAME STREQUAL "iOS") - add_definitions(-DIOS_BUILD) +if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android") + add_definitions(-DMOBILE_WALLET_BUILD) + if(CMAKE_SYSTEM_NAME STREQUAL "iOS" ) + add_definitions(-DIOS_BUILD) + endif() + if(CMAKE_SYSTEM_NAME STREQUAL "Android") + add_definitions(-DANDROID_BUILD) + message("Android sdk prefix: ${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}") + message("Android CMAKE_CXX_COMPILER prefix: ${CMAKE_CXX_COMPILER}") + message("Android ANDROID_LD: ${ANDROID_LD}") + endif() endif() - set_property(GLOBAL PROPERTY USE_FOLDERS ON) # build types @@ -30,6 +38,8 @@ else() # multi configurations for MSVC and XCode if(CMAKE_SYSTEM_NAME STREQUAL "iOS") set(CMAKE_CONFIGURATION_TYPES "Release") + elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") + set(CMAKE_CONFIGURATION_TYPES "Debug;Release") else() set(CMAKE_CONFIGURATION_TYPES "Debug;Release") endif() @@ -97,13 +107,13 @@ else() endif() # Since gcc 4.9 the LTO format is non-standard (slim), so we need the gcc-specific ar and ranlib binaries - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.0)) - set(CMAKE_AR "gcc-ar") - set(CMAKE_RANLIB "gcc-ranlib") - elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT APPLE) - set(CMAKE_AR "llvm-ar") - set(CMAKE_RANLIB "llvm-ranlib") - endif() + ##if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.0) AND NOT (MAKE_SYSTEM_NAME STREQUAL "Android")) + ## set(CMAKE_AR "gcc-ar") + ## set(CMAKE_RANLIB "gcc-ranlib") + ##elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT APPLE AND NOT (MAKE_SYSTEM_NAME STREQUAL "Android")) + ## set(CMAKE_AR "llvm-ar") + ## set(CMAKE_RANLIB "llvm-ranlib") + ##endif() if(MINGW) @@ -170,12 +180,21 @@ if(STATIC) set(Boost_USE_STATIC_RUNTIME ON) 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") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") + #set(Boost_INCLUDE_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/boost_1_68_0-clang/include") + #set(Boost_LIBRARY_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/boost_1_68_0-clang/${CMAKE_ANDROID_ARCH_ABI}/lib/") + 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}/") + #link_directories("${Boost_LIBRARY_DIRS}") + 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_LIBRARIES "libboost_system_w.a libboost_filesystem.a libboost_thread.a libboost_timer.a libboost_date_time.a libboost_chrono.a libboost_regex.a libboost_serialization.a libboost_atomic.a libboost_program_options.a libboost_locale.a") + set(Boost_VERSION "PurpleI2PBoost 1.68.0") else() find_package(Boost 1.55 REQUIRED COMPONENTS system filesystem thread timer date_time chrono regex serialization atomic program_options locale) endif() @@ -190,7 +209,7 @@ if(MINGW) set(Boost_LIBRARIES "${Boost_LIBRARIES};ws2_32;mswsock") elseif(NOT MSVC) if(NOT APPLE) - set(Boost_LIBRARIES "${Boost_LIBRARIES};rt") + set(Boost_LIBRARIES "${Boost_LIBRARIES};") if(STATIC) message("NOTICE: Including static ICU libraries") set(Boost_LIBRARIES "${Boost_LIBRARIES};icui18n.a;icuuc.a;icudata.a;dl") diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index 60de2c34..779876a1 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -6,7 +6,7 @@ add_subdirectory(db) add_subdirectory(ethereum) -if(CMAKE_SYSTEM_NAME STREQUAL "iOS") +if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android") message("excluded upnp support for IOS build") return() endif() diff --git a/contrib/db/CMakeLists.txt b/contrib/db/CMakeLists.txt index ad19848c..6f2213b4 100644 --- a/contrib/db/CMakeLists.txt +++ b/contrib/db/CMakeLists.txt @@ -1,6 +1,6 @@ -if(CMAKE_SYSTEM_NAME STREQUAL "iOS") +if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android") message("excluded db support for IOS build") return() endif() diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h index 5e4d9a31..be9f3b61 100644 --- a/contrib/epee/include/misc_log_ex.h +++ b/contrib/epee/include/misc_log_ex.h @@ -113,12 +113,14 @@ DISABLE_VS_WARNINGS(4100) #endif #define LOG_DEFAULT_CHANNEL NULL + #define ENABLE_CHANNEL_BY_DEFAULT(ch_name) \ static bool COMBINE(init_channel, __LINE__) UNUSED_ATTRIBUTE = epee::misc_utils::static_initializer([](){ \ epee::log_space::log_singletone::enable_channel(ch_name); return true; \ }); + #if defined(ENABLE_LOGGING_INTERNAL) #define LOG_PRINT_CHANNEL_NO_PREFIX2(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))\ @@ -365,6 +367,7 @@ namespace log_space inline bool is_stdout_a_tty() { +#ifndef ANDROID_BUILD static std::atomic initialized(false); static std::atomic is_a_tty(false); @@ -379,6 +382,9 @@ namespace log_space } return is_a_tty.load(std::memory_order_relaxed); +#else + return false; +#endif } inline void set_console_color(int color, bool bright) @@ -1150,7 +1156,9 @@ namespace log_space std::set enabled_channels_local = genabled_channels; enabled_channels_local.insert(ch_name); genabled_channels.swap(enabled_channels_local); +#ifndef ANDROID_BUILD std::cout << "log channel '" << ch_name << "' enabled" << std::endl; +#endif } static void disable_channels(const std::string& channels_set) diff --git a/contrib/epee/include/misc_os_dependent.h b/contrib/epee/include/misc_os_dependent.h index c755d70c..c06e5d94 100644 --- a/contrib/epee/include/misc_os_dependent.h +++ b/contrib/epee/include/misc_os_dependent.h @@ -109,14 +109,15 @@ namespace misc_utils #endif } -#if defined(__GNUC__) + +#if defined(__GNUC__) && !defined(__ANDROID__) #include #include #endif inline std::string print_trace_default() { std::stringstream ss; -#if defined(__GNUC__) +#if defined(__GNUC__) && !defined(__ANDROID__) ss << std::endl << "STACK" << std::endl; const size_t max_depth = 100; size_t stack_depth; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b11fa25d..d7ff6954 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -98,17 +98,32 @@ endif() add_library(crypto ${CRYPTO}) -add_library(wallet ${WALLET}) -add_dependencies(wallet version ${PCH_LIB_NAME}) -ENABLE_SHARED_PCH(WALLET) - add_library(currency_core ${CURRENCY_CORE}) add_dependencies(currency_core version ${PCH_LIB_NAME}) ENABLE_SHARED_PCH(CURRENCY_CORE) +if(CMAKE_SYSTEM_NAME STREQUAL "Android" ) + add_library(wallet ${WALLET}) + add_dependencies(wallet version ${PCH_LIB_NAME}) + target_link_libraries(wallet currency_core crypto common zlibstatic ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) +else() + add_library(wallet ${WALLET}) + add_dependencies(wallet version ${PCH_LIB_NAME}) + ENABLE_SHARED_PCH(WALLET) +endif() + + + + + + if(CMAKE_SYSTEM_NAME STREQUAL "iOS") install(TARGETS wallet currency_core crypto common DESTINATION lib) - message("Generating for iOS: finished") + message("Generating install for iOS") + return() +elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") + install(TARGETS wallet currency_core crypto common zlibstatic DESTINATION "${CMAKE_ANDROID_ARCH_ABI}/lib") + message("Generating install for Android") return() endif() @@ -125,7 +140,7 @@ target_link_libraries(currency_core lmdb mdbx) add_executable(daemon ${DAEMON} ${P2P} ${CURRENCY_PROTOCOL}) add_dependencies(daemon version) -target_link_libraries(daemon rpc stratum currency_core crypto common libminiupnpc-static zlibstatic ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) + target_link_libraries(daemon rpc stratum currency_core crypto common libminiupnpc-static zlibstatic ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) ENABLE_SHARED_PCH(DAEMON) ENABLE_SHARED_PCH_EXECUTABLE(daemon) diff --git a/src/common/int-util.h b/src/common/int-util.h index 9eff50be..b60c7d97 100644 --- a/src/common/int-util.h +++ b/src/common/int-util.h @@ -194,11 +194,11 @@ static inline void memcpy_swap64(void *dst, const void *src, size_t n) { } } -#if !defined(BYTE_ORDER) || !defined(LITTLE_ENDIAN) || !defined(BIG_ENDIAN) +#if !defined(__BYTE_ORDER__) || !defined(__ORDER_LITTLE_ENDIAN__) || !defined(__ORDER_BIG_ENDIAN__) static_assert(false, "BYTE_ORDER is undefined. Perhaps, GNU extensions are not enabled"); #endif -#if BYTE_ORDER == LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define SWAP32LE IDENT32 #define SWAP32BE SWAP32 #define swap32le ident32 @@ -217,7 +217,7 @@ static_assert(false, "BYTE_ORDER is undefined. Perhaps, GNU extensions are not e #define memcpy_swap64be memcpy_swap64 #endif -#if BYTE_ORDER == BIG_ENDIAN +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #define SWAP32BE IDENT32 #define SWAP32LE SWAP32 #define swap32be ident32 diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 781d9360..4351ef9c 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -7,7 +7,9 @@ #include "include_base_utils.h" #include -#include +#ifndef ANDROID_BUILD + #include +#endif using namespace epee; #include "print_fixed_point_helper.h" @@ -2678,6 +2680,7 @@ namespace currency return o << "<" << r.n << ":" << r.tx_id << ">"; } //-------------------------------------------------------------------------------- +#ifndef ANDROID_BUILD const std::locale& utf8_get_conversion_locale() { static std::locale loc = boost::locale::generator().generate("en_US.UTF-8"); @@ -2697,6 +2700,7 @@ namespace currency return true; return utf8_to_lower(s).find(utf8_to_lower(match), 0) != std::string::npos; } +#endif //-------------------------------------------------------------------------------- bool operator ==(const currency::transaction& a, const currency::transaction& b) { return currency::get_transaction_hash(a) == currency::get_transaction_hash(b); diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 547c939c..01d08170 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -595,9 +595,11 @@ namespace currency //--------------------------------------------------------------- std::ostream& operator <<(std::ostream& o, const ref_by_id& r); //--------------------------------------------------------------- +#ifndef ANDROID_BUILD std::string utf8_to_upper(const std::string& s); std::string utf8_to_lower(const std::string& s); bool utf8_substring_test_case_insensitive(const std::string& match, const std::string& s); // Returns true is 's' contains 'match' (case-insensitive) +#endif struct difficulties { diff --git a/src/currency_core/offers_services_helpers.cpp b/src/currency_core/offers_services_helpers.cpp index 3be77927..d99bf4de 100644 --- a/src/currency_core/offers_services_helpers.cpp +++ b/src/currency_core/offers_services_helpers.cpp @@ -56,7 +56,11 @@ namespace bc_services //------------------------------------------------------------------ bool order_offers_by_name(const offer_details_ex* a, const offer_details_ex* b) { +#ifndef ANDROID_BUILD return currency::utf8_to_lower(a->target) < currency::utf8_to_lower(b->target); +#else + return false; +#endif } //------------------------------------------------------------------ std::vector gsort_offers_predicates; @@ -146,14 +150,14 @@ namespace bc_services //check category if (!of.category.empty() && o.category.find(of.category) == std::string::npos) return false; - +#ifndef ANDROID_BUILD //check target condition if (of.target.size() && !currency::utf8_substring_test_case_insensitive(of.target, o.target)) return false; if (of.primary.size() && !currency::utf8_substring_test_case_insensitive(of.primary, o.primary)) return false; - +#endif //check payment_types condition (TODO: add more complicated algo here) if (of.payment_types.size()) @@ -169,11 +173,11 @@ namespace bc_services //check target condition if (of.location_country.size() && (of.location_country != o.location_country)) return false; - +#ifndef ANDROID_BUILD //check target condition if (of.location_city.size() && !currency::utf8_substring_test_case_insensitive(of.location_city, o.location_city)) return false; - +#endif //check amount if (of.amount_low_limit && (of.amount_low_limit > o.amount_primary)) return false; @@ -217,12 +221,12 @@ namespace bc_services //-------------------------------------------------------------------------------- bool filter_offers_list(std::list& offers, const bc_services::core_offers_filter& filter, uint64_t current_core_time) { - +#ifndef ANDROID_BUILD //filter offers.remove_if([&](bc_services::offer_details_ex& o) -> bool { return !is_offer_matched_by_filter(o, filter, current_core_time); }); - +#endif //sort CHECK_AND_ASSERT_MES(filter.order_by < gsort_offers_predicates.size(), false, "Wrong cof.order_by value"); auto cb = *gsort_offers_predicates[static_cast(filter.order_by)]; diff --git a/src/currency_core/offers_services_helpers.h b/src/currency_core/offers_services_helpers.h index a6182d11..fc2203fb 100644 --- a/src/currency_core/offers_services_helpers.h +++ b/src/currency_core/offers_services_helpers.h @@ -191,8 +191,21 @@ namespace bc_services inline double extract_rate(const odeh& v) { return calculate_offer_rate(v); } inline size_t extract_payment_types(const odeh& v) { return v.payment_types.size(); } inline std::string extract_contacts(const odeh& v) { return v.contacts; } - inline std::string extract_location(const odeh& v) { return currency::utf8_to_lower(v.location_country + v.location_city); } - inline std::string extract_name(const odeh& v) { return currency::utf8_to_lower(v.target); } + inline std::string extract_location(const odeh& v) { + +#ifndef ANDROID_BUILD + return currency::utf8_to_lower(v.location_country + v.location_city); +#else + return "UNSUPORTED"; +#endif + } + inline std::string extract_name(const odeh& v) { +#ifndef ANDROID_BUILD + return currency::utf8_to_lower(v.target); +#else + return "UNSUPORTED"; +#endif + } template struct sort_id_to_type diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 8a2c2165..58d83782 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -8,55 +8,51 @@ #include "currency_core/currency_config.h" #include "version.h" #include "currency_core/currency_format_utils.h" -//#include "wallets_manager.h" +#include "wallets_manager.h" -//TODO: global objects, need refactoring. Just temporary solution -std::map ginstances; -epee::critical_section ginstances_lock; -std::atomic gcounter(1); - std::atomic glogs_initialized(false); +std::atomic initialized(false); +#define ANDROID_PACKAGE_NAME "com.zano_mobile" +#ifdef IOS_BUILD #define HOME_FOLDER "Documents" +#elif ANDROID_BUILD +#define HOME_FOLDER "files" +#endif #define WALLETS_FOLDER_NAME "wallets" #define GENERAL_INTERNAL_ERRROR_INSTANCE "GENERAL_INTERNAL_ERROR: WALLET INSTNACE NOT FOUND" - -#define GET_INSTANCE(var_name, instance_handle) plain_wallet_api_impl* var_name = nullptr;\ - CRITICAL_REGION_BEGIN(ginstances_lock);\ - auto it = ginstances.find(instance_handle);\ - if (it == ginstances.end())\ - {\ - LOG_ERROR("Internall error: attempt to get instance wallet with wrong id: " << instance_handle);\ - return GENERAL_INTERNAL_ERRROR_INSTANCE;\ - }\ - var_name = it->second;\ - CRITICAL_REGION_END(); - +#define GENERAL_INTERNAL_ERRROR_INIT "Failed to intialize library" //TODO: global object, subject to refactoring -//wallets_manager gwm; +wallets_manager gwm; namespace plain_wallet { + typedef epee::json_rpc::response error_response; + std::string get_bundle_root_dir() { +#ifdef WIN32 + return ""; +#endif // WIN32 +#ifdef IOS_BUILD char* env = getenv("HOME"); return env ? env : ""; +#elif ANDROID_BUILD + /// data/data/com.zano_mobile/files + return "/data/data/" ANDROID_PACKAGE_NAME; +#endif } std::string get_wallets_folder() { - std::string path = get_bundle_root_dir() + "/" + HOME_FOLDER + "/" + WALLETS_FOLDER_NAME; - boost::system::error_code ec; - boost::filesystem::create_directories(path, ec); +#ifdef WIN32 + return ""; +#endif // WIN32 + std::string path = get_bundle_root_dir() + "/" + HOME_FOLDER + "/" + WALLETS_FOLDER_NAME + "/"; return path; } - std::string print_money(int64_t amount) - { - return currency::print_money(amount); - } - void initialize_logs() { std::string log_dir = get_bundle_root_dir(); @@ -64,11 +60,48 @@ namespace plain_wallet epee::log_space::get_set_log_detalisation_level(true, LOG_LEVEL_2); epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL); epee::log_space::log_singletone::add_logger(LOGGER_FILE, "plain_wallet.log", log_dir.c_str()); - LOG_PRINT_L0("Plain wallet initialized: " << CURRENCY_NAME << " v" << PROJECT_VERSION_LONG << ", log location: " << log_dir + "/plain_wallet.log"); + LOG_PRINT_L0("Plain wallet initialized: " << CURRENCY_NAME << " v" << PROJECT_VERSION_LONG << ", log location: " << log_dir + "/plain_wallet.log"); - glogs_initialized = true; + //glogs_initialized = true; } + std::string init(const std::string& ip, const std::string& port) + { + if (initialized) + { + LOG_ERROR("Double-initialization in plain_wallet detected."); + //throw std::runtime_error("Double-initialization in plain_wallet detected."); + return "Already initialized!"; + } + + + initialize_logs(); + std::string argss_1 = std::string("--remote-node=") + ip + ":" + port; + char * args[3]; + args[0] = "stub"; + args[1] = const_cast(argss_1.c_str()); + args[2] = nullptr; + if (!gwm.init(2, args, nullptr)) + { + LOG_ERROR("Failed to init wallets_manager"); + return GENERAL_INTERNAL_ERRROR_INIT; + } + + if(!gwm.start()) + { + LOG_ERROR("Failed to start wallets_manager"); + return GENERAL_INTERNAL_ERRROR_INIT; + } + + std::string wallet_folder = get_wallets_folder(); + boost::system::error_code ec; + boost::filesystem::create_directories(wallet_folder, ec); + + return API_RETURN_CODE_OK; + } + + + std::string get_version() { return PROJECT_VERSION_LONG; @@ -92,78 +125,75 @@ namespace plain_wallet return epee::serialization::store_t_to_json(sl); } - hwallet create_instance(const std::string& ip, const std::string& port) + std::string open(const std::string& path, const std::string& password) { - if (!glogs_initialized) - initialize_logs(); - - plain_wallet_api_impl* ptr = new plain_wallet_api_impl(ip, port); - hwallet new_h = gcounter++; - CRITICAL_REGION_BEGIN(ginstances_lock); - ginstances[new_h] = ptr; - CRITICAL_REGION_END(); - return new_h; - } - - void destroy_instance(hwallet h) - { - plain_wallet_api_impl* instance_ptr = nullptr; - CRITICAL_REGION_BEGIN(ginstances_lock); - auto it = ginstances.find(h); - if (it == ginstances.end()) + std::string full_path = get_wallets_folder() + path; + epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); + std::string rsp = gwm.open_wallet(epee::string_encoding::convert_to_unicode(full_path), password, 20, ok_response.result); + if (rsp == API_RETURN_CODE_OK || rsp == API_RETURN_CODE_FILE_RESTORED) { - LOG_ERROR("Internall error: attempt to delete wallet with wrong instance id: " << h); + if (rsp == API_RETURN_CODE_FILE_RESTORED) + { + ok_response.result.recovered = true; + } + gwm.run_wallet(ok_response.result.wallet_id); + + return epee::serialization::store_t_to_json(ok_response); + } + error_response err_result = AUTO_VAL_INIT(err_result); + err_result.error.code = rsp; + return epee::serialization::store_t_to_json(err_result); + } + std::string restore(const std::string& seed, const std::string& path, const std::string& password) + { + std::string full_path = get_wallets_folder() + path; + epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); + std::string rsp = gwm.restore_wallet(epee::string_encoding::convert_to_unicode(full_path), password, seed, ok_response.result); + if (rsp == API_RETURN_CODE_OK || rsp == API_RETURN_CODE_FILE_RESTORED) + { + if (rsp == API_RETURN_CODE_FILE_RESTORED) + { + ok_response.result.recovered = true; + } + gwm.run_wallet(ok_response.result.wallet_id); + return epee::serialization::store_t_to_json(ok_response); return; } - instance_ptr = it->second; - ginstances.erase(it); - CRITICAL_REGION_END(); - delete instance_ptr; - } - std::string open(hwallet h, const std::string& path, const std::string& password) - { - GET_INSTANCE(pimpl, h); - std::string full_path = get_wallets_folder() + "/" + path; - return pimpl->open(full_path, password); - } - std::string restore(hwallet h, const std::string& seed, const std::string& path, const std::string& password) - { - GET_INSTANCE(pimpl, h); - std::string full_path = get_wallets_folder() + "/" + path; - return pimpl->restore(seed, full_path, password); - } - std::string generate(hwallet h, const std::string& path, const std::string& password) - { - GET_INSTANCE(pimpl, h); - std::string full_path = get_wallets_folder() + "/" + path; - return pimpl->generate(full_path, password); - } - std::string start_sync_thread(hwallet h) - { - GET_INSTANCE(pimpl, h); - pimpl->start_sync_thread(); - return ""; - } - std::string get_sync_status(hwallet h) - { - GET_INSTANCE(pimpl, h); - return pimpl->get_sync_status(); + error_response err_result = AUTO_VAL_INIT(err_result); + err_result.error.code = rsp; + return epee::serialization::store_t_to_json(err_result); } - std::string cancel_sync_thread(hwallet h) + std::string generate(const std::string& path, const std::string& password) { - GET_INSTANCE(pimpl, h); - return pimpl->cancel_sync_thread(); + std::string full_path = get_wallets_folder() + path; + epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); + std::string rsp = gwm.generate_wallet(epee::string_encoding::convert_to_unicode(full_path), password, ok_response.result); + if (rsp == API_RETURN_CODE_OK || rsp == API_RETURN_CODE_FILE_RESTORED) + { + if (rsp == API_RETURN_CODE_FILE_RESTORED) + { + ok_response.result.recovered = true; + } + gwm.run_wallet(ok_response.result.wallet_id); + return epee::serialization::store_t_to_json(ok_response); + } + error_response err_result = AUTO_VAL_INIT(err_result); + err_result.error.code = rsp; + return epee::serialization::store_t_to_json(err_result); } - std::string sync(hwallet h) + std::string close_wallet(hwallet h) { - GET_INSTANCE(pimpl, h); - return pimpl->sync(); + return gwm.close_wallet(h); + } + + std::string get_wallet_status(hwallet h) + { + return gwm.get_wallet_status(h); } std::string invoke(hwallet h, const std::string& params) { - GET_INSTANCE(pimpl, h); - return pimpl->invoke(params); + return gwm.invoke(h, params); } } \ No newline at end of file diff --git a/src/wallet/plain_wallet_api.h b/src/wallet/plain_wallet_api.h index 42e70362..9c2e8fb0 100644 --- a/src/wallet/plain_wallet_api.h +++ b/src/wallet/plain_wallet_api.h @@ -10,19 +10,15 @@ namespace plain_wallet { typedef int64_t hwallet; - hwallet create_instance(const std::string& ip, const std::string& port); - void destroy_instance(hwallet h); + std::string init(const std::string& ip, const std::string& port); std::string get_version(); std::string get_wallet_files(); - std::string print_money(int64_t); - std::string open(hwallet h, const std::string& path, const std::string& password); - std::string restore(hwallet h, const std::string& seed, const std::string& path, const std::string& password); - std::string generate(hwallet h, const std::string& path, const std::string& password); + std::string open(const std::string& path, const std::string& password); + std::string restore(const std::string& seed, const std::string& path, const std::string& password); + std::string generate(const std::string& path, const std::string& password); - std::string start_sync_thread(hwallet h); - std::string get_sync_status(hwallet h); - std::string cancel_sync_thread(hwallet h); - std::string sync(hwallet h); + std::string get_wallet_status(hwallet h); + std::string close_wallet(hwallet h); std::string invoke(hwallet h, const std::string& params); } \ No newline at end of file diff --git a/src/wallet/view_iface.h b/src/wallet/view_iface.h index 2b814adc..48a87459 100644 --- a/src/wallet/view_iface.h +++ b/src/wallet/view_iface.h @@ -424,11 +424,15 @@ public: uint64_t wallet_id; transfers_array recent_history; wallet_info wi; + std::string seed; + bool recovered; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(wallet_id) KV_SERIALIZE(recent_history) KV_SERIALIZE(wi) + KV_SERIALIZE(seed) + KV_SERIALIZE(recovered) END_KV_SERIALIZE_MAP() }; @@ -518,6 +522,19 @@ public: END_KV_SERIALIZE_MAP() }; + struct wallet_sync_status_info + { + uint64_t wallet_state; + bool is_in_long_refresh; + uint64_t progress; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(wallet_state) + KV_SERIALIZE(is_in_long_refresh) + KV_SERIALIZE(progress) + END_KV_SERIALIZE_MAP() + }; + struct get_restore_info_response { std::string restore_key; @@ -745,6 +762,7 @@ public: #define API_RETURN_CODE_FALSE "FALSE" #define API_RETURN_CODE_CORE_BUSY "CORE_BUSY" #define API_RETURN_CODE_OVERFLOW "OVERFLOW" +#define API_RETURN_CODE_BUSY "BUSY" #define API_MAX_ALIASES_COUNT 10000 diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 02f0e077..cdd64fd6 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -46,7 +46,6 @@ #undef LOG_DEFAULT_CHANNEL #define LOG_DEFAULT_CHANNEL "wallet" -ENABLE_CHANNEL_BY_DEFAULT("wallet"); // wallet-specific logging functions #define WLT_LOG_L0(msg) LOG_PRINT_L0("[W:" << m_log_prefix << "] " << msg) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 103a700e..b6c01a50 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -6,11 +6,14 @@ #include "wallets_manager.h" #include "currency_core/alias_helper.h" -#include "core_fast_rpc_proxy.h" -#include "string_coding.h" -#include "currency_core/core_tools.h" +#ifndef MOBILE_WALLET_BUILD + #include "core_fast_rpc_proxy.h" + #include "currency_core/core_tools.h" +#endif #include "common/callstack_helper.h" -#include "wallet/wallet_helpers.h" +#include "string_coding.h" +#include "wallet_helpers.h" +#include "core_default_rpc_proxy.h" #define GET_WALLET_OPT_BY_ID(wallet_id, name) \ CRITICAL_REGION_LOCAL(m_wallets_lock); \ @@ -30,21 +33,28 @@ auto& name = it->second.w; wallets_manager::wallets_manager():m_pview(&m_view_stub), m_stop_singal_sent(false), +#ifndef MOBILE_WALLET_BUILD m_ccore(&m_cprotocol), m_cprotocol(m_ccore, &m_p2psrv), m_p2psrv(m_cprotocol), m_rpc_server(m_ccore, m_p2psrv, m_offers_service), m_rpc_proxy(new tools::core_fast_rpc_proxy(m_rpc_server)), + m_offers_service(nullptr), +#else + m_rpc_proxy(new tools::default_http_core_proxy()), +#endif + m_last_daemon_height(0), m_last_daemon_is_disconnected(false), m_wallet_id_counter(0), - m_offers_service(nullptr), m_ui_opt(AUTO_VAL_INIT(m_ui_opt)), m_remote_node_mode(false), m_is_pos_allowed(false), m_qt_logs_enbaled(false) { +#ifndef MOBILE_WALLET_BUILD m_offers_service.set_disabled(true); +#endif //m_ccore.get_blockchain_storage().get_attachment_services_manager().add_service(&m_offers_service); } @@ -86,8 +96,7 @@ bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler) view::daemon_status_info dsi = AUTO_VAL_INIT(dsi); dsi.pos_difficulty = dsi.pow_difficulty = "---"; - if (pview_handler) - pview_handler->update_daemon_status(dsi); + m_pview->update_daemon_status(dsi); log_space::get_set_log_detalisation_level(true, LOG_LEVEL_0); log_space::get_set_need_thread_id(true, true); @@ -100,10 +109,10 @@ bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler) // setup custom callstack retrieving function epee::misc_utils::get_callstack(tools::get_callstack); - +//#ifndef MOBILE_WALLET_BUILD // setup custom terminate functions std::set_terminate(&terminate_handler_func); - +//#endif //#if !defined(NDEBUG) // log_space::log_singletone::add_logger(LOGGER_DEBUGGER, nullptr, nullptr); //#endif @@ -132,12 +141,13 @@ bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler) command_line::add_arg(desc_cmd_sett, arg_remote_node); command_line::add_arg(desc_cmd_sett, arg_enable_qt_logs); - +#ifndef MOBILE_WALLET_BUILD currency::core::init_options(desc_cmd_sett); currency::core_rpc_server::init_options(desc_cmd_sett); nodetool::node_server >::init_options(desc_cmd_sett); currency::miner::init_options(desc_cmd_sett); bc_services::bc_offers_service::init_options(desc_cmd_sett); +#endif po::options_description desc_options("Allowed options"); desc_options.add(desc_cmd_only).add(desc_cmd_sett); @@ -221,7 +231,9 @@ bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler) if (command_line::has_arg(m_vm, arg_remote_node)) { - // configure for remote node + m_remote_node_mode = true; + m_rpc_proxy.reset(new tools::default_http_core_proxy()); + m_rpc_proxy->set_connection_addr(command_line::get_arg(m_vm, arg_remote_node)); } m_qt_logs_enbaled = command_line::get_arg(m_vm, arg_enable_qt_logs); @@ -289,6 +301,7 @@ std::string wallets_manager::get_config_folder() bool wallets_manager::init_local_daemon() { +#ifndef MOBILE_WALLET_BUILD view::daemon_status_info dsi = AUTO_VAL_INIT(dsi); dsi.pos_difficulty = dsi.pos_difficulty = "---"; dsi.daemon_network_state = currency::COMMAND_RPC_GET_INFO::daemon_network_state_loading_core; @@ -357,12 +370,13 @@ bool wallets_manager::init_local_daemon() res = m_p2psrv.run(false); CHECK_AND_ASSERT_AND_SET_GUI(res, "Failed to run p2p loop."); LOG_PRINT_L0("p2p net loop stopped"); - +#endif return true; } bool wallets_manager::deinit_local_daemon() { +#ifndef MOBILE_WALLET_BUILD view::daemon_status_info dsi = AUTO_VAL_INIT(dsi); dsi.daemon_network_state = currency::COMMAND_RPC_GET_INFO::daemon_network_state_unloading_core; m_pview->update_daemon_status(dsi); @@ -418,7 +432,7 @@ bool wallets_manager::deinit_local_daemon() //dsi.text_state = "Deinitializing core"; m_pview->update_daemon_status(dsi); m_ccore.deinit(); - +#endif return true; } @@ -568,10 +582,18 @@ void wallets_manager::init_wallet_entry(wallet_vs_options& wo, uint64_t id) wo.plast_daemon_is_disconnected = &m_last_daemon_is_disconnected; wo.pview = m_pview; wo.has_related_alias_in_unconfirmed = false; + wo.rpc_wrapper.reset(new tools::wallet_rpc_server(*wo.w.unlocked_get().get())); if (m_remote_node_mode) wo.core_conf = currency::get_default_core_runtime_config(); - else + else + { +#ifndef MOBILE_WALLET_BUILD wo.core_conf = m_ccore.get_blockchain_storage().get_core_runtime_config(); +#else + LOG_ERROR("Unexpected location reached"); +#endif + } + // update wallet log prefix for further usage { @@ -603,19 +625,22 @@ std::string wallets_manager::get_fav_offers(const std::list& offers) { if (m_remote_node_mode) return API_RETURN_CODE_FAIL; - +#ifndef MOBILE_WALLET_BUILD CRITICAL_REGION_LOCAL(m_wallets_lock); while (true) { @@ -657,6 +682,9 @@ std::string wallets_manager::get_my_offers(const bc_services::core_offers_filter LOG_PRINT("get_my_offers(): " << offers.size() << " offers returned (" << offers_count_before_filtering << " was before filter)", LOG_LEVEL_1); return API_RETURN_CODE_OK; +#else + return API_RETURN_CODE_FAIL; +#endif } std::string wallets_manager::open_wallet(const std::wstring& path, const std::string& password, uint64_t txs_to_return, view::open_wallet_response& owr) @@ -671,7 +699,11 @@ std::string wallets_manager::open_wallet(const std::wstring& path, const std::st } else { +#ifndef MOBILE_WALLET_BUILD w->set_core_proxy(std::shared_ptr(new tools::core_fast_rpc_proxy(m_rpc_server))); +#else + LOG_ERROR("Unexpected location reached"); +#endif } std::string return_code = API_RETURN_CODE_OK; @@ -687,6 +719,7 @@ std::string wallets_manager::open_wallet(const std::wstring& path, const std::st //w->get_unconfirmed_transfers(owr.recent_history.unconfirmed); w->get_unconfirmed_transfers(owr.recent_history.history); //workaround for missed fee + owr.seed = w->get_account().get_restore_braindata(); break; } catch (const tools::error::file_not_found& /**/) @@ -746,7 +779,12 @@ std::string wallets_manager::generate_wallet(const std::wstring& path, const std } else { +#ifndef MOBILE_WALLET_BUILD w->set_core_proxy(std::shared_ptr(new tools::core_fast_rpc_proxy(m_rpc_server))); +#else + LOG_ERROR("Unexpected location reached"); +#endif + } @@ -755,6 +793,7 @@ std::string wallets_manager::generate_wallet(const std::wstring& path, const std try { w->generate(path, password); + owr.seed = w->get_account().get_restore_braindata(); } catch (const tools::error::file_exists&) { @@ -780,9 +819,12 @@ std::string wallets_manager::get_mining_estimate(uint64_t amuont_coins, { if (m_remote_node_mode) return API_RETURN_CODE_FAIL; - +#ifndef MOBILE_WALLET_BUILD m_ccore.get_blockchain_storage().get_pos_mining_estimate(amuont_coins, time, estimate_result, pos_coins_and_pos_diff_rate, days); return API_RETURN_CODE_OK; +#else + return API_RETURN_CODE_FAIL; +#endif } std::string wallets_manager::is_pos_allowed() @@ -800,11 +842,15 @@ std::string wallets_manager::is_valid_brain_restore_data(const std::string& brai else return API_RETURN_CODE_FALSE; } +#ifndef MOBILE_WALLET_BUILD void wallets_manager::subscribe_to_core_events(currency::i_core_event_handler* pevents_handler) { + if(!m_remote_node_mode) m_ccore.get_blockchain_storage().set_event_handler(pevents_handler); + } +#endif void wallets_manager::get_gui_options(view::gui_options& opt) { opt = m_ui_opt; @@ -820,7 +866,12 @@ std::string wallets_manager::restore_wallet(const std::wstring& path, const std: } else { +#ifndef MOBILE_WALLET_BUILD w->set_core_proxy(std::shared_ptr(new tools::core_fast_rpc_proxy(m_rpc_server))); +#else + LOG_ERROR("Unexpected location reached"); +#endif + } currency::account_base acc; @@ -830,6 +881,7 @@ std::string wallets_manager::restore_wallet(const std::wstring& path, const std: try { w->restore(path, password, restore_key); + owr.seed = w->get_account().get_restore_braindata(); } catch (const tools::error::file_exists&) { @@ -883,6 +935,7 @@ std::string wallets_manager::get_aliases(view::alias_set& al_set) if (m_remote_node_mode) return API_RETURN_CODE_OVERFLOW; +#ifndef MOBILE_WALLET_BUILD if (m_ccore.get_blockchain_storage().get_aliases_count() > API_MAX_ALIASES_COUNT) return API_RETURN_CODE_OVERFLOW; @@ -893,8 +946,9 @@ std::string wallets_manager::get_aliases(view::alias_set& al_set) al_set.aliases = aliases.aliases; return API_RETURN_CODE_OK; } - +#endif return API_RETURN_CODE_FAIL; + } std::string wallets_manager::get_alias_info_by_address(const std::string& addr, currency::alias_rpc_details& res_details) { @@ -1131,6 +1185,43 @@ std::string wallets_manager::transfer(size_t wallet_id, const view::transfer_par return API_RETURN_CODE_OK; } +std::string wallets_manager::get_wallet_status(uint64_t wallet_id) +{ + GET_WALLET_OPT_BY_ID(wallet_id, wo); + view::wallet_sync_status_info wsi = AUTO_VAL_INIT(wsi); + wsi.is_in_long_refresh = wo.long_refresh_in_progress; + wsi.progress = wo.w.unlocked_get().get()->get_sync_progress(); + wsi.wallet_state = wo.wallet_state; + return epee::serialization::store_t_to_json(wsi); +} + +std::string wallets_manager::invoke(uint64_t wallet_id, std::string params) +{ + GET_WALLET_OPT_BY_ID(wallet_id, wo); + + CRITICAL_REGION_LOCAL1(wo.long_refresh_in_progress_lock); + if (wo.long_refresh_in_progress) + { + epee::json_rpc::response error_response = AUTO_VAL_INIT(error_response); + error_response.error.code = -1; + error_response.error.message = API_RETURN_CODE_BUSY; + return epee::serialization::store_t_to_json(error_response); + } + + + auto locker_object = wo.w.lock(); + + epee::net_utils::http::http_request_info query_info = AUTO_VAL_INIT(query_info); + epee::net_utils::http::http_response_info response_info = AUTO_VAL_INIT(response_info); + epee::net_utils::connection_context_base stub_conn_context = AUTO_VAL_INIT(stub_conn_context); + std::string reference_stub; + bool call_found = false; + query_info.m_URI = "/json_rpc"; + query_info.m_body = params; + wo.rpc_wrapper->handle_http_request_map(query_info, response_info, stub_conn_context, call_found, reference_stub); + return response_info.m_body; +} + std::string wallets_manager::get_wallet_info(size_t wallet_id, view::wallet_info& wi) { GET_WALLET_OPT_BY_ID(wallet_id, w); @@ -1434,10 +1525,14 @@ std::string wallets_manager::get_offers_ex(const bc_services::core_offers_filter { if (m_remote_node_mode) return API_RETURN_CODE_FAIL; +#ifndef MOBILE_WALLET_BUILD //TODO: make it proxy-like call //m_ccore.get_blockchain_storage().get_offers_ex(cof, offers, total_count); m_offers_service.get_offers_ex(cof, offers, total_count, m_ccore.get_blockchain_storage().get_core_runtime_config().get_core_time()); return API_RETURN_CODE_OK; +#else + return API_RETURN_CODE_FAIL; +#endif } @@ -1526,6 +1621,13 @@ void wallets_manager::wallet_vs_options::worker_func() if (last_wallet_synch_height && *plast_daemon_height - last_wallet_synch_height < 3) show_progress = false; + if(*plast_daemon_height - last_wallet_synch_height > 10) + { + CRITICAL_REGION_LOCAL(long_refresh_in_progress_lock); + long_refresh_in_progress = true; + } + + if (show_progress) { wallet_state = wsi.wallet_state = view::wallet_status_info::wallet_state_synchronizing; @@ -1533,6 +1635,7 @@ void wallets_manager::wallet_vs_options::worker_func() pview->update_wallet_status(wsi); } w->get()->refresh(stop_for_refresh); + long_refresh_in_progress = false; w->get()->resend_unconfirmed(); { auto w_ptr = *w; // get locked exclusive access to the wallet first (it's more likely that wallet is locked for a long time than 'offers') diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index d3d39c7a..8b69def2 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -19,16 +19,19 @@ using namespace epee; #include "console_handler.h" #include "p2p/net_node.h" #include "currency_core/checkpoints_create.h" -#include "currency_core/currency_core.h" -#include "currency_core/bc_offers_service.h" -#include "rpc/core_rpc_server.h" -#include "currency_protocol/currency_protocol_handler.h" -#include "daemon/daemon_commands_handler.h" +#ifndef MOBILE_WALLET_BUILD + #include "currency_core/currency_core.h" + #include "currency_core/bc_offers_service.h" + #include "rpc/core_rpc_server.h" + #include "currency_protocol/currency_protocol_handler.h" + #include "core_fast_rpc_proxy.h" +#endif +//#include "daemon/daemon_commands_handler.h" //#include "common/miniupnp_helper.h" #include "view_iface.h" -#include "core_fast_rpc_proxy.h" -#include "wallet/wallet2.h" +#include "wallet2.h" #include "wallet_id_adapter.h" +#include "wallet_rpc_server.h" POP_VS_WARNINGS @@ -38,8 +41,6 @@ namespace po = boost::program_options; #include #endif -//TODO: need refactoring here. (template classes can't be used in BOOST_CLASS_VERSION) -BOOST_CLASS_VERSION(nodetool::node_server >, CURRENT_P2P_STORAGE_ARCHIVE_VER); struct wallet_lock_time_watching_policy { @@ -55,6 +56,7 @@ public: { currency::core_runtime_config core_conf; epee::locked_object, wallet_lock_time_watching_policy> w; + std::shared_ptr rpc_wrapper; //500 bytes of extra data, we can afford it, to have rpc-like invoke map std::atomic do_mining; std::atomic major_stop; std::atomic stop_for_refresh; //use separate var for passing to "refresh" member function, @@ -68,6 +70,10 @@ public: std::atomic* plast_daemon_is_disconnected; std::atomic has_related_alias_in_unconfirmed; std::atomic need_to_update_wallet_info; + + std::atomic long_refresh_in_progress; + epee::critical_section long_refresh_in_progress_lock; //secure wallet state and prevent from long wait while long refresh is in work + view::i_view* pview; uint64_t wallet_id; epee::locked_object> offers; @@ -87,6 +93,8 @@ public: std::string open_wallet(const std::wstring& path, const std::string& password, uint64_t txs_to_return, view::open_wallet_response& owr); std::string generate_wallet(const std::wstring& path, const std::string& password, view::open_wallet_response& owr); std::string restore_wallet(const std::wstring& path, const std::string& password, const std::string& restore_key, view::open_wallet_response& owr); + std::string invoke(uint64_t wallet_id, std::string params); + std::string get_wallet_status(uint64_t wallet_id); std::string run_wallet(uint64_t wallet_id); std::string get_recent_transfers(size_t wallet_id, uint64_t offset, uint64_t count, view::transfers_array& tr_hist); std::string get_wallet_info(size_t wallet_id, view::wallet_info& wi); @@ -134,8 +142,10 @@ public: std::string transfer(size_t wallet_id, const view::transfer_params& tp, currency::transaction& res_tx); std::string get_config_folder(); std::string is_valid_brain_restore_data(const std::string& brain_text); +#ifndef MOBILE_WALLET_BUILD void subscribe_to_core_events(currency::i_core_event_handler* pevents_handler); - void unsubscribe_to_core_events(); + //void unsubscribe_to_core_events(); +#endif void get_gui_options(view::gui_options& opt); std::string get_wallet_log_prefix(size_t wallet_id) const; bool is_qt_logs_enabled() const { return m_qt_logs_enbaled; } @@ -176,12 +186,14 @@ private: std::string m_data_dir; view::gui_options m_ui_opt; +#ifndef MOBILE_WALLET_BUILD //daemon stuff bc_services::bc_offers_service m_offers_service; currency::core m_ccore; currency::t_currency_protocol_handler m_cprotocol; nodetool::node_server > m_p2psrv; currency::core_rpc_server m_rpc_server; +#endif bool m_remote_node_mode; bool m_qt_logs_enbaled; diff --git a/tests/functional_tests/core_concurrency_test.cpp b/tests/functional_tests/core_concurrency_test.cpp index d72cf983..52ff1b8c 100644 --- a/tests/functional_tests/core_concurrency_test.cpp +++ b/tests/functional_tests/core_concurrency_test.cpp @@ -13,7 +13,7 @@ using namespace epee; #include "currency_core/currency_core.h" #include "rpc/core_rpc_server.h" -#include "gui/qt-daemon/application/core_fast_rpc_proxy.h" +#include "wallet/core_fast_rpc_proxy.h" #include "version.h" #include "common/command_line.h" #include "common/boost_serialization_helper.h" diff --git a/tests/functional_tests/plain_wallet_tests.cpp b/tests/functional_tests/plain_wallet_tests.cpp index c843c3fe..82ccc75c 100644 --- a/tests/functional_tests/plain_wallet_tests.cpp +++ b/tests/functional_tests/plain_wallet_tests.cpp @@ -19,143 +19,163 @@ using namespace epee; void run_plain_wallet_api_test() { LOG_PRINT_L0("Creating instance..."); - plain_wallet::hwallet hw = plain_wallet::create_instance("127.0.0.1", "11211"); - LOG_PRINT_L0("Creating instance..." << std::hex << hw); + std::string s = plain_wallet::init("195.201.107.230", "11211"); LOG_PRINT_L0("Generating wallet..."); - std::string rsp = plain_wallet::open(hw, std::string("E:\\tmp\\zano_testwallet_74565030.zan"), ""); + std::string rsp = plain_wallet::open(std::string("E:\\tmp\\zano_testwallet_745ss65030.zan"), ""); LOG_PRINT_L0("RESPONSE:" << ENDL << rsp); - epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); + epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); epee::serialization::load_t_from_json(ok_response, rsp); - plain_wallet::start_sync_thread(hw); - LOG_PRINT_L0("Started sync thread."); while (true) { - std::string prog = plain_wallet::get_sync_status(hw); - plain_wallet::sync_status_response ssr = AUTO_VAL_INIT(ssr); - epee::serialization::load_t_from_json(ssr, prog); - LOG_PRINT_L0("Progress: " << ssr.progress << "Finished: " << ssr.finished); - if (ssr.finished) - break; + std::string prog = plain_wallet::get_wallet_status(ok_response.result.wallet_id); + LOG_PRINT_L0("Progress: " << ENDL << prog); + // view::sta ssr = AUTO_VAL_INIT(ssr); + // epee::serialization::load_t_from_json(ssr, prog); + // LOG_PRINT_L0("Progress: " << ssr.progress << "Finished: " << ssr.finished); + // if (ssr.finished) + // break; epee::misc_utils::sleep_no_w(1000); } - LOG_PRINT_L0("Sync finished OK"); +} - { - //request get wallet info: - epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); - gbreq.method = "get_wallet_info"; - epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); - std::string req_str = epee::serialization::store_t_to_json(gbreq); - - std::string res = plain_wallet::invoke(hw, req_str); - epee::serialization::load_t_from_json(gbres, res); - - LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: " - << ENDL << res); - } - - { - //request balance - epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); - gbreq.method = "getbalance"; - epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); - std::string req_str = epee::serialization::store_t_to_json(gbreq); - - std::string res = plain_wallet::invoke(hw, req_str); - epee::serialization::load_t_from_json(gbres, res); - - LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], balance: " - << gbres.result.balance << ", unlocked_balance: " << gbres.result.unlocked_balance); - } - - { - //request balance - epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); - gbreq.method = "store"; - epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); - std::string req_str = epee::serialization::store_t_to_json(gbreq); - - std::string res = plain_wallet::invoke(hw, req_str); - epee::serialization::load_t_from_json(gbres, res); - - LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: " - << ENDL << res); - } - - plain_wallet::destroy_instance(hw); - - - return; - //------- - { - LOG_PRINT_L0("Creating instance..."); - plain_wallet::hwallet hw = plain_wallet::create_instance("127.0.0.1", "11211"); - LOG_PRINT_L0("Creating instance..." << std::hex << hw); - - LOG_PRINT_L0("Generating wallet..."); - std::string rsp = plain_wallet::generate(hw, std::string("E:\\tmp\\zano_testwallet_") + std::to_string(epee::misc_utils::get_tick_count()) + ".zan", ""); - LOG_PRINT_L0("RESPONSE:" << ENDL << rsp); - epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); - epee::serialization::load_t_from_json(ok_response, rsp); - - plain_wallet::start_sync_thread(hw); - LOG_PRINT_L0("Started sync thread."); - - while (true) - { - std::string prog = plain_wallet::get_sync_status(hw); - plain_wallet::sync_status_response ssr = AUTO_VAL_INIT(ssr); - epee::serialization::load_t_from_json(ssr, prog); - LOG_PRINT_L0("Progress: " << ssr.progress << "Finished: " << ssr.finished); - if (ssr.finished) - break; - epee::misc_utils::sleep_no_w(1000); - } - LOG_PRINT_L0("Sync finished OK"); - - { - //request get wallet info: - epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); - gbreq.method = "get_wallet_info"; - epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); - std::string req_str = epee::serialization::store_t_to_json(gbreq); - - std::string res = plain_wallet::invoke(hw, req_str); - epee::serialization::load_t_from_json(gbres, res); - - LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: " - << ENDL << res); - } - - { - //request balance - epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); - gbreq.method = "getbalance"; - epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); - std::string req_str = epee::serialization::store_t_to_json(gbreq); - - std::string res = plain_wallet::invoke(hw, req_str); - epee::serialization::load_t_from_json(gbres, res); - - LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], balance: " - << gbres.result.balance << ", unlocked_balance: " << gbres.result.unlocked_balance); - } - - { - //request balance - epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); - gbreq.method = "store"; - epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); - std::string req_str = epee::serialization::store_t_to_json(gbreq); - - std::string res = plain_wallet::invoke(hw, req_str); - epee::serialization::load_t_from_json(gbres, res); - - LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: " - << ENDL << res); - } - } -} \ No newline at end of file +// LOG_PRINT_L0("Creating instance..." << std::hex << hw); +// +// LOG_PRINT_L0("Generating wallet..."); +// std::string rsp = plain_wallet::open(hw, std::string("E:\\tmp\\zano_testwallet_74565030.zan"), ""); +// LOG_PRINT_L0("RESPONSE:" << ENDL << rsp); +// epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); +// epee::serialization::load_t_from_json(ok_response, rsp); +// +// plain_wallet::start_sync_thread(hw); +// LOG_PRINT_L0("Started sync thread."); +// +// while (true) +// { +// std::string prog = plain_wallet::get_sync_status(hw); +// plain_wallet::sync_status_response ssr = AUTO_VAL_INIT(ssr); +// epee::serialization::load_t_from_json(ssr, prog); +// LOG_PRINT_L0("Progress: " << ssr.progress << "Finished: " << ssr.finished); +// if (ssr.finished) +// break; +// epee::misc_utils::sleep_no_w(1000); +// } +// LOG_PRINT_L0("Sync finished OK"); +// +// { +// //request get wallet info: +// epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); +// gbreq.method = "get_wallet_info"; +// epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); +// std::string req_str = epee::serialization::store_t_to_json(gbreq); +// +// std::string res = plain_wallet::invoke(hw, req_str); +// epee::serialization::load_t_from_json(gbres, res); +// +// LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: " +// << ENDL << res); +// } +// +// { +// //request balance +// epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); +// gbreq.method = "getbalance"; +// epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); +// std::string req_str = epee::serialization::store_t_to_json(gbreq); +// +// std::string res = plain_wallet::invoke(hw, req_str); +// epee::serialization::load_t_from_json(gbres, res); +// +// LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], balance: " +// << gbres.result.balance << ", unlocked_balance: " << gbres.result.unlocked_balance); +// } +// +// { +// //request balance +// epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); +// gbreq.method = "store"; +// epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); +// std::string req_str = epee::serialization::store_t_to_json(gbreq); +// +// std::string res = plain_wallet::invoke(hw, req_str); +// epee::serialization::load_t_from_json(gbres, res); +// +// LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: " +// << ENDL << res); +// } +// +// plain_wallet::destroy_instance(hw); +// +// +// return; +// //------- +// { +// LOG_PRINT_L0("Creating instance..."); +// plain_wallet::hwallet hw = plain_wallet::create_instance("127.0.0.1", "11211"); +// LOG_PRINT_L0("Creating instance..." << std::hex << hw); +// +// LOG_PRINT_L0("Generating wallet..."); +// std::string rsp = plain_wallet::generate(hw, std::string("E:\\tmp\\zano_testwallet_") + std::to_string(epee::misc_utils::get_tick_count()) + ".zan", ""); +// LOG_PRINT_L0("RESPONSE:" << ENDL << rsp); +// epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); +// epee::serialization::load_t_from_json(ok_response, rsp); +// +// plain_wallet::start_sync_thread(hw); +// LOG_PRINT_L0("Started sync thread."); +// +// while (true) +// { +// std::string prog = plain_wallet::get_sync_status(hw); +// plain_wallet::sync_status_response ssr = AUTO_VAL_INIT(ssr); +// epee::serialization::load_t_from_json(ssr, prog); +// LOG_PRINT_L0("Progress: " << ssr.progress << "Finished: " << ssr.finished); +// if (ssr.finished) +// break; +// epee::misc_utils::sleep_no_w(1000); +// } +// LOG_PRINT_L0("Sync finished OK"); +// +// { +// //request get wallet info: +// epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); +// gbreq.method = "get_wallet_info"; +// epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); +// std::string req_str = epee::serialization::store_t_to_json(gbreq); +// +// std::string res = plain_wallet::invoke(hw, req_str); +// epee::serialization::load_t_from_json(gbres, res); +// +// LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: " +// << ENDL << res); +// } +// +// { +// //request balance +// epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); +// gbreq.method = "getbalance"; +// epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); +// std::string req_str = epee::serialization::store_t_to_json(gbreq); +// +// std::string res = plain_wallet::invoke(hw, req_str); +// epee::serialization::load_t_from_json(gbres, res); +// +// LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], balance: " +// << gbres.result.balance << ", unlocked_balance: " << gbres.result.unlocked_balance); +// } +// +// { +// //request balance +// epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); +// gbreq.method = "store"; +// epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); +// std::string req_str = epee::serialization::store_t_to_json(gbreq); +// +// std::string res = plain_wallet::invoke(hw, req_str); +// epee::serialization::load_t_from_json(gbres, res); +// +// LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: " +// << ENDL << res); +// } +// }} \ No newline at end of file diff --git a/utils/build_android_libs.sh b/utils/build_android_libs.sh new file mode 100755 index 00000000..750ebf01 --- /dev/null +++ b/utils/build_android_libs.sh @@ -0,0 +1,78 @@ +set -x #echo on +cd .. +rm -r _builds +cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=21 -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + +cmake --build _builds --config Debug --target install -- -j 4 +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + +rm -r _builds +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + +cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=21 -DCMAKE_ANDROID_ARCH_ABI=x86 -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + +cmake --build _builds --config Debug --target install -- -j 4 +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + +rm -r _builds +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + + +cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=21 -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + +cmake --build _builds --config Debug --target install -- -j 4 +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + +rm -r _builds +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + + +cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=21 -DCMAKE_ANDROID_ARCH_ABI=x86_64 -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + +cmake --build _builds --config Debug --target install -- -j 4 +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + +rm -r _builds +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + +