forked from lthn/blockchain
Merge branch 'develop' into release
This commit is contained in:
commit
55cb64cedf
83 changed files with 2664 additions and 576 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,4 +1,5 @@
|
|||
/build*
|
||||
/_builds/*
|
||||
/tags
|
||||
.DS_Store
|
||||
._.DS_Store
|
||||
|
|
|
|||
|
|
@ -5,14 +5,26 @@ PROJECT(Zano)
|
|||
|
||||
set(VERSION "1.0")
|
||||
|
||||
if(POLICY CMP0043)
|
||||
cmake_policy(SET CMP0043 OLD)
|
||||
endif()
|
||||
# if(POLICY CMP0043)
|
||||
# cmake_policy(SET CMP0043 OLD)
|
||||
# endif()
|
||||
|
||||
if(POLICY CMP0020)
|
||||
cmake_policy(SET CMP0020 OLD)
|
||||
endif()
|
||||
# if(POLICY CMP0020)
|
||||
# cmake_policy(SET CMP0020 OLD)
|
||||
# endif()
|
||||
|
||||
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)
|
||||
|
||||
|
|
@ -24,7 +36,13 @@ if (UNIX AND NOT APPLE)
|
|||
endif()
|
||||
else()
|
||||
# multi configurations for MSVC and XCode
|
||||
set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
|
||||
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()
|
||||
endif()
|
||||
message("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}, and built type: ${CMAKE_BUILD_TYPE}")
|
||||
|
||||
|
|
@ -83,16 +101,16 @@ else()
|
|||
# set(WARNINGS "${WARNINGS} -Werror")
|
||||
# endif()
|
||||
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||
set(WARNINGS "${WARNINGS} -Wno-shift-count-overflow -Wno-error=mismatched-tags -Wno-error=null-conversion -Wno-overloaded-shift-op-parentheses -Wno-error=shift-count-overflow -Wno-error=tautological-constant-out-of-range-compare -Wno-error=unused-private-field -Wno-error=unneeded-internal-declaration")
|
||||
set(WARNINGS "${WARNINGS} -Wno-implicit-function-declaration -Wno-shift-count-overflow -Wno-error=mismatched-tags -Wno-error=null-conversion -Wno-overloaded-shift-op-parentheses -Wno-error=shift-count-overflow -Wno-error=tautological-constant-out-of-range-compare -Wno-error=unused-private-field -Wno-error=unneeded-internal-declaration")
|
||||
else()
|
||||
set(WARNINGS "${WARNINGS} -Wno-error=write-strings -Wlogical-op -Wno-error=maybe-uninitialized")
|
||||
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))
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.0) AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Android"))
|
||||
set(CMAKE_AR "gcc-ar")
|
||||
set(CMAKE_RANLIB "gcc-ranlib")
|
||||
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT APPLE)
|
||||
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT APPLE AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Android"))
|
||||
set(CMAKE_AR "llvm-ar")
|
||||
set(CMAKE_RANLIB "llvm-ranlib")
|
||||
endif()
|
||||
|
|
@ -161,11 +179,28 @@ if(STATIC)
|
|||
set(Boost_USE_STATIC_LIBS ON)
|
||||
set(Boost_USE_STATIC_RUNTIME ON)
|
||||
endif()
|
||||
find_package(Boost 1.53 REQUIRED COMPONENTS system filesystem thread timer date_time chrono regex serialization atomic program_options locale)
|
||||
if(MSVC AND (${Boost_MAJOR_VERSION} EQUAL 1) AND (${Boost_MINOR_VERSION} EQUAL 54))
|
||||
message(SEND_ERROR "Boost version 1.54 is unsupported, more details are available here http://goo.gl/RrCFmA")
|
||||
|
||||
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()
|
||||
|
||||
|
||||
|
||||
message(STATUS "Boost: ${Boost_VERSION} from ${Boost_LIBRARY_DIRS}")
|
||||
|
||||
|
||||
|
|
@ -174,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")
|
||||
|
|
|
|||
86
README.md
86
README.md
|
|
@ -1,7 +1,6 @@
|
|||
[](https://scan.coverity.com/projects/zanoproject) [](https://discord.gg/wE3rmYY)
|
||||
|
||||
[](https://scan.coverity.com/projects/zanoproject)
|
||||
|
||||
Building
|
||||
Building Zano
|
||||
--------
|
||||
|
||||
### Cloning
|
||||
|
|
@ -17,25 +16,67 @@ Be sure to properly clone the repository:
|
|||
| llvm/clang (Linux) | UNKNOWN | 7.0.1 | 8.0.0 |
|
||||
| [MSVC](https://visualstudio.microsoft.com/downloads/) (Windows) | 2015 (14.0 update 1) | 2015 (14.0 update 3) | 2017 (15.5.7) |
|
||||
| [XCode](https://developer.apple.com/downloads/) (macOS) | 7.3.1 | 9.2 | 9.2 |
|
||||
| [CMake](https://cmake.org/download/) | 2.8.6 | 3.4.1 | 3.11.0 |
|
||||
| [Boost](https://www.boost.org/users/download/) | 1.56 | 1.60 | 1.66 |
|
||||
| [Qt](https://download.qt.io/archive/qt/) (only for GUI) | 5.8.0 | 5.9.1 | 5.10.1 |
|
||||
| [CMake](https://cmake.org/download/) | 2.8.6 | 3.15.5 | 3.15.5 |
|
||||
| [Boost](https://www.boost.org/users/download/) | 1.56 | 1.68 | 1.68 |
|
||||
| [Qt](https://download.qt.io/archive/qt/) (only for GUI) | 5.8.0 | 5.11.2 | 5.13.2 |
|
||||
|
||||
### Linux
|
||||
|
||||
Recommended OS version: Ubuntu 17.04 LTS.
|
||||
Recommended OS version: Ubuntu 18.04 LTS.
|
||||
|
||||
1. For server version: \
|
||||
`$ sudo apt-get install -y build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev cmake git libboost-all-dev screen`\
|
||||
For GUI version:\
|
||||
`$ sudo apt-get install -y build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev cmake git libboost-all-dev screen mesa-common-dev libglu1-mesa-dev qt5-default qtwebengine5-dev`
|
||||
1. Prerequisites
|
||||
1. Prerequisites for server version:
|
||||
|
||||
sudo apt-get install -y build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev cmake git screen
|
||||
|
||||
1. Prerequisites for GUI version:
|
||||
|
||||
2. `$ cd zano/ && make -j$(nproc) gui`
|
||||
3. Look for the binaries, including the `Zano` GUI, in the build directory
|
||||
sudo apt-get install -y build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev cmake git screen mesa-common-dev libglu1-mesa-dev`
|
||||
|
||||
2. Download and build Boost
|
||||
|
||||
wget https://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.tar.bz2
|
||||
tar -xjf boost_1_68_0.tar.bz2
|
||||
cd boost_1_68_0
|
||||
./bootstrap.sh --with-libraries=system,filesystem,thread,date_time,chrono,regex,serialization,atomic,program_options,locale,timer
|
||||
./b2
|
||||
|
||||
3. Install Qt
|
||||
|
||||
wget https://download.qt.io/archive/qt/5.11/5.11.2/qt-opensource-linux-x64-5.11.2.run
|
||||
chmod +x qt-opensource-linux-x64-5.11.2.run
|
||||
./qt-opensource-linux-x64-5.11.2.run
|
||||
Then follow the instructions in Wizard. Don't forget to tick WebEngine module!
|
||||
|
||||
4. Set `BOOST_ROOT` and `QT_PREFIX_PATH` envinorment variables\
|
||||
For instance, by adding these lines to `~/.bashrc`:
|
||||
|
||||
export BOOST_ROOT=/home/user/boost_1_68_0
|
||||
export QT_PREFIX_PATH=/home/user/Qt5.11.2/5.11.2/gcc_64
|
||||
|
||||
|
||||
5. Building binaries
|
||||
1. Building daemon and simplewallet:
|
||||
|
||||
cd zano/ && make -j1
|
||||
or
|
||||
|
||||
cd zano && mkdir build && cd build
|
||||
cmake ..
|
||||
make -j1 daemon simplewallet
|
||||
|
||||
**NOTICE**: If you are building on machine with relatively high anount of RAM or with proper setting of virtual memory, then you can use `-j2` or `-j` option to speed up the building process. Use with caution.
|
||||
|
||||
1. Building GUI:
|
||||
|
||||
cd zano
|
||||
utils/build_sript_linux.sh
|
||||
|
||||
7. Look for the binaries in `build` folder
|
||||
|
||||
### Windows
|
||||
Recommended OS version: Windows 7 x64.
|
||||
1. Install required prerequisites.
|
||||
1. Install required prerequisites (Boost, Qt, CMake).
|
||||
2. Edit paths in `utils/configure_local_paths.cmd`.
|
||||
3. Run `utils/configure_win64_msvs2015_gui.cmd` or `utils/configure_win64_msvs2017_gui.cmd` according to your MSVC version.
|
||||
4. Go to the build folder and open generated Zano.sln in MSVC.
|
||||
|
|
@ -54,14 +95,15 @@ Recommended OS version: macOS Sierra 10.12.6 x64.
|
|||
|
||||
To build GUI application:
|
||||
|
||||
1. Create self-signing certificate via Keychain Access:
|
||||
a. Run Keychain Access.
|
||||
b. Choose Keychain Access > Certificate Assistant > Create a Certificate.
|
||||
c. Use “Zano” (without quotes) as certificate name.
|
||||
d. Choose “Code Signing” in “Certificate Type” field.
|
||||
e. Press “Create”, then “Done”.
|
||||
f. Make sure the certificate was added to keychain "System". If not—move it to "System".
|
||||
g. Double click the certificate you've just added, enter the trust section and under "When using this certificate" select "Always trust".
|
||||
1. Create self-signing certificate via Keychain Access:\
|
||||
a. Run Keychain Access.\
|
||||
b. Choose Keychain Access > Certificate Assistant > Create a Certificate.\
|
||||
c. Use “Zano” (without quotes) as certificate name.\
|
||||
d. Choose “Code Signing” in “Certificate Type” field.\
|
||||
e. Press “Create”, then “Done”.\
|
||||
f. Make sure the certificate was added to keychain "System". If not—move it to "System".\
|
||||
g. Double click the certificate you've just added, enter the trust section and under "When using this certificate" select "Always trust".\
|
||||
h. Unfold the certificate in Keychain Access window and double click underlying private key "Zano". Select "Access Control" tab, then select "Allow all applications to access this item". Click "Save Changes".
|
||||
2. Revise building script, comment out unwanted steps and run it: `utils/build_script_mac_osx.sh`
|
||||
3. The application should be here: `/buid_mac_osx_64/release/src`
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,24 @@
|
|||
set(UPNPC_BUILD_STATIC ON CACHE BOOL "Build static library")
|
||||
set(UPNPC_BUILD_SHARED OFF CACHE BOOL "Build shared library")
|
||||
set(UPNPC_BUILD_TESTS OFF CACHE BOOL "Build test executables")
|
||||
add_subdirectory(miniupnp/miniupnpc)
|
||||
add_subdirectory(zlib)
|
||||
add_subdirectory(db)
|
||||
add_subdirectory(ethereum)
|
||||
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
|
||||
message("excluded upnp support for IOS build")
|
||||
return()
|
||||
endif()
|
||||
add_subdirectory(miniupnp/miniupnpc)
|
||||
|
||||
|
||||
set_property(TARGET libminiupnpc-static PROPERTY FOLDER "contrib")
|
||||
set_property(TARGET zlibstatic PROPERTY FOLDER "contrib")
|
||||
set_property(TARGET mdbx PROPERTY FOLDER "contrib")
|
||||
set_property(TARGET lmdb PROPERTY FOLDER "contrib")
|
||||
set_property(TARGET upnpc-static mdbx_chk mdbx_copy mdbx_dump mdbx_load mdbx_stat minigzip zlib example PROPERTY FOLDER "unused")
|
||||
set_property(TARGET upnpc-static mdbx_chk mdbx_copy mdbx_dump mdbx_load mdbx_stat PROPERTY FOLDER "unused")
|
||||
|
||||
if(MSVC)
|
||||
set_property(TARGET ntdll_extra_target PROPERTY FOLDER "unused")
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,11 @@
|
|||
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
|
||||
message("excluded db support for IOS build")
|
||||
return()
|
||||
endif()
|
||||
|
||||
|
||||
message("DB ENGINE: lmdb")
|
||||
add_subdirectory(liblmdb)
|
||||
if(MSVC)
|
||||
|
|
|
|||
|
|
@ -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<bool> initialized(false);
|
||||
static std::atomic<bool> 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)
|
||||
|
|
@ -584,7 +590,7 @@ namespace log_space
|
|||
std::string buf(buffer, buffer_len);
|
||||
for(size_t i = 0; i!= buf.size(); i++)
|
||||
{
|
||||
if(buf[i] == 7 || buf[i] == -107)
|
||||
if(static_cast<unsigned char>(buf[i]) == 0x7 || static_cast<unsigned char>(buf[i]) == 0x95)
|
||||
buf[i] = '^';
|
||||
}
|
||||
|
||||
|
|
@ -1150,7 +1156,9 @@ namespace log_space
|
|||
std::set<std::string> 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)
|
||||
|
|
|
|||
|
|
@ -109,14 +109,15 @@ namespace misc_utils
|
|||
#endif
|
||||
}
|
||||
|
||||
#if defined(__GNUC__)
|
||||
|
||||
#if defined(__GNUC__) && !defined(__ANDROID__)
|
||||
#include <execinfo.h>
|
||||
#include <boost/core/demangle.hpp>
|
||||
#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;
|
||||
|
|
|
|||
|
|
@ -873,6 +873,7 @@ using namespace std;
|
|||
if (!tr.connect(u_c.host, static_cast<int>(u_c.port), timeout))
|
||||
{
|
||||
LOG_PRINT_L2("invoke_request: cannot connect to " << u_c.host << ":" << u_c.port);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -198,10 +198,12 @@ namespace epee
|
|||
struct response<dummy_result, t_error>
|
||||
{
|
||||
std::string jsonrpc;
|
||||
std::string method;
|
||||
t_error error;
|
||||
epee::serialization::storage_entry id;
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(jsonrpc)
|
||||
KV_SERIALIZE(method)
|
||||
KV_SERIALIZE(id)
|
||||
KV_SERIALIZE(error)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
|
|
@ -288,6 +290,7 @@ struct json_command_type_t
|
|||
PREPARE_OBJECTS_FROM_JSON(command_type) \
|
||||
epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
|
||||
fail_resp.jsonrpc = "2.0"; \
|
||||
fail_resp.method = req.method; \
|
||||
fail_resp.id = req.id; \
|
||||
if(!callback_f(req.params, resp.result, fail_resp.error, m_conn_context)) \
|
||||
{ \
|
||||
|
|
@ -304,6 +307,7 @@ struct json_command_type_t
|
|||
PREPARE_OBJECTS_FROM_JSON(command_type) \
|
||||
epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
|
||||
fail_resp.jsonrpc = "2.0"; \
|
||||
fail_resp.method = req.method; \
|
||||
fail_resp.id = req.id; \
|
||||
if(!callback_f(req.params, resp.result, fail_resp.error, m_conn_context, response_info)) \
|
||||
{ \
|
||||
|
|
@ -322,6 +326,7 @@ struct json_command_type_t
|
|||
{ \
|
||||
epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
|
||||
fail_resp.jsonrpc = "2.0"; \
|
||||
fail_resp.method = req.method; \
|
||||
fail_resp.id = req.id; \
|
||||
fail_resp.error.code = -32603; \
|
||||
fail_resp.error.message = "Internal error"; \
|
||||
|
|
@ -338,6 +343,7 @@ struct json_command_type_t
|
|||
epee::json_rpc::error_response rsp; \
|
||||
rsp.id = id_; \
|
||||
rsp.jsonrpc = "2.0"; \
|
||||
rsp.method = callback_name; \
|
||||
rsp.error.code = -32601; \
|
||||
rsp.error.message = "Method not found"; \
|
||||
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(rsp), response_info.m_body); \
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ namespace epee
|
|||
{
|
||||
|
||||
template<class pack_value, class t_stream>
|
||||
size_t pack_varint_t(t_stream& strm, uint8_t type_or, size_t& pv)
|
||||
size_t pack_varint_t(t_stream& strm, uint8_t type_or, const uint64_t& pv)
|
||||
{
|
||||
pack_value v = (*((pack_value*)&pv)) << 2;
|
||||
v |= type_or;
|
||||
|
|
@ -48,7 +48,7 @@ namespace epee
|
|||
PUSH_GCC_WARNINGS
|
||||
DISABLE_GCC_WARNING(strict-aliasing)
|
||||
template<class t_stream>
|
||||
size_t pack_varint(t_stream& strm, size_t val)
|
||||
size_t pack_varint(t_stream& strm, uint64_t val)
|
||||
{ //the first two bits always reserved for size information
|
||||
|
||||
if(val <= 63)
|
||||
|
|
|
|||
|
|
@ -157,6 +157,7 @@ namespace epee
|
|||
template<class t_stream>
|
||||
void dump_as_json(t_stream& strm, const double& v, size_t indent, end_of_line_t eol)
|
||||
{
|
||||
boost::io::ios_flags_saver ifs(strm);
|
||||
strm.precision(8);
|
||||
strm << std::fixed << v;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,8 +54,10 @@ namespace epee
|
|||
{}
|
||||
~locked_object_proxy()
|
||||
{
|
||||
TRY_ENTRY();
|
||||
uint64_t lock_time = epee::misc_utils::get_tick_count() - start_lock_time;
|
||||
lock_time_watching_policy::watch_lock_time(lock_time);
|
||||
CATCH_ALL_DO_NOTHING();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -82,6 +84,13 @@ namespace epee
|
|||
template<typename t_proxy_object, typename t_proxy_lock_time_watching_policy>
|
||||
friend class locked_object_proxy;
|
||||
public:
|
||||
std::shared_ptr<locked_object_proxy<t_object, lock_time_watching_policy>> lock()
|
||||
{
|
||||
std::shared_ptr<locked_object_proxy<t_object, lock_time_watching_policy>> res;
|
||||
res.reset(new locked_object_proxy<t_object, lock_time_watching_policy>(t, m));
|
||||
return res;
|
||||
}
|
||||
|
||||
std::shared_ptr<locked_object_proxy<t_object, lock_time_watching_policy>> try_lock()
|
||||
{
|
||||
std::shared_ptr<locked_object_proxy<t_object, lock_time_watching_policy>> res;
|
||||
|
|
|
|||
|
|
@ -183,10 +183,10 @@ if(MINGW)
|
|||
set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
|
||||
endif(MINGW)
|
||||
|
||||
add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
|
||||
#add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
|
||||
add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
|
||||
set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
|
||||
set_target_properties(zlib PROPERTIES SOVERSION 1)
|
||||
# set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
|
||||
# set_target_properties(zlib PROPERTIES SOVERSION 1)
|
||||
|
||||
if(NOT CYGWIN)
|
||||
# This property causes shared libraries on Linux to have the full version
|
||||
|
|
@ -196,22 +196,22 @@ if(NOT CYGWIN)
|
|||
#
|
||||
# This has no effect with MSVC, on that platform the version info for
|
||||
# the DLL comes from the resource file win32/zlib1.rc
|
||||
set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
|
||||
# set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
# On unix-like platforms the library is almost always called libz
|
||||
set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z)
|
||||
set_target_properties( zlibstatic PROPERTIES OUTPUT_NAME z)
|
||||
if(NOT APPLE)
|
||||
set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"")
|
||||
#set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"")
|
||||
endif()
|
||||
elseif(BUILD_SHARED_LIBS AND WIN32)
|
||||
# Creates zlib1.dll when building shared library version
|
||||
set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
|
||||
# set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
|
||||
endif()
|
||||
|
||||
if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
|
||||
install(TARGETS zlib zlibstatic
|
||||
install(TARGETS zlibstatic
|
||||
RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
|
||||
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )
|
||||
|
|
@ -230,20 +230,20 @@ endif()
|
|||
# Example binaries
|
||||
#============================================================================
|
||||
|
||||
add_executable(example test/example.c)
|
||||
target_link_libraries(example zlib)
|
||||
add_test(example example)
|
||||
#add_executable(example test/example.c)
|
||||
#target_link_libraries(example zlib)
|
||||
#add_test(example example)
|
||||
|
||||
add_executable(minigzip test/minigzip.c)
|
||||
target_link_libraries(minigzip zlib)
|
||||
#add_executable(minigzip test/minigzip.c)
|
||||
#target_link_libraries(minigzip zlib)
|
||||
|
||||
if(HAVE_OFF64_T)
|
||||
add_executable(example64 test/example.c)
|
||||
target_link_libraries(example64 zlib)
|
||||
set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
|
||||
add_test(example64 example64)
|
||||
# add_executable(example64 test/example.c)
|
||||
# target_link_libraries(example64 zlib)
|
||||
# set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
|
||||
# add_test(example64 example64)
|
||||
|
||||
add_executable(minigzip64 test/minigzip.c)
|
||||
target_link_libraries(minigzip64 zlib)
|
||||
set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
|
||||
# add_executable(minigzip64 test/minigzip.c)
|
||||
# target_link_libraries(minigzip64 zlib)
|
||||
# set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
if(POLICY CMP0043)
|
||||
cmake_policy(SET CMP0043 OLD)
|
||||
endif()
|
||||
# if(POLICY CMP0043)
|
||||
# cmake_policy(SET CMP0043 OLD)
|
||||
# endif()
|
||||
|
||||
###########
|
||||
# using shared PCH -- this is unusual case for MSVC... so mystery, such hack, many wow. See also: https://stackoverflow.com/questions/645747/sharing-precompiled-headers-between-projects-in-visual-studio/4170902#4170902
|
||||
|
|
@ -100,9 +99,34 @@ endif()
|
|||
add_library(crypto ${CRYPTO})
|
||||
|
||||
add_library(currency_core ${CURRENCY_CORE})
|
||||
add_dependencies(currency_core version rpc ${PCH_LIB_NAME})
|
||||
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 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()
|
||||
|
||||
add_library(rpc ${RPC})
|
||||
add_dependencies(rpc version ${PCH_LIB_NAME})
|
||||
ENABLE_SHARED_PCH(RPC)
|
||||
|
|
@ -111,15 +135,12 @@ add_library(stratum ${STRATUM})
|
|||
add_dependencies(stratum version ${PCH_LIB_NAME})
|
||||
ENABLE_SHARED_PCH(STRATUM)
|
||||
|
||||
add_library(wallet ${WALLET})
|
||||
add_dependencies(wallet version ${PCH_LIB_NAME})
|
||||
ENABLE_SHARED_PCH(WALLET)
|
||||
|
||||
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)
|
||||
|
||||
|
|
|
|||
|
|
@ -315,13 +315,13 @@ namespace tools
|
|||
PROFILE_FUNC("lmdb_db_backend::set");
|
||||
int res = 0;
|
||||
MDB_val key = AUTO_VAL_INIT(key);
|
||||
MDB_val data = AUTO_VAL_INIT(data);
|
||||
MDB_val data[2] = {}; // mdb_put may access data[1] if some flags are set, this may trigger static code analizers, so here we allocate two elements to avoid it
|
||||
key.mv_data = (void*)k;
|
||||
key.mv_size = ks;
|
||||
data.mv_data = (void*)v;
|
||||
data.mv_size = vs;
|
||||
data[0].mv_data = (void*)v;
|
||||
data[0].mv_size = vs;
|
||||
|
||||
res = mdb_put(get_current_tx(), static_cast<MDB_dbi>(h), &key, &data, 0);
|
||||
res = mdb_put(get_current_tx(), static_cast<MDB_dbi>(h), &key, data, 0);
|
||||
CHECK_AND_ASSERT_MESS_LMDB_DB(res, false, "Unable to mdb_put");
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,17 @@
|
|||
#include <intrin.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if !defined(__ORDER_LITTLE_ENDIAN__)
|
||||
#define __ORDER_LITTLE_ENDIAN__ 1011012001
|
||||
#endif
|
||||
|
||||
#if !defined(__BYTE_ORDER__)
|
||||
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
|
||||
#endif
|
||||
|
||||
#if !defined(__ORDER_BIG_ENDIAN__)
|
||||
#define __ORDER_BIG_ENDIAN__ 0
|
||||
#endif
|
||||
|
||||
static inline uint32_t rol32(uint32_t x, int r) {
|
||||
static_assert(sizeof(uint32_t) == sizeof(unsigned int), "this code assumes 32-bit integers");
|
||||
|
|
@ -194,11 +205,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 +228,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
|
||||
|
|
|
|||
|
|
@ -30,13 +30,18 @@ namespace tools
|
|||
char m_lanaddr[64];
|
||||
int m_IGD;
|
||||
boost::thread m_mapper_thread;
|
||||
boost::thread m_initializer_thread;
|
||||
uint32_t m_external_port;
|
||||
uint32_t m_internal_port;
|
||||
uint32_t m_period_ms;
|
||||
public:
|
||||
miniupnp_helper():m_devlist(nullptr),
|
||||
m_urls(AUTO_VAL_INIT(m_urls)),
|
||||
m_data(AUTO_VAL_INIT(m_data)),
|
||||
m_IGD(0),
|
||||
m_external_port{}
|
||||
m_external_port(0),
|
||||
m_internal_port(0),
|
||||
m_period_ms(0)
|
||||
{
|
||||
m_lanaddr[0] = 0;
|
||||
}
|
||||
|
|
@ -52,9 +57,10 @@ namespace tools
|
|||
bool start_regular_mapping(uint32_t internal_port, uint32_t external_port, uint32_t period_ms)
|
||||
{
|
||||
m_external_port = external_port;
|
||||
m_internal_port = internal_port;
|
||||
m_period_ms = period_ms;
|
||||
if(!init())
|
||||
return false;
|
||||
m_mapper_thread = boost::thread([=](){run_port_mapping_loop(internal_port, external_port, period_ms);});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -77,27 +83,42 @@ namespace tools
|
|||
|
||||
bool init()
|
||||
{
|
||||
deinit();
|
||||
m_initializer_thread = boost::thread([=]()
|
||||
{
|
||||
deinit();
|
||||
|
||||
int error = 0;
|
||||
m_devlist = upnpDiscover(2000, nullptr, nullptr, 0, 0, 2, &error);
|
||||
if(error)
|
||||
{
|
||||
LOG_PRINT_L0("Failed to call upnpDiscover");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_IGD = UPNP_GetValidIGD(m_devlist, &m_urls, &m_data, m_lanaddr, sizeof(m_lanaddr));
|
||||
if(m_IGD != 1)
|
||||
{
|
||||
LOG_PRINT_L2("IGD not found");
|
||||
return false;
|
||||
}
|
||||
int error = 0;
|
||||
m_devlist = upnpDiscover(2000, nullptr, nullptr, 0, 0, 2, &error);
|
||||
if (error)
|
||||
{
|
||||
LOG_PRINT_L0("Failed to call upnpDiscover");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_IGD = UPNP_GetValidIGD(m_devlist, &m_urls, &m_data, m_lanaddr, sizeof(m_lanaddr));
|
||||
if (m_IGD != 1)
|
||||
{
|
||||
LOG_PRINT_L2("IGD not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_mapper_thread = boost::thread([=]() {run_port_mapping_loop(m_internal_port, m_external_port, m_period_ms); });
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
bool deinit()
|
||||
{
|
||||
if(m_initializer_thread.get_id() != boost::this_thread::get_id())
|
||||
{
|
||||
if (m_initializer_thread.joinable())
|
||||
{
|
||||
m_initializer_thread.interrupt();
|
||||
m_initializer_thread.join();
|
||||
}
|
||||
}
|
||||
|
||||
stop_mapping();
|
||||
|
||||
if(m_devlist)
|
||||
|
|
|
|||
|
|
@ -1976,6 +1976,72 @@ void ge_scalarmult(ge_p2 *r, const unsigned char *a, const ge_p3 *A) {
|
|||
}
|
||||
}
|
||||
|
||||
/* Assumes that a[31] <= 127 */
|
||||
void ge_scalarmult_p3(ge_p3 *result, const unsigned char *a, const ge_p3 *A) {
|
||||
signed char e[64];
|
||||
int carry, carry2, i;
|
||||
ge_cached Ai[8]; /* 1 * A, 2 * A, ..., 8 * A */
|
||||
ge_p1p1 t;
|
||||
ge_p3 u;
|
||||
ge_p2 r_tmp;
|
||||
ge_p2* r = &r_tmp;
|
||||
|
||||
carry = 0; /* 0..1 */
|
||||
for (i = 0; i < 31; i++) {
|
||||
carry += a[i]; /* 0..256 */
|
||||
carry2 = (carry + 8) >> 4; /* 0..16 */
|
||||
e[2 * i] = carry - (carry2 << 4); /* -8..7 */
|
||||
carry = (carry2 + 8) >> 4; /* 0..1 */
|
||||
e[2 * i + 1] = carry2 - (carry << 4); /* -8..7 */
|
||||
}
|
||||
carry += a[31]; /* 0..128 */
|
||||
carry2 = (carry + 8) >> 4; /* 0..8 */
|
||||
e[62] = carry - (carry2 << 4); /* -8..7 */
|
||||
e[63] = carry2; /* 0..8 */
|
||||
|
||||
ge_p3_to_cached(&Ai[0], A);
|
||||
for (i = 0; i < 7; i++) {
|
||||
ge_add(&t, A, &Ai[i]);
|
||||
ge_p1p1_to_p3(&u, &t);
|
||||
ge_p3_to_cached(&Ai[i + 1], &u);
|
||||
}
|
||||
|
||||
ge_p2_0(r);
|
||||
for (i = 63; i >= 0; i--) {
|
||||
signed char b = e[i];
|
||||
unsigned char bnegative = negative(b);
|
||||
unsigned char babs = b - (((-bnegative) & b) << 1);
|
||||
ge_cached cur, minuscur;
|
||||
ge_p2_dbl(&t, r);
|
||||
ge_p1p1_to_p2(r, &t);
|
||||
ge_p2_dbl(&t, r);
|
||||
ge_p1p1_to_p2(r, &t);
|
||||
ge_p2_dbl(&t, r);
|
||||
ge_p1p1_to_p2(r, &t);
|
||||
ge_p2_dbl(&t, r);
|
||||
ge_p1p1_to_p3(&u, &t);
|
||||
ge_cached_0(&cur);
|
||||
ge_cached_cmov(&cur, &Ai[0], equal(babs, 1));
|
||||
ge_cached_cmov(&cur, &Ai[1], equal(babs, 2));
|
||||
ge_cached_cmov(&cur, &Ai[2], equal(babs, 3));
|
||||
ge_cached_cmov(&cur, &Ai[3], equal(babs, 4));
|
||||
ge_cached_cmov(&cur, &Ai[4], equal(babs, 5));
|
||||
ge_cached_cmov(&cur, &Ai[5], equal(babs, 6));
|
||||
ge_cached_cmov(&cur, &Ai[6], equal(babs, 7));
|
||||
ge_cached_cmov(&cur, &Ai[7], equal(babs, 8));
|
||||
fe_copy(minuscur.YplusX, cur.YminusX);
|
||||
fe_copy(minuscur.YminusX, cur.YplusX);
|
||||
fe_copy(minuscur.Z, cur.Z);
|
||||
fe_neg(minuscur.T2d, cur.T2d);
|
||||
ge_cached_cmov(&cur, &minuscur, bnegative);
|
||||
ge_add(&t, &u, &cur);
|
||||
if (i > 0)
|
||||
ge_p1p1_to_p2(r, &t);
|
||||
else
|
||||
ge_p1p1_to_p3(result, &t); // last iteration
|
||||
}
|
||||
}
|
||||
|
||||
void ge_double_scalarmult_precomp_vartime(ge_p2 *r, const unsigned char *a, const ge_p3 *A, const unsigned char *b, const ge_dsmp Bi) {
|
||||
signed char aslide[256];
|
||||
signed char bslide[256];
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ void sc_reduce(unsigned char *);
|
|||
/* New code */
|
||||
|
||||
void ge_scalarmult(ge_p2 *, const unsigned char *, const ge_p3 *);
|
||||
void ge_scalarmult_p3(ge_p3 *, const unsigned char *, const ge_p3 *);
|
||||
void ge_double_scalarmult_precomp_vartime(ge_p2 *, const unsigned char *, const ge_p3 *, const unsigned char *, const ge_dsmp);
|
||||
void ge_mul8(ge_p1p1 *, const ge_p2 *);
|
||||
extern const fe fe_ma2;
|
||||
|
|
|
|||
|
|
@ -158,7 +158,10 @@ namespace currency
|
|||
account_public_address transform_str_to_addr(const std::string& str)
|
||||
{
|
||||
account_public_address ad = AUTO_VAL_INIT(ad);
|
||||
get_account_address_from_str(ad, str);
|
||||
if (!get_account_address_from_str(ad, str))
|
||||
{
|
||||
LOG_ERROR("cannot parse address from string: " << str);
|
||||
}
|
||||
return ad;
|
||||
}
|
||||
}
|
||||
|
|
@ -70,7 +70,6 @@ using namespace currency;
|
|||
#endif
|
||||
#define BLOCK_POS_STRICT_SEQUENCE_LIMIT 20
|
||||
|
||||
#define CURRENCY_BLOCKCHAINDATA_FOLDERNAME_SUFFIX "_v1"
|
||||
|
||||
DISABLE_VS_WARNINGS(4267)
|
||||
|
||||
|
|
@ -293,14 +292,21 @@ bool blockchain_storage::init(const std::string& config_folder, const boost::pro
|
|||
bool need_reinit = false;
|
||||
if (m_db_blocks.size() != 0)
|
||||
{
|
||||
if (m_db_storage_major_compatibility_version != BLOCKCHAIN_STORAGE_MAJOR_COMPATIBILITY_VERSION)
|
||||
if (m_db_storage_major_compatibility_version == 93 && BLOCKCHAIN_STORAGE_MAJOR_COMPATIBILITY_VERSION == 94)
|
||||
{
|
||||
// do not reinit db if moving from version 93 to version 94
|
||||
LOG_PRINT_MAGENTA("DB storage does not need reinit because moving from v93 to v94", LOG_LEVEL_0);
|
||||
}
|
||||
else if (m_db_storage_major_compatibility_version != BLOCKCHAIN_STORAGE_MAJOR_COMPATIBILITY_VERSION)
|
||||
{
|
||||
need_reinit = true;
|
||||
LOG_PRINT_MAGENTA("DB storage needs reinit because it has major compatibility ver " << m_db_storage_major_compatibility_version << ", expected : " << BLOCKCHAIN_STORAGE_MAJOR_COMPATIBILITY_VERSION, LOG_LEVEL_0);
|
||||
}
|
||||
else if (m_db_storage_minor_compatibility_version != BLOCKCHAIN_STORAGE_MINOR_COMPATIBILITY_VERSION)
|
||||
else if (m_db_storage_minor_compatibility_version > BLOCKCHAIN_STORAGE_MINOR_COMPATIBILITY_VERSION)
|
||||
{
|
||||
// nothing
|
||||
// reinit db only if minor version in the DB is greather (i.e. newer) than minor version in the code
|
||||
need_reinit = true;
|
||||
LOG_PRINT_MAGENTA("DB storage needs reinit because it has minor compatibility ver " << m_db_storage_minor_compatibility_version << " that is greater than BLOCKCHAIN_STORAGE_MINOR_COMPATIBILITY_VERSION: " << BLOCKCHAIN_STORAGE_MINOR_COMPATIBILITY_VERSION, LOG_LEVEL_0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -528,17 +534,22 @@ bool blockchain_storage::prune_ring_signatures_and_attachments_if_need()
|
|||
{
|
||||
CRITICAL_REGION_LOCAL(m_read_lock);
|
||||
|
||||
if(m_db_blocks.size() && m_checkpoints.get_top_checkpoint_height() && m_checkpoints.get_top_checkpoint_height() > m_db_current_pruned_rs_height)
|
||||
if (m_db_blocks.size() > 1 && m_checkpoints.get_top_checkpoint_height() && m_checkpoints.get_top_checkpoint_height() > m_db_current_pruned_rs_height)
|
||||
{
|
||||
LOG_PRINT_CYAN("Starting pruning ring signatues and attachments...", LOG_LEVEL_0);
|
||||
uint64_t tx_count = 0, sig_count = 0, attach_count = 0;
|
||||
for(uint64_t height = m_db_current_pruned_rs_height; height < m_db_blocks.size() && height <= m_checkpoints.get_top_checkpoint_height(); height++)
|
||||
uint64_t pruning_last_height = std::min(m_db_blocks.size() - 1, m_checkpoints.get_top_checkpoint_height());
|
||||
if (pruning_last_height > m_db_current_pruned_rs_height)
|
||||
{
|
||||
bool res = prune_ring_signatures_and_attachments(height, tx_count, sig_count, attach_count);
|
||||
CHECK_AND_ASSERT_MES(res, false, "failed to prune_ring_signatures_and_attachments for height = " << height);
|
||||
LOG_PRINT_CYAN("Starting pruning ring signatues and attachments from height " << m_db_current_pruned_rs_height + 1 << " to height " << pruning_last_height
|
||||
<< " (" << pruning_last_height - m_db_current_pruned_rs_height << " blocks)", LOG_LEVEL_0);
|
||||
uint64_t tx_count = 0, sig_count = 0, attach_count = 0;
|
||||
for(uint64_t height = m_db_current_pruned_rs_height + 1; height <= pruning_last_height; height++)
|
||||
{
|
||||
bool res = prune_ring_signatures_and_attachments(height, tx_count, sig_count, attach_count);
|
||||
CHECK_AND_ASSERT_MES(res, false, "failed to prune_ring_signatures_and_attachments for height = " << height);
|
||||
}
|
||||
m_db_current_pruned_rs_height = pruning_last_height;
|
||||
LOG_PRINT_CYAN("Transaction pruning finished: " << sig_count << " signatures and " << attach_count << " attachments released in " << tx_count << " transactions.", LOG_LEVEL_0);
|
||||
}
|
||||
m_db_current_pruned_rs_height = m_checkpoints.get_top_checkpoint_height();
|
||||
LOG_PRINT_CYAN("Transaction pruning finished: " << sig_count << " signatures and " << attach_count << " attachments released in " << tx_count << " transactions.", LOG_LEVEL_0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -641,7 +652,7 @@ bool blockchain_storage::purge_transaction_keyimages_from_blockchain(const trans
|
|||
}
|
||||
};
|
||||
|
||||
BOOST_FOREACH(const txin_v& in, tx.vin)
|
||||
for(const txin_v& in : tx.vin)
|
||||
{
|
||||
bool r = boost::apply_visitor(purge_transaction_visitor(*this, m_db_spent_keys, strict_check), in);
|
||||
CHECK_AND_ASSERT_MES(!strict_check || r, false, "failed to process purge_transaction_visitor");
|
||||
|
|
@ -3909,7 +3920,7 @@ bool blockchain_storage::check_tx_inputs(const transaction& tx, const crypto::ha
|
|||
const std::vector<crypto::signature>* psig = &sig_stub;
|
||||
|
||||
TIME_MEASURE_START_PD(tx_check_inputs_loop);
|
||||
BOOST_FOREACH(const auto& txin, tx.vin)
|
||||
for(const auto& txin : tx.vin)
|
||||
{
|
||||
if (!m_is_in_checkpoint_zone)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,12 +9,22 @@
|
|||
#include "checkpoints.h"
|
||||
#include "misc_log_ex.h"
|
||||
|
||||
#define ADD_CHECKPOINT(h, hash) CHECK_AND_ASSERT(checkpoints.add_checkpoint(h, hash), false);
|
||||
#define ADD_CHECKPOINT(h, hash) CHECK_AND_ASSERT(checkpoints.add_checkpoint(h, hash), false)
|
||||
|
||||
namespace currency
|
||||
{
|
||||
|
||||
namespace currency {
|
||||
inline bool create_checkpoints(currency::checkpoints& checkpoints)
|
||||
{
|
||||
#ifdef TESTNET
|
||||
ADD_CHECKPOINT(50000, "cb05a7bdc7f78c5cdb6ef1048f85b27c569f44879233903ce5f5a4e5bd590a3d");
|
||||
ADD_CHECKPOINT(100000, "6b8b54356a9d44f6c1ebdacb8593d8f5ab2e2e2ca4493e7ae7baf4b3755c5e16");
|
||||
#else
|
||||
// MAINNET
|
||||
ADD_CHECKPOINT(425000, "46a6c36d5dec2d484d5e4845a8525ca322aafc06915ed9c8da2a241b51b7d1e8");
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace currency
|
||||
|
|
|
|||
|
|
@ -192,7 +192,9 @@
|
|||
|
||||
|
||||
#define CURRENCY_POOLDATA_FOLDERNAME_PREFIX "poolstate_"
|
||||
#define CURRENCY_POOLDATA_FOLDERNAME_SUFFIX "_v1"
|
||||
#define CURRENCY_BLOCKCHAINDATA_FOLDERNAME_PREFIX "blockchain_"
|
||||
#define CURRENCY_BLOCKCHAINDATA_FOLDERNAME_SUFFIX "_v1"
|
||||
|
||||
#define P2P_NET_DATA_FILENAME "p2pstate.bin"
|
||||
#define MINER_CONFIG_FILENAME "miner_conf.json"
|
||||
|
|
@ -205,7 +207,7 @@
|
|||
#define CURRENT_TRANSACTION_CHAIN_ENTRY_ARCHIVE_VER 3
|
||||
#define CURRENT_BLOCK_EXTENDED_INFO_ARCHIVE_VER 1
|
||||
|
||||
#define BLOCKCHAIN_STORAGE_MAJOR_COMPATIBILITY_VERSION CURRENCY_FORMATION_VERSION + 9
|
||||
#define BLOCKCHAIN_STORAGE_MAJOR_COMPATIBILITY_VERSION CURRENCY_FORMATION_VERSION + 10
|
||||
#define BLOCKCHAIN_STORAGE_MINOR_COMPATIBILITY_VERSION 1
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@
|
|||
|
||||
#include "include_base_utils.h"
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/locale.hpp>
|
||||
#ifndef ANDROID_BUILD
|
||||
#include <boost/locale.hpp>
|
||||
#endif
|
||||
using namespace epee;
|
||||
|
||||
#include "print_fixed_point_helper.h"
|
||||
|
|
@ -625,7 +627,8 @@ namespace currency
|
|||
//put hash into extra
|
||||
std::stringstream ss;
|
||||
binary_archive<true> oar(ss);
|
||||
::do_serialize(oar, const_cast<std::vector<attachment_v>&>(attachment));
|
||||
if (!::do_serialize(oar, const_cast<std::vector<attachment_v>&>(attachment)))
|
||||
return;
|
||||
std::string buff = ss.str();
|
||||
eai.sz = buff.size();
|
||||
eai.hsh = get_blob_hash(buff);
|
||||
|
|
@ -1605,7 +1608,7 @@ namespace currency
|
|||
return true;
|
||||
|
||||
size_t i = 0;
|
||||
BOOST_FOREACH(const tx_out& o, tx.vout)
|
||||
for(const tx_out& o : tx.vout)
|
||||
{
|
||||
if (o.target.type() == typeid(txout_to_key))
|
||||
{
|
||||
|
|
@ -2677,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");
|
||||
|
|
@ -2696,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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ namespace currency {
|
|||
using std::uint64_t;
|
||||
using std::vector;
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#include <windows.h>
|
||||
#include <winnt.h>
|
||||
//#if defined(_MSC_VER)
|
||||
//#include <windows.h>
|
||||
//#include <winnt.h>
|
||||
|
||||
static inline void mul(uint64_t a, uint64_t b, uint64_t &low, uint64_t &high) {
|
||||
boost::multiprecision::uint128_t res = boost::multiprecision::uint128_t(a) * b;
|
||||
|
|
@ -36,7 +36,7 @@ namespace currency {
|
|||
//low = UnsignedMultiply128(a, b, &high);
|
||||
}
|
||||
|
||||
#else
|
||||
/* #else
|
||||
|
||||
static inline void mul(uint64_t a, uint64_t b, uint64_t &low, uint64_t &high) {
|
||||
typedef unsigned __int128 uint128_t;
|
||||
|
|
@ -45,7 +45,7 @@ namespace currency {
|
|||
high = (uint64_t)(res >> 64);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif */
|
||||
|
||||
static inline bool cadd(uint64_t a, uint64_t b) {
|
||||
return a + b < a;
|
||||
|
|
|
|||
|
|
@ -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<sort_offers_func_type> 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<bc_services::offer_details_ex>& 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<size_t>(filter.order_by)];
|
||||
|
|
|
|||
|
|
@ -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<int sort_type>
|
||||
struct sort_id_to_type
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ DISABLE_VS_WARNINGS(4244 4345 4503) //'boost::foreach_detail_::or_' : decorated
|
|||
#define TRANSACTION_POOL_OPTIONS_ID_STORAGE_MAJOR_COMPATIBILITY_VERSION 92 // DON'T CHANGE THIS, if you need to resync db! Change TRANSACTION_POOL_MAJOR_COMPATIBILITY_VERSION instead!
|
||||
#define TRANSACTION_POOL_MAJOR_COMPATIBILITY_VERSION BLOCKCHAIN_STORAGE_MAJOR_COMPATIBILITY_VERSION + 1
|
||||
|
||||
#define CURRENCY_POOLDATA_FOLDERNAME_SUFFIX "_v1"
|
||||
|
||||
#define CONFLICT_KEY_IMAGE_SPENT_DEPTH_TO_REMOVE_TX_FROM_POOL 50 // if there's a conflict in key images between tx in the pool and in the blockchain this much depth in required to remove correspongin tx from pool
|
||||
|
||||
|
|
@ -92,6 +91,16 @@ namespace currency
|
|||
//---------------------------------------------------------------------------------
|
||||
bool tx_memory_pool::add_tx(const transaction &tx, const crypto::hash &id, uint64_t blob_size, tx_verification_context& tvc, bool kept_by_block, bool from_core)
|
||||
{
|
||||
if (!kept_by_block && !from_core && m_blockchain.is_in_checkpoint_zone())
|
||||
{
|
||||
// BCS is in CP zone, tx verification is impossible until it gets synchronized
|
||||
tvc.m_added_to_pool = false;
|
||||
tvc.m_should_be_relayed = false;
|
||||
tvc.m_verification_failed = false;
|
||||
tvc.m_verification_impossible = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
TIME_MEASURE_START_PD(tx_processing_time);
|
||||
TIME_MEASURE_START_PD(check_inputs_types_supported_time);
|
||||
if(!check_inputs_types_supported(tx))
|
||||
|
|
@ -996,12 +1005,12 @@ namespace currency
|
|||
|
||||
std::vector<txv> txs_v;
|
||||
txs_v.reserve(m_db_transactions.size());
|
||||
std::vector<txv*> txs;
|
||||
std::vector<size_t> txs; // selected transactions, vector of indices of txs_v
|
||||
|
||||
|
||||
//keep getting it as a values cz db items cache will keep it as unserialised object stored by shared ptrs
|
||||
m_db_transactions.enumerate_keys([&](uint64_t i, crypto::hash& k){txs_v.resize(i + 1); txs_v[i].first = k; return true;});
|
||||
txs.resize(txs_v.size(), nullptr);
|
||||
txs.resize(txs_v.size(), SIZE_MAX);
|
||||
|
||||
for (uint64_t i = 0; i != txs_v.size(); i++)
|
||||
{
|
||||
|
|
@ -1010,17 +1019,17 @@ namespace currency
|
|||
if (!txs_v[i].second)
|
||||
{
|
||||
LOG_ERROR("Internal tx pool db error: key " << k << " was enumerated as key but couldn't get value");
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
txs[i] = &txs_v[i];
|
||||
txs[i] = i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::sort(txs.begin(), txs.end(), [](txv *a, txv *b) -> bool {
|
||||
std::sort(txs.begin(), txs.end(), [&txs_v](size_t a, size_t b) -> bool {
|
||||
boost::multiprecision::uint128_t a_, b_;
|
||||
a_ = boost::multiprecision::uint128_t(a->second->fee) * b->second->blob_size;
|
||||
b_ = boost::multiprecision::uint128_t(b->second->fee) * a->second->blob_size;
|
||||
a_ = boost::multiprecision::uint128_t(txs_v[a].second->fee) * txs_v[b].second->blob_size;
|
||||
b_ = boost::multiprecision::uint128_t(txs_v[b].second->fee) * txs_v[a].second->blob_size;
|
||||
return a_ > b_;
|
||||
});
|
||||
|
||||
|
|
@ -1040,10 +1049,10 @@ namespace currency
|
|||
|
||||
// scan txs for alias reg requests - if there are such requests, don't process alias updates
|
||||
bool alias_regs_exist = false;
|
||||
for (auto txp : txs)
|
||||
for (auto txi : txs)
|
||||
{
|
||||
tx_extra_info ei = AUTO_VAL_INIT(ei);
|
||||
bool r = parse_and_validate_tx_extra(txp->second->tx, ei);
|
||||
bool r = parse_and_validate_tx_extra(txs_v[txi].second->tx, ei);
|
||||
CHECK_AND_ASSERT_MES(r, false, "parse_and_validate_tx_extra failed while looking up the tx pool");
|
||||
if (!ei.m_alias.m_alias.empty() && !ei.m_alias.m_sign.size()) {
|
||||
alias_regs_exist = true;
|
||||
|
|
@ -1057,12 +1066,12 @@ namespace currency
|
|||
|
||||
for (size_t i = 0; i < txs.size(); i++)
|
||||
{
|
||||
txv &tx(*txs[i]);
|
||||
txv &tx(txs_v[txs[i]]);
|
||||
|
||||
// expiration time check -- skip expired transactions
|
||||
if (is_tx_expired(tx.second->tx, tx_expiration_ts_median))
|
||||
{
|
||||
txs[i] = nullptr;
|
||||
txs[i] = SIZE_MAX;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -1076,7 +1085,7 @@ namespace currency
|
|||
if ((alias_count >= MAX_ALIAS_PER_BLOCK) || // IF this tx registers/updates an alias AND alias per block threshold exceeded
|
||||
(update_an_alias && alias_regs_exist)) // OR this tx updates an alias AND there are alias reg requests...
|
||||
{
|
||||
txs[i] = NULL; // ...skip this tx
|
||||
txs[i] = SIZE_MAX; // ...skip this tx
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
@ -1094,7 +1103,7 @@ namespace currency
|
|||
}
|
||||
|
||||
if (!is_tx_ready_to_go_result || have_key_images(k_images, tx.second->tx)) {
|
||||
txs[i] = NULL;
|
||||
txs[i] = SIZE_MAX;
|
||||
continue;
|
||||
}
|
||||
append_key_images(k_images, tx.second->tx);
|
||||
|
|
@ -1121,17 +1130,18 @@ namespace currency
|
|||
|
||||
for (size_t i = 0; i != txs.size(); i++)
|
||||
{
|
||||
if (txs[i])
|
||||
if (txs[i] != SIZE_MAX)
|
||||
{
|
||||
txv &tx(txs_v[txs[i]]);
|
||||
if (i < best_position)
|
||||
{
|
||||
bl.tx_hashes.push_back(txs[i]->first);
|
||||
bl.tx_hashes.push_back(tx.first);
|
||||
}
|
||||
else if (have_attachment_service_in_container(txs[i]->second->tx.attachment, BC_OFFERS_SERVICE_ID, BC_OFFERS_SERVICE_INSTRUCTION_DEL))
|
||||
else if (have_attachment_service_in_container(tx.second->tx.attachment, BC_OFFERS_SERVICE_ID, BC_OFFERS_SERVICE_INSTRUCTION_DEL))
|
||||
{
|
||||
// BC_OFFERS_SERVICE_INSTRUCTION_DEL transactions has zero fee, so include them here regardless of reward effectiveness
|
||||
bl.tx_hashes.push_back(txs[i]->first);
|
||||
total_size += txs[i]->second->blob_size;
|
||||
bl.tx_hashes.push_back(tx.first);
|
||||
total_size += tx.second->blob_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1165,7 +1175,7 @@ namespace currency
|
|||
uint64_t cache_size_l1 = CACHE_SIZE;
|
||||
LOG_PRINT_GREEN("Using pool db file cache size(L1): " << cache_size_l1, LOG_LEVEL_0);
|
||||
|
||||
// remove old incompartible DB
|
||||
// remove old incompatible DB
|
||||
const std::string old_db_folder_path = m_config_folder + "/" CURRENCY_POOLDATA_FOLDERNAME_OLD;
|
||||
if (boost::filesystem::exists(epee::string_encoding::utf8_to_wstring(old_db_folder_path)))
|
||||
{
|
||||
|
|
@ -1192,8 +1202,6 @@ namespace currency
|
|||
|
||||
res = m_db_transactions.init(TRANSACTION_POOL_CONTAINER_TRANSACTIONS);
|
||||
CHECK_AND_ASSERT_MES(res, false, "Unable to init db container");
|
||||
// res = m_db_key_images_set.init(TRANSACTION_POOL_CONTAINER_KEY_IMAGES);
|
||||
// CHECK_AND_ASSERT_MES(res, false, "Unable to init db container");
|
||||
res = m_db_black_tx_list.init(TRANSACTION_POOL_CONTAINER_BLACK_TX_LIST);
|
||||
CHECK_AND_ASSERT_MES(res, false, "Unable to init db container");
|
||||
res = m_db_alias_names.init(TRANSACTION_POOL_CONTAINER_ALIAS_NAMES);
|
||||
|
|
|
|||
|
|
@ -159,7 +159,6 @@ namespace currency
|
|||
|
||||
typedef tools::db::cached_key_value_accessor<crypto::hash, tx_details, true, false> transactions_container;
|
||||
typedef tools::db::cached_key_value_accessor<crypto::hash, bool, false, false> hash_container;
|
||||
//typedef tools::db::cached_key_value_accessor<crypto::key_image, uint64_t, false, false> key_images_container;
|
||||
typedef tools::db::cached_key_value_accessor<uint64_t, uint64_t, false, true> solo_options_container;
|
||||
typedef tools::db::cached_key_value_accessor<std::string, bool, false, false> aliases_container;
|
||||
typedef tools::db::cached_key_value_accessor<account_public_address, bool, false, false> address_to_aliases_container;
|
||||
|
|
@ -172,7 +171,6 @@ namespace currency
|
|||
|
||||
transactions_container m_db_transactions;
|
||||
hash_container m_db_black_tx_list;
|
||||
//key_images_container m_db_key_images_set;
|
||||
aliases_container m_db_alias_names;
|
||||
address_to_aliases_container m_db_alias_addresses;
|
||||
solo_options_container m_db_solo_options;
|
||||
|
|
|
|||
|
|
@ -179,17 +179,17 @@ namespace currency
|
|||
&& m_core.get_blockchain_storage().get_checkpoints().get_top_checkpoint_height() < hshd.last_checkpoint_height
|
||||
&& m_core.get_current_blockchain_size() < hshd.last_checkpoint_height )
|
||||
{
|
||||
LOG_PRINT_RED("Remote node have longer checkpoints zone( " << hshd.last_checkpoint_height << ") " <<
|
||||
"that local (" << m_core.get_blockchain_storage().get_checkpoints().get_top_checkpoint_height() << ")" <<
|
||||
"That means that current software is outdated, please updated it." <<
|
||||
"Current heigh lay under checkpoints on remote host, so it is not possible validate this transactions on local host, disconnecting.", LOG_LEVEL_0);
|
||||
LOG_PRINT_RED("Remote node has longer checkpoints zone (" << hshd.last_checkpoint_height << ") " <<
|
||||
"than local (" << m_core.get_blockchain_storage().get_checkpoints().get_top_checkpoint_height() << "). " <<
|
||||
"It means that current software is outdated, please updated it! " <<
|
||||
"Current height lays under checkpoints zone on remote host, so it's impossible to validate remote transactions locally, disconnecting.", LOG_LEVEL_0);
|
||||
return false;
|
||||
}
|
||||
else if (m_core.get_blockchain_storage().get_checkpoints().get_top_checkpoint_height() < hshd.last_checkpoint_height)
|
||||
{
|
||||
LOG_PRINT_MAGENTA("Remote node have longer checkpoints zone( " << hshd.last_checkpoint_height << ") " <<
|
||||
"that local (" << m_core.get_blockchain_storage().get_checkpoints().get_top_checkpoint_height() << ")" <<
|
||||
"That means that current software is outdated, please updated it.", LOG_LEVEL_0);
|
||||
LOG_PRINT_MAGENTA("Remote node has longer checkpoints zone (" << hshd.last_checkpoint_height << ") " <<
|
||||
"than local (" << m_core.get_blockchain_storage().get_checkpoints().get_top_checkpoint_height() << "). " <<
|
||||
"It means that current software is outdated, please updated it!", LOG_LEVEL_0);
|
||||
}
|
||||
|
||||
context.m_state = currency_connection_context::state_synchronizing;
|
||||
|
|
|
|||
|
|
@ -304,7 +304,9 @@ bool MainWindow::store_app_config()
|
|||
{
|
||||
TRY_ENTRY();
|
||||
std::string conf_path = m_backend.get_config_folder() + "/" + GUI_INTERNAL_CONFIG;
|
||||
return tools::serialize_obj_to_file(m_config, conf_path);
|
||||
LOG_PRINT_L0("storing gui internal config from " << conf_path);
|
||||
CHECK_AND_ASSERT_MES(tools::serialize_obj_to_file(m_config, conf_path), false, "failed to store gui internal config");
|
||||
return true;
|
||||
CATCH_ENTRY2(false);
|
||||
}
|
||||
|
||||
|
|
@ -312,7 +314,10 @@ bool MainWindow::load_app_config()
|
|||
{
|
||||
TRY_ENTRY();
|
||||
std::string conf_path = m_backend.get_config_folder() + "/" + GUI_INTERNAL_CONFIG;
|
||||
return tools::unserialize_obj_from_file(m_config, conf_path);
|
||||
LOG_PRINT_L0("loading gui internal config from " << conf_path);
|
||||
bool r = tools::unserialize_obj_from_file(m_config, conf_path);
|
||||
LOG_PRINT_L0("gui internal config " << (r ? "loaded ok" : "was not loaded"));
|
||||
return r;
|
||||
CATCH_ENTRY2(false);
|
||||
}
|
||||
|
||||
|
|
@ -1060,13 +1065,13 @@ QString MainWindow::get_secure_app_data(const QString& param)
|
|||
bool r = file_io_utils::load_file_to_string(filename, app_data_buff);
|
||||
if (!r)
|
||||
{
|
||||
LOG_PRINT_L1("config file was not loaded: " << m_backend.get_config_folder() + "/" + GUI_SECURE_CONFIG_FILENAME);
|
||||
LOG_PRINT_L1("gui secure config was not loaded from " << filename);
|
||||
return "";
|
||||
}
|
||||
|
||||
if (app_data_buff.size() < sizeof(app_data_file_binary_header))
|
||||
{
|
||||
LOG_ERROR("app_data_buff.size() < sizeof(app_data_file_binary_header) check failed");
|
||||
LOG_ERROR("app_data_buff.size() < sizeof(app_data_file_binary_header) check failed while loading from " << filename);
|
||||
view::api_response ar;
|
||||
ar.error_code = API_RETURN_CODE_FAIL;
|
||||
return MAKE_RESPONSE(ar);
|
||||
|
|
@ -1077,7 +1082,7 @@ QString MainWindow::get_secure_app_data(const QString& param)
|
|||
const app_data_file_binary_header* phdr = reinterpret_cast<const app_data_file_binary_header*>(app_data_buff.data());
|
||||
if (phdr->m_signature != APP_DATA_FILE_BINARY_SIGNATURE)
|
||||
{
|
||||
LOG_ERROR("password missmatch");
|
||||
LOG_ERROR("gui secure config: password missmatch while loading from " << filename);
|
||||
view::api_response ar;
|
||||
ar.error_code = API_RETURN_CODE_WRONG_PASSWORD;
|
||||
return MAKE_RESPONSE(ar);
|
||||
|
|
@ -1087,7 +1092,7 @@ QString MainWindow::get_secure_app_data(const QString& param)
|
|||
|
||||
crypto::hash master_password_pre_hash = crypto::cn_fast_hash(m_master_password.c_str(), m_master_password.length());
|
||||
crypto::hash master_password_hash = crypto::cn_fast_hash(&master_password_pre_hash, sizeof master_password_pre_hash);
|
||||
LOG_PRINT_L0("get_secure_app_data, pass hash: " << master_password_hash);
|
||||
LOG_PRINT_L0("gui secure config loaded ok from " << filename << ", pass hash: " << master_password_hash);
|
||||
|
||||
return app_data_buff.substr(sizeof(app_data_file_binary_header)).c_str();
|
||||
CATCH_ENTRY2(API_RETURN_CODE_INTERNAL_ERROR);
|
||||
|
|
@ -1161,10 +1166,6 @@ QString MainWindow::store_app_data(const QString& param)
|
|||
return MAKE_RESPONSE(ar);
|
||||
}
|
||||
|
||||
crypto::hash master_password_pre_hash = crypto::cn_fast_hash(m_master_password.c_str(), m_master_password.length());
|
||||
crypto::hash master_password_hash = crypto::cn_fast_hash(&master_password_pre_hash, sizeof master_password_pre_hash);
|
||||
LOG_PRINT_L0("store_app_data, pass hash: " << master_password_hash);
|
||||
|
||||
std::string filename = m_backend.get_config_folder() + "/" + GUI_CONFIG_FILENAME;
|
||||
bool r = file_io_utils::save_string_to_file(filename, param.toStdString());
|
||||
if (r)
|
||||
|
|
@ -1313,6 +1314,8 @@ QString MainWindow::have_secure_app_data()
|
|||
else
|
||||
ar.error_code = API_RETURN_CODE_FALSE;
|
||||
|
||||
LOG_PRINT_L0("have_secure_app_data, r = " << ar.error_code);
|
||||
|
||||
return MAKE_RESPONSE(ar);
|
||||
CATCH_ENTRY_FAIL_API_RESPONCE();
|
||||
}
|
||||
|
|
@ -1328,6 +1331,9 @@ QString MainWindow::drop_secure_app_data()
|
|||
ar.error_code = API_RETURN_CODE_TRUE;
|
||||
else
|
||||
ar.error_code = API_RETURN_CODE_FALSE;
|
||||
|
||||
LOG_PRINT_L0("drop_secure_app_data, r = " << ar.error_code);
|
||||
|
||||
return MAKE_RESPONSE(ar);
|
||||
CATCH_ENTRY_FAIL_API_RESPONCE();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@
|
|||
#include <QtWidgets>
|
||||
#include <QWebChannel>
|
||||
|
||||
#include "view_iface.h"
|
||||
#include "wallet/view_iface.h"
|
||||
#ifndef Q_MOC_RUN
|
||||
#include "daemon_backend.h"
|
||||
#include "wallet/wallets_manager.h"
|
||||
#include "currency_core/offers_services_helpers.h"
|
||||
#endif
|
||||
|
||||
|
|
@ -227,7 +227,7 @@ private:
|
|||
QWebChannel* m_channel;
|
||||
|
||||
// DATA
|
||||
daemon_backend m_backend;
|
||||
wallets_manager m_backend;
|
||||
//std::atomic<bool> m_quit_requested;
|
||||
std::atomic<bool> m_gui_deinitialize_done_1;
|
||||
std::atomic<bool> m_backend_stopped_2;
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -649,7 +649,7 @@ module.exports = function (NAME, wrapper, methods, common, IS_MAP, IS_WEAK) {
|
|||
/*! no static exports found */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
var core = module.exports = { version: '2.6.10' };
|
||||
var core = module.exports = { version: '2.6.11' };
|
||||
if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef
|
||||
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -8,6 +8,7 @@
|
|||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(255, 255, 255, 0.25);
|
||||
z-index: 5;
|
||||
}
|
||||
.modal {
|
||||
position: relative;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@
|
|||
<div class="sidebar-account-row account-title-balance">
|
||||
<span class="title" tooltip="{{ wallet.name }}" placement="top-left" tooltipClass="table-tooltip account-tooltip" [delay]="500" [showWhenNoOverflow]="false">{{wallet.name}}</span>
|
||||
<span class="balance">{{wallet.balance | intToMoney : '3' }} {{variablesService.defaultCurrency}}</span>
|
||||
<button type="button" (click)="showDialog(wallet.wallet_id)" tooltip="{{ 'WALLET.TOOLTIPS.CLOSE' | translate }}" placement="top-left" tooltipClass="table-tooltip account-tooltip" [delay]="500" [timeDelay]="500">
|
||||
<i class="icon close-wallet"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="sidebar-account-row account-alias">
|
||||
<div class="name">
|
||||
|
|
@ -155,3 +158,4 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<app-confirm-modal *ngIf="isModalDialogVisible" [title]=" 'WALLET.CONFIRM.TITLE' | translate " [message]=" 'WALLET.CONFIRM.MESSAGE' | translate " (confirmed)="confirmed($event)"></app-confirm-modal>
|
||||
|
|
|
|||
|
|
@ -179,6 +179,31 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: transparent;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
font-weight: 400;
|
||||
outline: none;
|
||||
padding: 0;
|
||||
padding-bottom: 5rem;
|
||||
position: absolute;
|
||||
left: 105%;
|
||||
|
||||
.icon {
|
||||
margin-right: 1.2rem;
|
||||
width: 1.3rem;
|
||||
height: 1.3rem;
|
||||
|
||||
&.close-wallet {
|
||||
mask: url(../../assets/icons/close-wallet.svg) no-repeat center;
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&:focus {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@ export class SidebarComponent implements OnInit, OnDestroy {
|
|||
settings = icons.settings;
|
||||
exit = icons.exit;
|
||||
|
||||
isModalDialogVisible = false;
|
||||
closeWalletId: number;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
|
|
@ -68,6 +71,39 @@ export class SidebarComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
}
|
||||
|
||||
showDialog(wallet_id) {
|
||||
this.isModalDialogVisible = true;
|
||||
this.closeWalletId = wallet_id;
|
||||
}
|
||||
|
||||
confirmed(confirmed: boolean) {
|
||||
if (confirmed) {
|
||||
this.closeWallet(this.closeWalletId);
|
||||
}
|
||||
this.isModalDialogVisible = false;
|
||||
}
|
||||
|
||||
closeWallet(wallet_id) {
|
||||
this.backend.closeWallet(wallet_id, () => {
|
||||
for (let i = this.variablesService.wallets.length - 1; i >= 0; i--) {
|
||||
if (this.variablesService.wallets[i].wallet_id === this.variablesService.currentWallet.wallet_id) {
|
||||
this.variablesService.wallets.splice(i, 1);
|
||||
}
|
||||
}
|
||||
this.ngZone.run(() => {
|
||||
if (this.variablesService.wallets.length) {
|
||||
this.variablesService.currentWallet = this.variablesService.wallets[0];
|
||||
this.router.navigate(['/wallet/' + this.variablesService.currentWallet.wallet_id]);
|
||||
} else {
|
||||
this.router.navigate(['/']);
|
||||
}
|
||||
});
|
||||
if (this.variablesService.appPass) {
|
||||
this.backend.storeSecureAppData();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getUpdate() {
|
||||
this.backend.openUrlInBrowser('zano.org/downloads.html');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,9 +17,6 @@
|
|||
<button [routerLink]="['/details']" routerLinkActive="active" tooltip="{{ 'WALLET.TOOLTIPS.SETTINGS' | translate }}" placement="left" tooltipClass="table-tooltip account-tooltip" [delay]="500" [timeDelay]="500">
|
||||
<i class="icon details"></i>
|
||||
</button>
|
||||
<button type="button" (click)="showDialog()" tooltip="{{ 'WALLET.TOOLTIPS.CLOSE' | translate }}" placement="bottom-right" tooltipClass="table-tooltip account-tooltip" [delay]="500" [timeDelay]="500">
|
||||
<i class="icon close-wallet"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="address">
|
||||
|
|
@ -57,5 +54,3 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<app-confirm-modal *ngIf="isModalDialogVisible" [title]=" 'WALLET.CONFIRM.TITLE' | translate " [message]=" 'WALLET.CONFIRM.MESSAGE' | translate " (confirmed)="confirmed($event)"></app-confirm-modal>
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ export class WalletComponent implements OnInit, OnDestroy {
|
|||
copyAnimation = false;
|
||||
copyAnimationTimeout;
|
||||
balanceTooltip;
|
||||
isModalDialogVisible = false;
|
||||
activeTab = 'history';
|
||||
|
||||
public currentPage = 1;
|
||||
|
|
@ -189,38 +188,6 @@ export class WalletComponent implements OnInit, OnDestroy {
|
|||
this.backend.openUrlInBrowser(link);
|
||||
}
|
||||
|
||||
showDialog() {
|
||||
this.isModalDialogVisible = true;
|
||||
}
|
||||
|
||||
confirmed(confirmed: boolean) {
|
||||
if (confirmed) {
|
||||
this.closeWallet();
|
||||
}
|
||||
this.isModalDialogVisible = false;
|
||||
}
|
||||
|
||||
closeWallet() {
|
||||
this.backend.closeWallet(this.variablesService.currentWallet.wallet_id, () => {
|
||||
for (let i = this.variablesService.wallets.length - 1; i >= 0; i--) {
|
||||
if (this.variablesService.wallets[i].wallet_id === this.variablesService.currentWallet.wallet_id) {
|
||||
this.variablesService.wallets.splice(i, 1);
|
||||
}
|
||||
}
|
||||
this.ngZone.run(() => {
|
||||
if (this.variablesService.wallets.length) {
|
||||
this.variablesService.currentWallet = this.variablesService.wallets[0];
|
||||
this.router.navigate(['/wallet/' + this.variablesService.currentWallet.wallet_id]);
|
||||
} else {
|
||||
this.router.navigate(['/']);
|
||||
}
|
||||
});
|
||||
if (this.variablesService.appPass) {
|
||||
this.backend.storeSecureAppData();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public setPage(pageNumber: number) {
|
||||
if (pageNumber === this.variablesService.currentWallet.currentPage) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -880,10 +880,10 @@ namespace currency
|
|||
}
|
||||
//@#@
|
||||
//temporary double check timestamp
|
||||
if (time(NULL) - get_actual_timestamp(b) > 5)
|
||||
if (time(NULL) - static_cast<int64_t>(get_actual_timestamp(b)) > 5)
|
||||
{
|
||||
LOG_PRINT_RED_L0("Found block (" << get_block_hash(b) << ") timestamp (" << get_actual_timestamp(b)
|
||||
<< ") is suspiciously less (" << time(NULL) - get_actual_timestamp(b) << ") then curren time( " << time(NULL) << ")");
|
||||
<< ") is suspiciously less (" << time(NULL) - static_cast<int64_t>(get_actual_timestamp(b)) << ") than current time ( " << time(NULL) << ")");
|
||||
//mark node to make it easier to find it via scanner
|
||||
m_core.get_blockchain_storage().get_performnce_data().epic_failure_happend = true;
|
||||
}
|
||||
|
|
@ -937,10 +937,10 @@ namespace currency
|
|||
}
|
||||
//@#@
|
||||
//temporary double check timestamp
|
||||
if (time(NULL) - get_actual_timestamp(b) > 5)
|
||||
if (time(NULL) - static_cast<int64_t>(get_actual_timestamp(b)) > 5)
|
||||
{
|
||||
LOG_PRINT_RED_L0("Found block (" << get_block_hash(b) << ") timestamp (" << get_actual_timestamp(b)
|
||||
<< ") is suspiciously less (" << time(NULL) - get_actual_timestamp(b) << ") then curren time( " << time(NULL) << ")");
|
||||
<< ") is suspiciously less (" << time(NULL) - static_cast<int64_t>(get_actual_timestamp(b)) << ") than current time ( " << time(NULL) << ")");
|
||||
//mark node to make it easier to find it via scanner
|
||||
m_core.get_blockchain_storage().get_performnce_data().epic_failure_happend = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,7 +155,6 @@ namespace currency
|
|||
MAP_JON_RPC ("get_current_core_tx_expiration_median", on_get_current_core_tx_expiration_median, COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN)
|
||||
//
|
||||
MAP_JON_RPC_WE("marketplace_global_get_offers_ex", on_get_offers_ex, COMMAND_RPC_GET_OFFERS_EX)
|
||||
|
||||
//remote miner rpc
|
||||
MAP_JON_RPC_N(on_login, mining::COMMAND_RPC_LOGIN)
|
||||
MAP_JON_RPC_N(on_getjob, mining::COMMAND_RPC_GETJOB)
|
||||
|
|
|
|||
|
|
@ -1195,7 +1195,7 @@ bool simple_wallet::transfer(const std::vector<std::string> &args_)
|
|||
|
||||
|
||||
std::vector<currency::attachment_v> attachments;
|
||||
if (!set_payment_id_to_tx(attachments, payment_id))
|
||||
if (!payment_id.empty() && !set_payment_id_to_tx(attachments, payment_id))
|
||||
{
|
||||
fail_msg_writer() << "provided (or embedded) payment id can't be set: \"" << payment_id << "\"";
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
|
||||
#define PROJECT_MAJOR_VERSION "1"
|
||||
#define PROJECT_MINOR_VERSION "1"
|
||||
#define PROJECT_REVISION "4"
|
||||
#define PROJECT_REVISION "5"
|
||||
#define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION
|
||||
|
||||
#define PROJECT_VERSION_BUILD_NO 77
|
||||
#define PROJECT_VERSION_BUILD_NO 79
|
||||
#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 "]"
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
#include "core_rpc_proxy.h"
|
||||
#include "storages/http_abstract_invoke.h"
|
||||
|
||||
#define WALLET_RCP_CONNECTION_TIMEOUT 200000
|
||||
#define WALLET_RCP_CONNECTION_TIMEOUT 10000
|
||||
#define WALLET_RCP_COUNT_ATTEMNTS 3
|
||||
|
||||
namespace tools
|
||||
|
|
@ -63,7 +63,10 @@ namespace tools
|
|||
ret = request();
|
||||
}
|
||||
|
||||
m_plast_daemon_is_disconnected->store(!ret);
|
||||
if (ret)
|
||||
m_last_success_interract_time = time(nullptr);
|
||||
else
|
||||
*m_plast_daemon_is_disconnected = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -90,10 +93,16 @@ namespace tools
|
|||
return epee::net_utils::invoke_http_json_remote_command2(m_daemon_address + url, req, res, m_http_client, WALLET_RCP_CONNECTION_TIMEOUT);
|
||||
});
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
virtual time_t get_last_success_interract_time()
|
||||
{
|
||||
return m_last_success_interract_time;
|
||||
}
|
||||
|
||||
epee::critical_section m_lock;
|
||||
epee::net_utils::http::http_simple_client m_http_client;
|
||||
std::string m_daemon_address;
|
||||
std::atomic<time_t> m_last_success_interract_time;
|
||||
std::atomic<bool> *m_plast_daemon_is_disconnected;
|
||||
std::atomic<bool> m_last_daemon_is_disconnected_stub;
|
||||
|
||||
|
|
|
|||
|
|
@ -138,6 +138,11 @@ namespace tools
|
|||
{
|
||||
return tools::get_transfer_address(adr_str, addr, payment_id, this);
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
virtual time_t get_last_success_interract_time()
|
||||
{
|
||||
return time(nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
currency::core_rpc_server& m_rpc;
|
||||
|
|
@ -45,6 +45,7 @@ namespace tools
|
|||
|
||||
|
||||
virtual bool check_connection(){ return false; }
|
||||
virtual time_t get_last_success_interract_time() { return 0; }
|
||||
virtual bool get_transfer_address(const std::string& adr_str, currency::account_public_address& addr, std::string& payment_id){ return false; }
|
||||
};
|
||||
}
|
||||
|
|
|
|||
302
src/wallet/plain_wallet_api.cpp
Normal file
302
src/wallet/plain_wallet_api.cpp
Normal file
|
|
@ -0,0 +1,302 @@
|
|||
// Copyright (c) 2014-2020 Zano Project
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
|
||||
#include "plain_wallet_api.h"
|
||||
#include "plain_wallet_api_impl.h"
|
||||
#include "currency_core/currency_config.h"
|
||||
#include "version.h"
|
||||
#include "string_tools.h"
|
||||
#include "currency_core/currency_format_utils.h"
|
||||
#include "wallets_manager.h"
|
||||
|
||||
#define ANDROID_PACKAGE_NAME "com.zano_mobile"
|
||||
#ifdef IOS_BUILD
|
||||
#define HOME_FOLDER "Documents"
|
||||
#elif ANDROID_BUILD
|
||||
#define HOME_FOLDER "files"
|
||||
#else
|
||||
#define HOME_FOLDER ""
|
||||
#endif
|
||||
#define WALLETS_FOLDER_NAME "wallets"
|
||||
|
||||
#define GENERAL_INTERNAL_ERRROR_INSTANCE "GENERAL_INTERNAL_ERROR: WALLET INSTNACE NOT FOUND"
|
||||
#define GENERAL_INTERNAL_ERRROR_INIT "Failed to intialize library"
|
||||
|
||||
//TODO: global object, subject to refactoring
|
||||
wallets_manager gwm;
|
||||
std::atomic<bool> initialized(false);
|
||||
|
||||
std::atomic<uint64_t> gjobs_counter(1);
|
||||
std::map<uint64_t, std::string> gjobs;
|
||||
epee::critical_section gjobs_lock;
|
||||
|
||||
namespace plain_wallet
|
||||
{
|
||||
typedef epee::json_rpc::response<epee::json_rpc::dummy_result, error> 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()
|
||||
{
|
||||
#ifdef WIN32
|
||||
return "";
|
||||
#else
|
||||
std::string path = get_bundle_root_dir() + "/" + HOME_FOLDER + "/" + WALLETS_FOLDER_NAME + "/";
|
||||
return path;
|
||||
#endif // WIN32
|
||||
}
|
||||
|
||||
void initialize_logs()
|
||||
{
|
||||
std::string log_dir = get_bundle_root_dir();
|
||||
log_dir += "/" HOME_FOLDER;
|
||||
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");
|
||||
|
||||
//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<char*>(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);
|
||||
initialized = true;
|
||||
return API_RETURN_CODE_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string get_version()
|
||||
{
|
||||
return PROJECT_VERSION_LONG;
|
||||
}
|
||||
|
||||
struct strings_list
|
||||
{
|
||||
std::list<std::string> items;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(items)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
|
||||
};
|
||||
|
||||
std::string get_wallet_files()
|
||||
{
|
||||
std::string wallet_files_path = get_wallets_folder();
|
||||
strings_list sl = AUTO_VAL_INIT(sl);
|
||||
epee::file_io_utils::get_folder_content(wallet_files_path, sl.items, true);
|
||||
return epee::serialization::store_t_to_json(sl);
|
||||
}
|
||||
|
||||
std::string open(const std::string& path, const std::string& password)
|
||||
{
|
||||
std::string full_path = get_wallets_folder() + path;
|
||||
epee::json_rpc::response<view::open_wallet_response, epee::json_rpc::dummy_error> 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)
|
||||
{
|
||||
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<view::open_wallet_response, epee::json_rpc::dummy_error> 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);
|
||||
}
|
||||
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 generate(const std::string& path, const std::string& password)
|
||||
{
|
||||
std::string full_path = get_wallets_folder() + path;
|
||||
epee::json_rpc::response<view::open_wallet_response, epee::json_rpc::dummy_error> 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 close_wallet(hwallet h)
|
||||
{
|
||||
std::string r = "{\"response\": \"";
|
||||
r += gwm.close_wallet(h);
|
||||
r += "\"}";
|
||||
return r;
|
||||
}
|
||||
|
||||
std::string get_wallet_status(hwallet h)
|
||||
{
|
||||
return gwm.get_wallet_status(h);
|
||||
}
|
||||
std::string invoke(hwallet h, const std::string& params)
|
||||
{
|
||||
return gwm.invoke(h, params);
|
||||
}
|
||||
|
||||
void put_result(uint64_t job_id, const std::string& res)
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(gjobs_lock);
|
||||
gjobs[job_id] = res;
|
||||
LOG_PRINT_L0("[ASYNC_CALL]: Finished(result put), job id: " << job_id);
|
||||
}
|
||||
|
||||
|
||||
std::string async_call(const std::string& method_name, uint64_t instance_id, const std::string& params)
|
||||
{
|
||||
std::function<void()> async_callback;
|
||||
|
||||
uint64_t job_id = gjobs_counter++;
|
||||
if (method_name == "close")
|
||||
{
|
||||
async_callback = [job_id, instance_id]()
|
||||
{
|
||||
close_wallet(instance_id);
|
||||
view::api_responce_return_code rc = AUTO_VAL_INIT(rc);
|
||||
rc.return_code = API_RETURN_CODE_OK;
|
||||
put_result(job_id, epee::serialization::store_t_to_json(rc));
|
||||
};
|
||||
}
|
||||
else if (method_name == "open")
|
||||
{
|
||||
view::open_wallet_request owr = AUTO_VAL_INIT(owr);
|
||||
if (!epee::serialization::load_t_from_json(owr, params))
|
||||
{
|
||||
view::api_response ar = AUTO_VAL_INIT(ar);
|
||||
ar.error_code = "Wrong parameter";
|
||||
put_result(job_id, epee::serialization::store_t_to_json(ar));
|
||||
}
|
||||
async_callback = [job_id, owr]()
|
||||
{
|
||||
std::string res = open(owr.path, owr.pass);
|
||||
put_result(job_id, res);
|
||||
};
|
||||
}
|
||||
else if (method_name == "restore")
|
||||
{
|
||||
view::restore_wallet_request rwr = AUTO_VAL_INIT(rwr);
|
||||
if (!epee::serialization::load_t_from_json(rwr, params))
|
||||
{
|
||||
view::api_response ar = AUTO_VAL_INIT(ar);
|
||||
ar.error_code = "Wrong parameter";
|
||||
put_result(job_id, epee::serialization::store_t_to_json(ar));
|
||||
}
|
||||
async_callback = [job_id, rwr]()
|
||||
{
|
||||
std::string res = restore(rwr.restore_key, rwr.path, rwr.pass);
|
||||
put_result(job_id, res);
|
||||
};
|
||||
}
|
||||
else if (method_name == "invoke")
|
||||
{
|
||||
std::string local_params = params;
|
||||
async_callback = [job_id, local_params, instance_id]()
|
||||
{
|
||||
std::string res = invoke(instance_id, local_params);
|
||||
put_result(job_id, res);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
view::api_response ar = AUTO_VAL_INIT(ar);
|
||||
ar.error_code = "UNKNOWN METHOD";
|
||||
put_result(job_id, epee::serialization::store_t_to_json(ar));
|
||||
return std::string("{ \"job_id\": ") + std::to_string(job_id) + "}";;
|
||||
}
|
||||
|
||||
|
||||
std::thread t([async_callback]() {async_callback(); });
|
||||
t.detach();
|
||||
LOG_PRINT_L0("[ASYNC_CALL]: started " << method_name << ", job id: " << job_id);
|
||||
return std::string("{ \"job_id\": ") + std::to_string(job_id) + "}";
|
||||
}
|
||||
|
||||
std::string try_pull_result(uint64_t job_id)
|
||||
{
|
||||
//TODO: need refactoring
|
||||
CRITICAL_REGION_LOCAL(gjobs_lock);
|
||||
auto it = gjobs.find(job_id);
|
||||
if (it == gjobs.end())
|
||||
{
|
||||
return "{\"delivered\": false}";
|
||||
}
|
||||
std::string res = "{\"delivered\": true, \"result\": ";
|
||||
res += it->second;
|
||||
res += " }";
|
||||
gjobs.erase(it);
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
28
src/wallet/plain_wallet_api.h
Normal file
28
src/wallet/plain_wallet_api.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (c) 2014-2020 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 <string>
|
||||
|
||||
namespace plain_wallet
|
||||
{
|
||||
typedef int64_t hwallet;
|
||||
std::string init(const std::string& ip, const std::string& port);
|
||||
std::string get_version();
|
||||
std::string get_wallet_files();
|
||||
|
||||
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 get_wallet_status(hwallet h);
|
||||
std::string close_wallet(hwallet h);
|
||||
std::string invoke(hwallet h, const std::string& params);
|
||||
|
||||
//async api
|
||||
std::string async_call(const std::string& method_name, uint64_t instance_id, const std::string& params);
|
||||
std::string try_pull_result(uint64_t);
|
||||
}
|
||||
50
src/wallet/plain_wallet_api_defs.h
Normal file
50
src/wallet/plain_wallet_api_defs.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// Copyright (c) 2014-2020 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 "net/http_server_handlers_map2.h"
|
||||
#include "view_iface.h"
|
||||
|
||||
namespace plain_wallet
|
||||
{
|
||||
struct error
|
||||
{
|
||||
std::string code;
|
||||
std::string message;
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(code)
|
||||
KV_SERIALIZE(message)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
||||
struct open_wallet_response
|
||||
{
|
||||
view::transfers_array recent_history;
|
||||
view::wallet_info wi;
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(recent_history)
|
||||
KV_SERIALIZE(wi)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct sync_status_response
|
||||
{
|
||||
bool finished;
|
||||
uint64_t progress;
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(finished)
|
||||
KV_SERIALIZE(progress)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct basic_status_response
|
||||
{
|
||||
std::string status;
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(status)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
} // namespace tools
|
||||
176
src/wallet/plain_wallet_api_impl.cpp
Normal file
176
src/wallet/plain_wallet_api_impl.cpp
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
// 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.
|
||||
|
||||
#include "plain_wallet_api_impl.h"
|
||||
#include "wallet/wallet_helpers.h"
|
||||
|
||||
namespace plain_wallet
|
||||
{
|
||||
typedef epee::json_rpc::response<epee::json_rpc::dummy_result, error> error_response;
|
||||
|
||||
plain_wallet_api_impl::plain_wallet_api_impl(const std::string& ip, const std::string& port):
|
||||
m_stop(false),
|
||||
m_sync_finished(false)
|
||||
{
|
||||
m_wallet.reset(new tools::wallet2());
|
||||
m_wallet->init(ip + ":" + port);
|
||||
m_rpc_wrapper.reset(new tools::wallet_rpc_server(*m_wallet));
|
||||
}
|
||||
|
||||
plain_wallet_api_impl::~plain_wallet_api_impl()
|
||||
{
|
||||
if (m_sync_thread.joinable())
|
||||
m_sync_thread.join();
|
||||
}
|
||||
|
||||
std::string plain_wallet_api_impl::open(const std::string& path, const std::string& password)
|
||||
{
|
||||
error_response err_result = AUTO_VAL_INIT(err_result);
|
||||
try
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_wallet_lock);
|
||||
m_wallet->load(epee::string_encoding::utf8_to_wstring(path), password);
|
||||
epee::json_rpc::response<open_wallet_response, epee::json_rpc::dummy_error> ok_response = AUTO_VAL_INIT(ok_response);
|
||||
m_wallet->get_recent_transfers_history(ok_response.result.recent_history.history, 0, 20, ok_response.result.recent_history.total_history_items);
|
||||
m_wallet->get_unconfirmed_transfers(ok_response.result.recent_history.history);
|
||||
tools::get_wallet_info(*m_wallet, ok_response.result.wi);
|
||||
return epee::serialization::store_t_to_json(ok_response);
|
||||
}
|
||||
catch (const tools::error::wallet_load_notice_wallet_restored& e)
|
||||
{
|
||||
LOG_ERROR("Wallet initialize was with problems, but still worked : " << e.what());
|
||||
err_result.error.code = API_RETURN_CODE_FILE_RESTORED;
|
||||
return epee::serialization::store_t_to_json(err_result);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
LOG_ERROR("Wallet initialize failed: " << e.what());
|
||||
err_result.error.code = API_RETURN_CODE_FAIL;
|
||||
return epee::serialization::store_t_to_json(err_result);
|
||||
}
|
||||
}
|
||||
|
||||
std::string plain_wallet_api_impl::restore(const std::string& seed, const std::string& path, const std::string& password)
|
||||
{
|
||||
error_response err_result = AUTO_VAL_INIT(err_result);
|
||||
try
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_wallet_lock);
|
||||
m_wallet->restore(epee::string_encoding::utf8_to_wstring(path), password, seed);
|
||||
epee::json_rpc::response<open_wallet_response, epee::json_rpc::dummy_error> ok_response = AUTO_VAL_INIT(ok_response);
|
||||
tools::get_wallet_info(*m_wallet, ok_response.result.wi);
|
||||
return epee::serialization::store_t_to_json(ok_response);
|
||||
|
||||
}
|
||||
catch (const tools::error::wallet_load_notice_wallet_restored& e)
|
||||
{
|
||||
LOG_ERROR("Wallet initialize was with problems, but still worked : " << e.what());
|
||||
err_result.error.code = API_RETURN_CODE_FILE_RESTORED;
|
||||
return epee::serialization::store_t_to_json(err_result);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
LOG_ERROR("Wallet initialize failed: " << e.what());
|
||||
err_result.error.code = API_RETURN_CODE_FAIL;
|
||||
return epee::serialization::store_t_to_json(err_result);
|
||||
}
|
||||
}
|
||||
|
||||
std::string plain_wallet_api_impl::generate(const std::string& path, const std::string& password)
|
||||
{
|
||||
error_response err_result = AUTO_VAL_INIT(err_result);
|
||||
try
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_wallet_lock);
|
||||
m_wallet->generate(epee::string_encoding::utf8_to_wstring(path), password);
|
||||
epee::json_rpc::response<open_wallet_response, epee::json_rpc::dummy_error> ok_response = AUTO_VAL_INIT(ok_response);
|
||||
tools::get_wallet_info(*m_wallet, ok_response.result.wi);
|
||||
return epee::serialization::store_t_to_json(ok_response);
|
||||
}
|
||||
catch (const tools::error::wallet_load_notice_wallet_restored& e)
|
||||
{
|
||||
LOG_ERROR("Wallet initialize was with problems, but still worked : " << e.what());
|
||||
err_result.error.code = API_RETURN_CODE_FILE_RESTORED;
|
||||
return epee::serialization::store_t_to_json(err_result);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
LOG_ERROR("Wallet initialize failed: " << e.what());
|
||||
err_result.error.code = API_RETURN_CODE_FAIL;
|
||||
return epee::serialization::store_t_to_json(err_result);
|
||||
}
|
||||
}
|
||||
|
||||
std::string plain_wallet_api_impl::start_sync_thread()
|
||||
{
|
||||
m_sync_thread = std::thread([&]()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_wallet_lock);
|
||||
m_wallet->refresh(m_stop);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
LOG_ERROR("Wallet refresh failed: " << e.what());
|
||||
return;
|
||||
}
|
||||
m_sync_finished = true;
|
||||
});
|
||||
basic_status_response bsr = AUTO_VAL_INIT(bsr);
|
||||
bsr.status = API_RETURN_CODE_OK;
|
||||
return epee::serialization::store_t_to_json(bsr);
|
||||
}
|
||||
|
||||
std::string plain_wallet_api_impl::cancel_sync_thread()
|
||||
{
|
||||
m_stop = true;
|
||||
if (m_sync_thread.joinable())
|
||||
m_sync_thread.join();
|
||||
basic_status_response bsr = AUTO_VAL_INIT(bsr);
|
||||
bsr.status = API_RETURN_CODE_OK;
|
||||
return epee::serialization::store_t_to_json(bsr);
|
||||
|
||||
}
|
||||
|
||||
std::string plain_wallet_api_impl::get_sync_status()
|
||||
{
|
||||
sync_status_response ssr = AUTO_VAL_INIT(ssr);
|
||||
ssr.finished = m_sync_finished;
|
||||
ssr.progress = m_wallet->get_sync_progress();
|
||||
return epee::serialization::store_t_to_json(ssr);
|
||||
}
|
||||
|
||||
std::string plain_wallet_api_impl::sync()
|
||||
{
|
||||
basic_status_response bsr = AUTO_VAL_INIT(bsr);
|
||||
try
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_wallet_lock);
|
||||
m_wallet->refresh(m_stop);
|
||||
bsr.status = API_RETURN_CODE_OK;
|
||||
return epee::serialization::store_t_to_json(bsr);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
LOG_ERROR("Wallet refresh failed: " << e.what());
|
||||
bsr.status = API_RETURN_CODE_FAIL;
|
||||
return epee::serialization::store_t_to_json(bsr);
|
||||
}
|
||||
}
|
||||
std::string plain_wallet_api_impl::invoke(const std::string& params)
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_wallet_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;
|
||||
m_rpc_wrapper->handle_http_request_map(query_info, response_info, stub_conn_context, call_found, reference_stub);
|
||||
return response_info.m_body;
|
||||
}
|
||||
}
|
||||
40
src/wallet/plain_wallet_api_impl.h
Normal file
40
src/wallet/plain_wallet_api_impl.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (c) 2014-2020 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 <string>
|
||||
#include "wallet2.h"
|
||||
#include "wallet_rpc_server.h"
|
||||
#include "plain_wallet_api_defs.h"
|
||||
|
||||
namespace plain_wallet
|
||||
{
|
||||
class plain_wallet_api_impl
|
||||
{
|
||||
public:
|
||||
plain_wallet_api_impl(const std::string& ip, const std::string& port);
|
||||
~plain_wallet_api_impl();
|
||||
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();
|
||||
std::string cancel_sync_thread();
|
||||
std::string get_sync_status();
|
||||
|
||||
std::string sync();
|
||||
std::string invoke(const std::string& params);
|
||||
private:
|
||||
bool get_wallet_info(view::wallet_info& wi);
|
||||
std::thread m_sync_thread;
|
||||
epee::critical_section m_wallet_lock;
|
||||
std::atomic<bool> m_stop;
|
||||
std::atomic<bool> m_sync_finished;
|
||||
std::shared_ptr<tools::wallet2> m_wallet;
|
||||
std::shared_ptr<tools::wallet_rpc_server> m_rpc_wrapper;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <QObject>
|
||||
#ifndef Q_MOC_RUN
|
||||
// #include <stdint.h>
|
||||
// #include <QObject>
|
||||
// #ifndef Q_MOC_RUN
|
||||
#include "warnings.h"
|
||||
|
||||
PUSH_VS_WARNINGS
|
||||
|
|
@ -22,7 +22,7 @@ DISABLE_VS_WARNINGS(4503)
|
|||
#include "currency_core/basic_api_response_codes.h"
|
||||
POP_VS_WARNINGS
|
||||
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
namespace view
|
||||
{
|
||||
|
|
@ -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,23 @@ public:
|
|||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct wallet_sync_status_info
|
||||
{
|
||||
bool is_daemon_connected;
|
||||
uint64_t wallet_state;
|
||||
bool is_in_long_refresh;
|
||||
uint64_t progress;
|
||||
uint64_t current_daemon_height;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(is_daemon_connected)
|
||||
KV_SERIALIZE(wallet_state)
|
||||
KV_SERIALIZE(is_in_long_refresh)
|
||||
KV_SERIALIZE(progress)
|
||||
KV_SERIALIZE(current_daemon_height)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct get_restore_info_response
|
||||
{
|
||||
std::string restore_key;
|
||||
|
|
@ -700,6 +721,14 @@ public:
|
|||
};
|
||||
|
||||
|
||||
struct api_responce_return_code
|
||||
{
|
||||
std::string return_code;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(return_code)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
||||
struct api_void
|
||||
|
|
@ -745,6 +774,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
|
||||
|
||||
|
|
@ -1086,10 +1086,10 @@ void wallet2::process_new_blockchain_entry(const currency::block& b, const curre
|
|||
process_new_transaction(tx_entry->tx, height, b);
|
||||
}
|
||||
TIME_MEASURE_FINISH(txs_handle_time);
|
||||
WLT_LOG_L2("Processed block: " << bl_id << ", height " << height << ", " << miner_tx_handle_time + txs_handle_time << "(" << miner_tx_handle_time << "/" << txs_handle_time <<")ms");
|
||||
WLT_LOG_L3("Processed block: " << bl_id << ", height " << height << ", " << miner_tx_handle_time + txs_handle_time << "(" << miner_tx_handle_time << "/" << txs_handle_time <<")ms");
|
||||
}else
|
||||
{
|
||||
WLT_LOG_L2( "Skipped block by timestamp, height: " << height << ", block time " << b.timestamp << ", account time " << m_account.get_createtime());
|
||||
WLT_LOG_L3( "Skipped block by timestamp, height: " << height << ", block time " << b.timestamp << ", account time " << m_account.get_createtime());
|
||||
}
|
||||
m_blockchain.push_back(bl_id);
|
||||
++m_local_bc_height;
|
||||
|
|
@ -1236,6 +1236,11 @@ void wallet2::handle_pulled_blocks(size_t& blocks_added, std::atomic<bool>& stop
|
|||
WLT_LOG_L1("[PULL BLOCKS] " << res.start_height << " --> " << m_blockchain.size());
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
uint64_t wallet2::get_sync_progress()
|
||||
{
|
||||
return m_last_sync_percent;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::refresh()
|
||||
{
|
||||
size_t blocks_fetched = 0;
|
||||
|
|
@ -2329,7 +2334,7 @@ bool wallet2::generate_packing_transaction_if_needed(currency::transaction& tx,
|
|||
|
||||
//let's check if we have at least WALLET_POS_MINT_PACKING_SIZE transactions which is ready to go
|
||||
size_t count = 0;
|
||||
for (auto it_ind = it->second.begin(); it_ind != it->second.end() && count < m_pos_mint_packing_size; it_ind++)
|
||||
for (auto it_ind = it->second.begin(); it_ind != it->second.end() && count <= m_pos_mint_packing_size; it_ind++)
|
||||
{
|
||||
if (is_transfer_ready_to_go(m_transfers[*it_ind], fake_outputs_number))
|
||||
++count;
|
||||
|
|
@ -2584,6 +2589,11 @@ uint64_t wallet2::get_recent_transfers_total_count()
|
|||
return m_transfer_history.size();
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
uint64_t wallet2::get_transfer_entries_count()
|
||||
{
|
||||
return m_transfers.size();
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::get_recent_transfers_history(std::vector<wallet_public::wallet_transfer_info>& trs, size_t offset, size_t count, uint64_t& total)
|
||||
{
|
||||
if (offset >= m_transfer_history.size())
|
||||
|
|
@ -2838,7 +2848,7 @@ bool wallet2::build_minted_block(const currency::COMMAND_RPC_SCAN_POS::request&
|
|||
if (generate_packing_transaction_if_needed(pack_tx, 0))
|
||||
{
|
||||
tx_to_blob(pack_tx, tmpl_req.explicit_transaction);
|
||||
WLT_LOG_GREEN("Pacling inputs: " << pack_tx.vin.size() << " inputs consolidated", LOG_LEVEL_0);
|
||||
WLT_LOG_GREEN("Packing inputs: " << pack_tx.vin.size() << " inputs consolidated in tx " << get_transaction_hash(pack_tx), LOG_LEVEL_0);
|
||||
}
|
||||
m_core_proxy->call_COMMAND_RPC_GETBLOCKTEMPLATE(tmpl_req, tmpl_rsp);
|
||||
WLT_CHECK_AND_ASSERT_MES(tmpl_rsp.status == CORE_RPC_STATUS_OK, false, "Failed to create block template after kernel hash found!");
|
||||
|
|
@ -2899,10 +2909,10 @@ bool wallet2::build_minted_block(const currency::COMMAND_RPC_SCAN_POS::request&
|
|||
m_wcallback->on_pos_block_found(b);
|
||||
//@#@
|
||||
//double check timestamp
|
||||
if (time(NULL) - get_actual_timestamp(b) > 5)
|
||||
if (time(NULL) - static_cast<int64_t>(get_actual_timestamp(b)) > 5)
|
||||
{
|
||||
WLT_LOG_RED("Found block (" << get_block_hash(b) << ") timestamp (" << get_actual_timestamp(b)
|
||||
<< ") is suspiciously less (" << time(NULL) - get_actual_timestamp(b) << ") then curren time( " << time(NULL) << ")", LOG_LEVEL_0);
|
||||
<< ") is suspiciously less (" << time(NULL) - static_cast<int64_t>(get_actual_timestamp(b)) << ") than current time ( " << time(NULL) << ")", LOG_LEVEL_0);
|
||||
}
|
||||
//
|
||||
return true;
|
||||
|
|
@ -4348,11 +4358,38 @@ bool wallet2::store_unsigned_tx_to_file_and_reserve_transfers(const finalize_tx_
|
|||
return true;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::check_and_throw_if_self_directed_tx_with_payment_id_requested(const construct_tx_param& ctp)
|
||||
{
|
||||
// If someone sends coins to his own address, all tx outputs will be detected as own outputs.
|
||||
// It's totally okay unless payment id is used, because it would be impossible to distinguish
|
||||
// between change outs and transfer outs. Thus, such tx with a payment id can't be correctly
|
||||
// obtained via RPC by the given payment id. It could be a problem for an exchange or other
|
||||
// service when a user, identifyied by payment id sends coins to another user on the same
|
||||
// exchange/service. Coins will be received but RPCs like get_payments won't give the transfer.
|
||||
// To avoid such issues we prohibit such txs with a soft rule on sender side.
|
||||
|
||||
for (auto& d : ctp.dsts)
|
||||
{
|
||||
for (auto& addr : d.addr)
|
||||
{
|
||||
if (addr != m_account.get_public_address())
|
||||
return; // at least one destination address is not our address -- it's not self-directed tx
|
||||
}
|
||||
}
|
||||
|
||||
// it's self-directed tx
|
||||
payment_id_t pid;
|
||||
bool has_payment_id = get_payment_id_from_tx(ctp.attachments, pid) && !pid.empty();
|
||||
WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(!has_payment_id, "sending funds to yourself with payment id is not allowed");
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::transfer(const construct_tx_param& ctp,
|
||||
currency::transaction &tx,
|
||||
bool send_to_network,
|
||||
std::string* p_signed_tx_blob_str)
|
||||
{
|
||||
check_and_throw_if_self_directed_tx_with_payment_id_requested(ctp);
|
||||
|
||||
TIME_MEASURE_START(prepare_transaction_time);
|
||||
finalize_tx_param ftp = AUTO_VAL_INIT(ftp);
|
||||
prepare_transaction(ctp, ftp);
|
||||
|
|
@ -4545,7 +4582,7 @@ void wallet2::sweep_below(size_t fake_outs_count, const currency::account_public
|
|||
{
|
||||
finalize_transaction(ftp, tx, tx_key, false, false);
|
||||
}
|
||||
catch (error::tx_too_big)
|
||||
catch (error::tx_too_big&)
|
||||
{
|
||||
return rc_too_many_outputs;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -452,9 +451,9 @@ namespace tools
|
|||
END_SERIALIZE()
|
||||
};
|
||||
void assign_account(const currency::account_base& acc);
|
||||
void generate(const std::wstring& wallet, const std::string& password);
|
||||
void generate(const std::wstring& path, const std::string& password);
|
||||
void restore(const std::wstring& path, const std::string& pass, const std::string& restore_key);
|
||||
void load(const std::wstring& wallet, const std::string& password);
|
||||
void load(const std::wstring& path, const std::string& password);
|
||||
void store();
|
||||
void store(const std::wstring& path);
|
||||
void store(const std::wstring& path, const std::string& password);
|
||||
|
|
@ -466,6 +465,7 @@ namespace tools
|
|||
|
||||
void get_recent_transfers_history(std::vector<wallet_public::wallet_transfer_info>& trs, size_t offset, size_t count, uint64_t& total);
|
||||
uint64_t get_recent_transfers_total_count();
|
||||
uint64_t get_transfer_entries_count();
|
||||
void get_unconfirmed_transfers(std::vector<wallet_public::wallet_transfer_info>& trs);
|
||||
void init(const std::string& daemon_address = "http://localhost:8080");
|
||||
bool deinit();
|
||||
|
|
@ -744,7 +744,7 @@ namespace tools
|
|||
std::string get_log_prefix() const { return m_log_prefix; }
|
||||
static uint64_t get_max_unlock_time_from_receive_indices(const currency::transaction& tx, const money_transfer2_details& td);
|
||||
bool get_utxo_distribution(std::map<uint64_t, uint64_t>& distribution);
|
||||
|
||||
uint64_t get_sync_progress();
|
||||
private:
|
||||
void add_transfers_to_expiration_list(const std::vector<uint64_t>& selected_transfers, uint64_t expiration, uint64_t change_amount, const crypto::hash& related_tx_id);
|
||||
void remove_transfer_from_expiration_list(uint64_t transfer_index);
|
||||
|
|
@ -863,7 +863,7 @@ private:
|
|||
void check_for_free_space_and_throw_if_it_lacks(const std::wstring& path, uint64_t exact_size_needed_if_known = UINT64_MAX);
|
||||
bool generate_packing_transaction_if_needed(currency::transaction& tx, uint64_t fake_outputs_number);
|
||||
bool store_unsigned_tx_to_file_and_reserve_transfers(const finalize_tx_param& ftp, const std::string& filename, std::string* p_unsigned_tx_blob_str = nullptr);
|
||||
|
||||
void check_and_throw_if_self_directed_tx_with_payment_id_requested(const construct_tx_param& ctp);
|
||||
|
||||
currency::account_base m_account;
|
||||
bool m_watch_only;
|
||||
|
|
@ -895,7 +895,7 @@ private:
|
|||
std::shared_ptr<i_core_proxy> m_core_proxy;
|
||||
std::shared_ptr<i_wallet2_callback> m_wcallback;
|
||||
uint64_t m_height_of_start_sync;
|
||||
uint64_t m_last_sync_percent;
|
||||
std::atomic<uint64_t> m_last_sync_percent;
|
||||
uint64_t m_last_pow_block_h;
|
||||
currency::core_runtime_config m_core_runtime_config;
|
||||
escrow_contracts_container m_contracts;
|
||||
|
|
|
|||
24
src/wallet/wallet_helpers.h
Normal file
24
src/wallet/wallet_helpers.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (c) 2014-2020 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 "wallet2.h"
|
||||
#include "view_iface.h"
|
||||
|
||||
|
||||
namespace tools
|
||||
{
|
||||
inline bool get_wallet_info(wallet2& w, view::wallet_info& wi)
|
||||
{
|
||||
wi = AUTO_VAL_INIT_T(view::wallet_info);
|
||||
wi.address = w.get_account().get_public_address_str();
|
||||
wi.tracking_hey = epee::string_tools::pod_to_hex(w.get_account().get_keys().m_view_secret_key);
|
||||
uint64_t fake = 0;
|
||||
wi.balance = w.balance(wi.unlocked_balance, fake, fake, wi.mined_total);
|
||||
wi.path = epee::string_encoding::wstring_to_utf8(w.get_wallet_path());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@
|
|||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include "currency_protocol/currency_protocol_defs.h"
|
||||
#include "currency_core/currency_basic.h"
|
||||
#include "crypto/hash.h"
|
||||
|
|
@ -206,6 +207,99 @@ namespace wallet_public
|
|||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct COMMAND_RPC_GET_WALLET_INFO
|
||||
{
|
||||
struct request
|
||||
{
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct response
|
||||
{
|
||||
std::string address;
|
||||
std::string path;
|
||||
std::string seed;
|
||||
uint64_t transfers_count;
|
||||
uint64_t transfer_entries_count;
|
||||
bool is_whatch_only;
|
||||
std::vector<std::string> utxo_distribution;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(address)
|
||||
KV_SERIALIZE(path)
|
||||
KV_SERIALIZE(seed)
|
||||
KV_SERIALIZE(transfers_count)
|
||||
KV_SERIALIZE(transfer_entries_count)
|
||||
KV_SERIALIZE(is_whatch_only)
|
||||
KV_SERIALIZE(utxo_distribution)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct wallet_provision_info
|
||||
{
|
||||
uint64_t transfers_count;
|
||||
uint64_t transfer_entries_count;
|
||||
uint64_t balance;
|
||||
uint64_t unlocked_balance;
|
||||
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(transfers_count)
|
||||
KV_SERIALIZE(transfer_entries_count)
|
||||
KV_SERIALIZE(balance)
|
||||
KV_SERIALIZE(unlocked_balance)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct COMMAND_RPC_GET_RECENT_TXS_AND_INFO
|
||||
{
|
||||
struct request
|
||||
{
|
||||
|
||||
/*
|
||||
if offset is 0, then GET_RECENT_TXS_AND_INFO return
|
||||
unconfirmed transactions as the first first items of "transfers",
|
||||
this unconfirmed transactions is not counted regarding "count" parameter
|
||||
*/
|
||||
uint64_t offset;
|
||||
uint64_t count;
|
||||
|
||||
/*
|
||||
need_to_get_info - should backend re-calculate balance(could be relatively heavy,
|
||||
and not needed when getting long tx history with multiple calls
|
||||
of GET_RECENT_TXS_AND_INFO with offsets)
|
||||
*/
|
||||
bool update_provision_info;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(offset)
|
||||
KV_SERIALIZE(count)
|
||||
KV_SERIALIZE(update_provision_info)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct response
|
||||
{
|
||||
wallet_provision_info pi;
|
||||
std::vector<wallet_transfer_info> transfers;
|
||||
uint64_t total_transfers;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(pi)
|
||||
KV_SERIALIZE(transfers)
|
||||
KV_SERIALIZE(total_transfers)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
struct trnsfer_destination
|
||||
{
|
||||
uint64_t amount;
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ namespace tools
|
|||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool wallet_rpc_server::run(bool do_mint, bool offline_mode, const currency::account_public_address& miner_address)
|
||||
{
|
||||
static const uint64_t wallet_rpt_idle_work_period_ms = 2000;
|
||||
static const uint64_t wallet_rpc_idle_work_period_ms = 2000;
|
||||
|
||||
m_do_mint = do_mint;
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ namespace tools
|
|||
}
|
||||
|
||||
return true;
|
||||
}, wallet_rpt_idle_work_period_ms);
|
||||
}, wallet_rpc_idle_work_period_ms);
|
||||
}
|
||||
|
||||
//DO NOT START THIS SERVER IN MORE THEN 1 THREADS WITHOUT REFACTORING
|
||||
|
|
@ -186,6 +186,55 @@ namespace tools
|
|||
}
|
||||
return true;
|
||||
}
|
||||
bool wallet_rpc_server::on_getwallet_info(const wallet_public::COMMAND_RPC_GET_WALLET_INFO::request& req, wallet_public::COMMAND_RPC_GET_WALLET_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx)
|
||||
{
|
||||
try
|
||||
{
|
||||
res.address = m_wallet.get_account().get_public_address_str();
|
||||
res.is_whatch_only = m_wallet.is_watch_only();
|
||||
res.path = epee::string_encoding::convert_to_ansii(m_wallet.get_wallet_path());
|
||||
res.transfers_count = m_wallet.get_recent_transfers_total_count();
|
||||
res.transfer_entries_count = m_wallet.get_transfer_entries_count();
|
||||
res.seed = m_wallet.get_account().get_restore_braindata();
|
||||
std::map<uint64_t, uint64_t> distribution;
|
||||
m_wallet.get_utxo_distribution(distribution);
|
||||
for (const auto& ent : distribution)
|
||||
res.utxo_distribution.push_back(currency::print_money_brief(ent.first) + ":" + std::to_string(ent.second));
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
|
||||
er.message = e.what();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool wallet_rpc_server::on_get_recent_txs_and_info(const wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::request& req, wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (req.update_provision_info)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
if (req.offset == 0)
|
||||
m_wallet.get_unconfirmed_transfers(res.transfers);
|
||||
|
||||
m_wallet.get_recent_transfers_history(res.transfers, req.offset, req.count, res.total_transfers);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
|
||||
er.message = e.what();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool wallet_rpc_server::on_transfer(const wallet_public::COMMAND_RPC_TRANSFER::request& req, wallet_public::COMMAND_RPC_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -33,14 +33,14 @@ namespace tools
|
|||
static void init_options(boost::program_options::options_description& desc);
|
||||
bool init(const boost::program_options::variables_map& vm);
|
||||
bool run(bool do_mint, bool offline_mode, const currency::account_public_address& miner_address);
|
||||
|
||||
|
||||
bool handle_http_request(const epee::net_utils::http::http_request_info& query_info, epee::net_utils::http::http_response_info& response, connection_context& m_conn_context);
|
||||
|
||||
BEGIN_URI_MAP2()
|
||||
BEGIN_JSON_RPC_MAP("/json_rpc")
|
||||
MAP_JON_RPC_WE("getbalance", on_getbalance, wallet_public::COMMAND_RPC_GET_BALANCE)
|
||||
MAP_JON_RPC_WE("getaddress", on_getaddress, wallet_public::COMMAND_RPC_GET_ADDRESS)
|
||||
MAP_JON_RPC_WE("get_wallet_info", on_getwallet_info, wallet_public::COMMAND_RPC_GET_WALLET_INFO)
|
||||
MAP_JON_RPC_WE("get_recent_txs_and_info", on_get_recent_txs_and_info, wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO)
|
||||
MAP_JON_RPC_WE("transfer", on_transfer, wallet_public::COMMAND_RPC_TRANSFER)
|
||||
MAP_JON_RPC_WE("store", on_store, wallet_public::COMMAND_RPC_STORE)
|
||||
MAP_JON_RPC_WE("get_payments", on_get_payments, wallet_public::COMMAND_RPC_GET_PAYMENTS)
|
||||
|
|
@ -50,7 +50,7 @@ namespace tools
|
|||
MAP_JON_RPC_WE("sweep_below", on_sweep_below, wallet_public::COMMAND_SWEEP_BELOW)
|
||||
MAP_JON_RPC_WE("sign_transfer", on_sign_transfer, wallet_public::COMMAND_SIGN_TRANSFER)
|
||||
MAP_JON_RPC_WE("submit_transfer", on_submit_transfer, wallet_public::COMMAND_SUBMIT_TRANSFER)
|
||||
//contracts API
|
||||
//contracts API Skipped block by timestamp, height: 94766, block time 1563035089
|
||||
MAP_JON_RPC_WE("contracts_send_proposal", on_contracts_send_proposal, wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL)
|
||||
MAP_JON_RPC_WE("contracts_accept_proposal", on_contracts_accept_proposal, wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL)
|
||||
MAP_JON_RPC_WE("contracts_get_all", on_contracts_get_all, wallet_public::COMMAND_CONTRACTS_GET_ALL)
|
||||
|
|
@ -68,6 +68,8 @@ namespace tools
|
|||
//json_rpc
|
||||
bool on_getbalance(const wallet_public::COMMAND_RPC_GET_BALANCE::request& req, wallet_public::COMMAND_RPC_GET_BALANCE::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
bool on_getaddress(const wallet_public::COMMAND_RPC_GET_ADDRESS::request& req, wallet_public::COMMAND_RPC_GET_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
bool on_getwallet_info(const wallet_public::COMMAND_RPC_GET_WALLET_INFO::request& req, wallet_public::COMMAND_RPC_GET_WALLET_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
bool on_get_recent_txs_and_info(const wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::request& req, wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
bool on_transfer(const wallet_public::COMMAND_RPC_TRANSFER::request& req, wallet_public::COMMAND_RPC_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
bool on_store(const wallet_public::COMMAND_RPC_STORE::request& req, wallet_public::COMMAND_RPC_STORE::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
bool on_get_payments(const wallet_public::COMMAND_RPC_GET_PAYMENTS::request& req, wallet_public::COMMAND_RPC_GET_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
|
|
|
|||
|
|
@ -4,12 +4,16 @@
|
|||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "daemon_backend.h"
|
||||
#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 "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); \
|
||||
|
|
@ -25,25 +29,32 @@ if (it == m_wallets.end()) \
|
|||
return API_RETURN_CODE_WALLET_WRONG_ID; \
|
||||
auto& name = it->second.w;
|
||||
|
||||
#define DAEMON_IDLE_UPDATE_TIME_MS 1000
|
||||
|
||||
|
||||
daemon_backend::daemon_backend():m_pview(&m_view_stub),
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -63,9 +74,11 @@ void wallet_lock_time_watching_policy::watch_lock_time(uint64_t lock_time)
|
|||
}
|
||||
}
|
||||
|
||||
daemon_backend::~daemon_backend()
|
||||
wallets_manager::~wallets_manager()
|
||||
{
|
||||
TRY_ENTRY();
|
||||
stop();
|
||||
CATCH_ENTRY_NO_RETURN();
|
||||
}
|
||||
|
||||
void terminate_handler_func()
|
||||
|
|
@ -75,7 +88,7 @@ void terminate_handler_func()
|
|||
std::abort(); // default terminate handler's behavior
|
||||
}
|
||||
|
||||
bool daemon_backend::init(int argc, char* argv[], view::i_view* pview_handler)
|
||||
bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler)
|
||||
{
|
||||
m_stop_singal_sent = false;
|
||||
if (pview_handler)
|
||||
|
|
@ -83,7 +96,7 @@ bool daemon_backend::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 = "---";
|
||||
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);
|
||||
|
|
@ -96,10 +109,10 @@ bool daemon_backend::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
|
||||
|
|
@ -128,12 +141,13 @@ bool daemon_backend::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<currency::t_currency_protocol_handler<currency::core> >::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);
|
||||
|
|
@ -217,7 +231,11 @@ bool daemon_backend::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;
|
||||
auto proxy_ptr = new tools::default_http_core_proxy();
|
||||
proxy_ptr->set_plast_daemon_is_disconnected(&m_last_daemon_is_disconnected);
|
||||
m_rpc_proxy.reset(proxy_ptr);
|
||||
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);
|
||||
|
|
@ -236,7 +254,7 @@ bool daemon_backend::init(int argc, char* argv[], view::i_view* pview_handler)
|
|||
CATCH_ENTRY_L0("init", false);
|
||||
}
|
||||
|
||||
bool daemon_backend::start()
|
||||
bool wallets_manager::start()
|
||||
{
|
||||
TRY_ENTRY();
|
||||
|
||||
|
|
@ -248,14 +266,14 @@ bool daemon_backend::start()
|
|||
|
||||
|
||||
|
||||
bool daemon_backend::send_stop_signal()
|
||||
bool wallets_manager::send_stop_signal()
|
||||
{
|
||||
m_stop_singal_sent = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool daemon_backend::stop()
|
||||
bool wallets_manager::stop()
|
||||
{
|
||||
send_stop_signal();
|
||||
if (m_main_worker_thread.joinable())
|
||||
|
|
@ -269,7 +287,7 @@ bool daemon_backend::stop()
|
|||
return true;
|
||||
}
|
||||
|
||||
std::string daemon_backend::get_config_folder()
|
||||
std::string wallets_manager::get_config_folder()
|
||||
{
|
||||
return m_data_dir;
|
||||
}
|
||||
|
|
@ -283,8 +301,9 @@ std::string daemon_backend::get_config_folder()
|
|||
return false; \
|
||||
}
|
||||
|
||||
bool daemon_backend::init_local_daemon()
|
||||
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;
|
||||
|
|
@ -353,12 +372,13 @@ bool daemon_backend::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 daemon_backend::deinit_local_daemon()
|
||||
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);
|
||||
|
|
@ -414,11 +434,11 @@ bool daemon_backend::deinit_local_daemon()
|
|||
//dsi.text_state = "Deinitializing core";
|
||||
m_pview->update_daemon_status(dsi);
|
||||
m_ccore.deinit();
|
||||
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void daemon_backend::main_worker(const po::variables_map& m_vm)
|
||||
void wallets_manager::main_worker(const po::variables_map& m_vm)
|
||||
{
|
||||
log_space::log_singletone::set_thread_log_prefix("[BACKEND_M]");
|
||||
TRY_ENTRY();
|
||||
|
|
@ -473,7 +493,7 @@ void daemon_backend::main_worker(const po::variables_map& m_vm)
|
|||
CATCH_ENTRY_L0("daemon_backend::main_worker", void());
|
||||
}
|
||||
|
||||
bool daemon_backend::update_state_info()
|
||||
bool wallets_manager::update_state_info()
|
||||
{
|
||||
view::daemon_status_info dsi = AUTO_VAL_INIT(dsi);
|
||||
currency::COMMAND_RPC_GET_INFO::request req = AUTO_VAL_INIT(req);
|
||||
|
|
@ -530,7 +550,7 @@ bool daemon_backend::update_state_info()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool daemon_backend::get_last_blocks(view::daemon_status_info& dsi)
|
||||
bool wallets_manager::get_last_blocks(view::daemon_status_info& dsi)
|
||||
{
|
||||
|
||||
return true;
|
||||
|
|
@ -538,22 +558,22 @@ bool daemon_backend::get_last_blocks(view::daemon_status_info& dsi)
|
|||
|
||||
|
||||
|
||||
void daemon_backend::toggle_pos_mining()
|
||||
void wallets_manager::toggle_pos_mining()
|
||||
{
|
||||
//m_do_mint = !m_do_mint;
|
||||
//update_wallets_info();
|
||||
}
|
||||
|
||||
void daemon_backend::loop()
|
||||
void wallets_manager::loop()
|
||||
{
|
||||
while(!m_stop_singal_sent)
|
||||
{
|
||||
update_state_info();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(DAEMON_IDLE_UPDATE_TIME_MS));
|
||||
}
|
||||
}
|
||||
|
||||
void daemon_backend::init_wallet_entry(wallet_vs_options& wo, uint64_t id)
|
||||
void wallets_manager::init_wallet_entry(wallet_vs_options& wo, uint64_t id)
|
||||
{
|
||||
wo.wallet_id = id;
|
||||
wo.do_mining = false;
|
||||
|
|
@ -564,10 +584,18 @@ void daemon_backend::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
|
||||
{
|
||||
|
|
@ -579,7 +607,7 @@ void daemon_backend::init_wallet_entry(wallet_vs_options& wo, uint64_t id)
|
|||
}
|
||||
|
||||
|
||||
std::string daemon_backend::get_tx_pool_info(currency::COMMAND_RPC_GET_POOL_INFO::response& res)
|
||||
std::string wallets_manager::get_tx_pool_info(currency::COMMAND_RPC_GET_POOL_INFO::response& res)
|
||||
{
|
||||
currency::COMMAND_RPC_GET_POOL_INFO::request req = AUTO_VAL_INIT(req);
|
||||
res = AUTO_VAL_INIT_T(currency::COMMAND_RPC_GET_POOL_INFO::response);
|
||||
|
|
@ -591,27 +619,30 @@ std::string daemon_backend::get_tx_pool_info(currency::COMMAND_RPC_GET_POOL_INFO
|
|||
}
|
||||
|
||||
|
||||
uint64_t daemon_backend::get_default_fee()
|
||||
uint64_t wallets_manager::get_default_fee()
|
||||
{
|
||||
return TX_DEFAULT_FEE;
|
||||
}
|
||||
std::string daemon_backend::get_fav_offers(const std::list<bc_services::offer_id>& hashes, const bc_services::core_offers_filter& filter, std::list<bc_services::offer_details_ex>& offers)
|
||||
std::string wallets_manager::get_fav_offers(const std::list<bc_services::offer_id>& hashes, const bc_services::core_offers_filter& filter, std::list<bc_services::offer_details_ex>& offers)
|
||||
{
|
||||
if (m_remote_node_mode)
|
||||
return API_RETURN_CODE_FAIL;
|
||||
|
||||
#ifndef MOBILE_WALLET_BUILD
|
||||
currency::blockchain_storage& bcs = m_ccore.get_blockchain_storage();
|
||||
|
||||
m_offers_service.get_offers_by_id(hashes, offers);
|
||||
filter_offers_list(offers, filter, bcs.get_core_runtime_config().get_core_time());
|
||||
return API_RETURN_CODE_OK;
|
||||
#else
|
||||
return API_RETURN_CODE_FAIL;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string daemon_backend::get_my_offers(const bc_services::core_offers_filter& filter, std::list<bc_services::offer_details_ex>& offers)
|
||||
std::string wallets_manager::get_my_offers(const bc_services::core_offers_filter& filter, std::list<bc_services::offer_details_ex>& offers)
|
||||
{
|
||||
if (m_remote_node_mode)
|
||||
return API_RETURN_CODE_FAIL;
|
||||
|
||||
#ifndef MOBILE_WALLET_BUILD
|
||||
CRITICAL_REGION_LOCAL(m_wallets_lock);
|
||||
while (true)
|
||||
{
|
||||
|
|
@ -653,9 +684,12 @@ std::string daemon_backend::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 daemon_backend::open_wallet(const std::wstring& path, const std::string& password, uint64_t txs_to_return, view::open_wallet_response& owr)
|
||||
std::string wallets_manager::open_wallet(const std::wstring& path, const std::string& password, uint64_t txs_to_return, view::open_wallet_response& owr)
|
||||
{
|
||||
std::shared_ptr<tools::wallet2> w(new tools::wallet2());
|
||||
owr.wallet_id = m_wallet_id_counter++;
|
||||
|
|
@ -667,7 +701,11 @@ std::string daemon_backend::open_wallet(const std::wstring& path, const std::str
|
|||
}
|
||||
else
|
||||
{
|
||||
#ifndef MOBILE_WALLET_BUILD
|
||||
w->set_core_proxy(std::shared_ptr<tools::i_core_proxy>(new tools::core_fast_rpc_proxy(m_rpc_server)));
|
||||
#else
|
||||
LOG_ERROR("Unexpected location reached");
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string return_code = API_RETURN_CODE_OK;
|
||||
|
|
@ -683,6 +721,7 @@ std::string daemon_backend::open_wallet(const std::wstring& path, const std::str
|
|||
//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& /**/)
|
||||
|
|
@ -708,7 +747,7 @@ std::string daemon_backend::open_wallet(const std::wstring& path, const std::str
|
|||
return return_code;
|
||||
}
|
||||
|
||||
std::string daemon_backend::get_recent_transfers(size_t wallet_id, uint64_t offset, uint64_t count, view::transfers_array& tr_hist)
|
||||
std::string wallets_manager::get_recent_transfers(size_t wallet_id, uint64_t offset, uint64_t count, view::transfers_array& tr_hist)
|
||||
{
|
||||
GET_WALLET_BY_ID(wallet_id, w);
|
||||
auto wallet_locked = w.try_lock();
|
||||
|
|
@ -731,7 +770,7 @@ std::string daemon_backend::get_recent_transfers(size_t wallet_id, uint64_t offs
|
|||
return API_RETURN_CODE_OK;
|
||||
}
|
||||
|
||||
std::string daemon_backend::generate_wallet(const std::wstring& path, const std::string& password, view::open_wallet_response& owr)
|
||||
std::string wallets_manager::generate_wallet(const std::wstring& path, const std::string& password, view::open_wallet_response& owr)
|
||||
{
|
||||
std::shared_ptr<tools::wallet2> w(new tools::wallet2());
|
||||
owr.wallet_id = m_wallet_id_counter++;
|
||||
|
|
@ -742,7 +781,12 @@ std::string daemon_backend::generate_wallet(const std::wstring& path, const std:
|
|||
}
|
||||
else
|
||||
{
|
||||
#ifndef MOBILE_WALLET_BUILD
|
||||
w->set_core_proxy(std::shared_ptr<tools::i_core_proxy>(new tools::core_fast_rpc_proxy(m_rpc_server)));
|
||||
#else
|
||||
LOG_ERROR("Unexpected location reached");
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -751,8 +795,9 @@ std::string daemon_backend::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/*& e*/)
|
||||
catch (const tools::error::file_exists&)
|
||||
{
|
||||
return API_RETURN_CODE_ALREADY_EXISTS;
|
||||
}
|
||||
|
|
@ -768,7 +813,7 @@ std::string daemon_backend::generate_wallet(const std::wstring& path, const std:
|
|||
return API_RETURN_CODE_OK;
|
||||
}
|
||||
|
||||
std::string daemon_backend::get_mining_estimate(uint64_t amuont_coins,
|
||||
std::string wallets_manager::get_mining_estimate(uint64_t amuont_coins,
|
||||
uint64_t time,
|
||||
uint64_t& estimate_result,
|
||||
uint64_t& pos_coins_and_pos_diff_rate,
|
||||
|
|
@ -776,19 +821,22 @@ std::string daemon_backend::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 daemon_backend::is_pos_allowed()
|
||||
std::string wallets_manager::is_pos_allowed()
|
||||
{
|
||||
if (m_is_pos_allowed)
|
||||
return API_RETURN_CODE_TRUE;
|
||||
else
|
||||
return API_RETURN_CODE_FALSE;
|
||||
}
|
||||
std::string daemon_backend::is_valid_brain_restore_data(const std::string& brain_text)
|
||||
std::string wallets_manager::is_valid_brain_restore_data(const std::string& brain_text)
|
||||
{
|
||||
currency::account_base acc;
|
||||
if (acc.restore_keys_from_braindata(brain_text))
|
||||
|
|
@ -796,16 +844,20 @@ std::string daemon_backend::is_valid_brain_restore_data(const std::string& brain
|
|||
else
|
||||
return API_RETURN_CODE_FALSE;
|
||||
}
|
||||
void daemon_backend::subscribe_to_core_events(currency::i_core_event_handler* pevents_handler)
|
||||
#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);
|
||||
|
||||
}
|
||||
void daemon_backend::get_gui_options(view::gui_options& opt)
|
||||
#endif
|
||||
void wallets_manager::get_gui_options(view::gui_options& opt)
|
||||
{
|
||||
opt = m_ui_opt;
|
||||
}
|
||||
std::string daemon_backend::restore_wallet(const std::wstring& path, const std::string& password, const std::string& restore_key, view::open_wallet_response& owr)
|
||||
std::string wallets_manager::restore_wallet(const std::wstring& path, const std::string& password, const std::string& restore_key, view::open_wallet_response& owr)
|
||||
{
|
||||
std::shared_ptr<tools::wallet2> w(new tools::wallet2());
|
||||
owr.wallet_id = m_wallet_id_counter++;
|
||||
|
|
@ -816,7 +868,12 @@ std::string daemon_backend::restore_wallet(const std::wstring& path, const std::
|
|||
}
|
||||
else
|
||||
{
|
||||
#ifndef MOBILE_WALLET_BUILD
|
||||
w->set_core_proxy(std::shared_ptr<tools::i_core_proxy>(new tools::core_fast_rpc_proxy(m_rpc_server)));
|
||||
#else
|
||||
LOG_ERROR("Unexpected location reached");
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
currency::account_base acc;
|
||||
|
|
@ -826,8 +883,9 @@ std::string daemon_backend::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/*& e*/)
|
||||
catch (const tools::error::file_exists&)
|
||||
{
|
||||
return API_RETURN_CODE_ALREADY_EXISTS;
|
||||
}
|
||||
|
|
@ -842,7 +900,7 @@ std::string daemon_backend::restore_wallet(const std::wstring& path, const std::
|
|||
get_wallet_info(wo, owr.wi);
|
||||
return API_RETURN_CODE_OK;
|
||||
}
|
||||
std::string daemon_backend::close_wallet(size_t wallet_id)
|
||||
std::string wallets_manager::close_wallet(size_t wallet_id)
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_wallets_lock);
|
||||
|
||||
|
|
@ -874,11 +932,12 @@ std::string daemon_backend::close_wallet(size_t wallet_id)
|
|||
return API_RETURN_CODE_OK;
|
||||
}
|
||||
|
||||
std::string daemon_backend::get_aliases(view::alias_set& al_set)
|
||||
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;
|
||||
|
||||
|
|
@ -889,10 +948,11 @@ std::string daemon_backend::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 daemon_backend::get_alias_info_by_address(const std::string& addr, currency::alias_rpc_details& res_details)
|
||||
std::string wallets_manager::get_alias_info_by_address(const std::string& addr, currency::alias_rpc_details& res_details)
|
||||
{
|
||||
if (addr.empty())
|
||||
return API_RETURN_CODE_NOT_FOUND;
|
||||
|
|
@ -911,7 +971,7 @@ std::string daemon_backend::get_alias_info_by_address(const std::string& addr, c
|
|||
return res.status;
|
||||
}
|
||||
|
||||
std::string daemon_backend::get_alias_info_by_name(const std::string& name, currency::alias_rpc_details& res_details)
|
||||
std::string wallets_manager::get_alias_info_by_name(const std::string& name, currency::alias_rpc_details& res_details)
|
||||
{
|
||||
if(name.empty())
|
||||
return API_RETURN_CODE_FILE_NOT_FOUND;
|
||||
|
|
@ -931,7 +991,7 @@ std::string daemon_backend::get_alias_info_by_name(const std::string& name, curr
|
|||
return res.status;
|
||||
}
|
||||
|
||||
std::string daemon_backend::get_alias_coast(const std::string& a, uint64_t& coast)
|
||||
std::string wallets_manager::get_alias_coast(const std::string& a, uint64_t& coast)
|
||||
{
|
||||
currency::COMMAND_RPC_GET_ALIAS_REWARD::request req = AUTO_VAL_INIT(req);
|
||||
currency::COMMAND_RPC_GET_ALIAS_REWARD::response rsp = AUTO_VAL_INIT(rsp);
|
||||
|
|
@ -943,7 +1003,7 @@ std::string daemon_backend::get_alias_coast(const std::string& a, uint64_t& coas
|
|||
return rsp.status;
|
||||
|
||||
}
|
||||
std::string daemon_backend::request_alias_registration(const currency::alias_rpc_details& al, uint64_t wallet_id, uint64_t fee, currency::transaction& res_tx, uint64_t reward)
|
||||
std::string wallets_manager::request_alias_registration(const currency::alias_rpc_details& al, uint64_t wallet_id, uint64_t fee, currency::transaction& res_tx, uint64_t reward)
|
||||
{
|
||||
currency::extra_alias_entry ai = AUTO_VAL_INIT(ai);
|
||||
if (!currency::alias_rpc_details_to_alias_info(al, ai))
|
||||
|
|
@ -982,7 +1042,7 @@ std::string daemon_backend::request_alias_registration(const currency::alias_rpc
|
|||
return API_RETURN_CODE_ALREADY_EXISTS;
|
||||
}
|
||||
|
||||
std::string daemon_backend::request_alias_update(const currency::alias_rpc_details& al, uint64_t wallet_id, uint64_t fee, currency::transaction& res_tx, uint64_t reward)
|
||||
std::string wallets_manager::request_alias_update(const currency::alias_rpc_details& al, uint64_t wallet_id, uint64_t fee, currency::transaction& res_tx, uint64_t reward)
|
||||
{
|
||||
currency::extra_alias_entry ai = AUTO_VAL_INIT(ai);
|
||||
if (!currency::alias_rpc_details_to_alias_info(al, ai))
|
||||
|
|
@ -1022,7 +1082,7 @@ std::string daemon_backend::request_alias_update(const currency::alias_rpc_detai
|
|||
}
|
||||
|
||||
|
||||
std::string daemon_backend::transfer(size_t wallet_id, const view::transfer_params& tp, currency::transaction& res_tx)
|
||||
std::string wallets_manager::transfer(size_t wallet_id, const view::transfer_params& tp, currency::transaction& res_tx)
|
||||
{
|
||||
|
||||
std::vector<currency::tx_destination_entry> dsts;
|
||||
|
|
@ -1127,12 +1187,62 @@ std::string daemon_backend::transfer(size_t wallet_id, const view::transfer_para
|
|||
return API_RETURN_CODE_OK;
|
||||
}
|
||||
|
||||
std::string daemon_backend::get_wallet_info(size_t wallet_id, view::wallet_info& wi)
|
||||
bool wallets_manager::get_is_remote_daemon_connected()
|
||||
{
|
||||
if (!m_remote_node_mode)
|
||||
return true;
|
||||
if (m_last_daemon_is_disconnected)
|
||||
return false;
|
||||
if (time(nullptr) - m_rpc_proxy->get_last_success_interract_time() > DAEMON_IDLE_UPDATE_TIME_MS * 2)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
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.is_daemon_connected = get_is_remote_daemon_connected();
|
||||
wsi.progress = wo.w.unlocked_get().get()->get_sync_progress();
|
||||
wsi.wallet_state = wo.wallet_state;
|
||||
wsi.current_daemon_height = m_last_daemon_height;
|
||||
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<epee::json_rpc::dummy_result, epee::json_rpc::error> 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);
|
||||
return get_wallet_info(w, wi);
|
||||
}
|
||||
std::string daemon_backend::get_contracts(size_t wallet_id, std::vector<tools::wallet_public::escrow_contract_details>& contracts)
|
||||
std::string wallets_manager::get_contracts(size_t wallet_id, std::vector<tools::wallet_public::escrow_contract_details>& contracts)
|
||||
{
|
||||
tools::wallet2::escrow_contracts_container cc;
|
||||
GET_WALLET_OPT_BY_ID(wallet_id, w);
|
||||
|
|
@ -1156,7 +1266,7 @@ std::string daemon_backend::get_contracts(size_t wallet_id, std::vector<tools::w
|
|||
|
||||
return API_RETURN_CODE_OK;
|
||||
}
|
||||
std::string daemon_backend::create_proposal(const view::create_proposal_param_gui& cpp)
|
||||
std::string wallets_manager::create_proposal(const view::create_proposal_param_gui& cpp)
|
||||
{
|
||||
//tools::wallet2::escrow_contracts_container cc;
|
||||
GET_WALLET_OPT_BY_ID(cpp.wallet_id, w);
|
||||
|
|
@ -1188,7 +1298,7 @@ std::string daemon_backend::create_proposal(const view::create_proposal_param_gu
|
|||
}
|
||||
}
|
||||
|
||||
std::string daemon_backend::accept_proposal(size_t wallet_id, const crypto::hash& contract_id)
|
||||
std::string wallets_manager::accept_proposal(size_t wallet_id, const crypto::hash& contract_id)
|
||||
{
|
||||
GET_WALLET_OPT_BY_ID(wallet_id, w);
|
||||
try
|
||||
|
|
@ -1202,7 +1312,7 @@ std::string daemon_backend::accept_proposal(size_t wallet_id, const crypto::hash
|
|||
return API_RETURN_CODE_FAIL;
|
||||
}
|
||||
}
|
||||
std::string daemon_backend::release_contract(size_t wallet_id, const crypto::hash& contract_id, const std::string& contract_over_type)
|
||||
std::string wallets_manager::release_contract(size_t wallet_id, const crypto::hash& contract_id, const std::string& contract_over_type)
|
||||
{
|
||||
GET_WALLET_OPT_BY_ID(wallet_id, w);
|
||||
try
|
||||
|
|
@ -1216,7 +1326,7 @@ std::string daemon_backend::release_contract(size_t wallet_id, const crypto::has
|
|||
return API_RETURN_CODE_FAIL;
|
||||
}
|
||||
}
|
||||
std::string daemon_backend::request_cancel_contract(size_t wallet_id, const crypto::hash& contract_id, uint64_t fee, uint64_t expiration_period)
|
||||
std::string wallets_manager::request_cancel_contract(size_t wallet_id, const crypto::hash& contract_id, uint64_t fee, uint64_t expiration_period)
|
||||
{
|
||||
GET_WALLET_OPT_BY_ID(wallet_id, w);
|
||||
try
|
||||
|
|
@ -1235,7 +1345,7 @@ std::string daemon_backend::request_cancel_contract(size_t wallet_id, const cryp
|
|||
return API_RETURN_CODE_FAIL;
|
||||
}
|
||||
}
|
||||
std::string daemon_backend::accept_cancel_contract(size_t wallet_id, const crypto::hash& contract_id)
|
||||
std::string wallets_manager::accept_cancel_contract(size_t wallet_id, const crypto::hash& contract_id)
|
||||
{
|
||||
GET_WALLET_OPT_BY_ID(wallet_id, w);
|
||||
try
|
||||
|
|
@ -1254,7 +1364,7 @@ std::string daemon_backend::accept_cancel_contract(size_t wallet_id, const crypt
|
|||
return API_RETURN_CODE_FAIL;
|
||||
}
|
||||
}
|
||||
std::string daemon_backend::backup_wallet(uint64_t wallet_id, const std::wstring& path)
|
||||
std::string wallets_manager::backup_wallet(uint64_t wallet_id, const std::wstring& path)
|
||||
{
|
||||
GET_WALLET_OPT_BY_ID(wallet_id, w);
|
||||
try
|
||||
|
|
@ -1267,7 +1377,7 @@ std::string daemon_backend::backup_wallet(uint64_t wallet_id, const std::wstring
|
|||
}
|
||||
return API_RETURN_CODE_OK;
|
||||
}
|
||||
std::string daemon_backend::reset_wallet_password(uint64_t wallet_id, const std::string& pass)
|
||||
std::string wallets_manager::reset_wallet_password(uint64_t wallet_id, const std::string& pass)
|
||||
{
|
||||
GET_WALLET_OPT_BY_ID(wallet_id, w);
|
||||
if (w.w->get()->reset_password(pass))
|
||||
|
|
@ -1275,7 +1385,7 @@ std::string daemon_backend::reset_wallet_password(uint64_t wallet_id, const std:
|
|||
else
|
||||
return API_RETURN_CODE_FAIL;
|
||||
}
|
||||
std::string daemon_backend::is_wallet_password_valid(uint64_t wallet_id, const std::string& pass)
|
||||
std::string wallets_manager::is_wallet_password_valid(uint64_t wallet_id, const std::string& pass)
|
||||
{
|
||||
GET_WALLET_OPT_BY_ID(wallet_id, w);
|
||||
if (w.w->get()->is_password_valid(pass))
|
||||
|
|
@ -1283,21 +1393,21 @@ std::string daemon_backend::is_wallet_password_valid(uint64_t wallet_id, const s
|
|||
else
|
||||
return API_RETURN_CODE_FAIL;
|
||||
}
|
||||
std::string daemon_backend::resync_wallet(uint64_t wallet_id)
|
||||
std::string wallets_manager::resync_wallet(uint64_t wallet_id)
|
||||
{
|
||||
GET_WALLET_OPT_BY_ID(wallet_id, w);
|
||||
w.w->get()->reset_history();
|
||||
w.last_wallet_synch_height = 0;
|
||||
return API_RETURN_CODE_OK;
|
||||
}
|
||||
std::string daemon_backend::start_pos_mining(uint64_t wallet_id)
|
||||
std::string wallets_manager::start_pos_mining(uint64_t wallet_id)
|
||||
{
|
||||
GET_WALLET_OPT_BY_ID(wallet_id, wo);
|
||||
wo.do_mining = true;
|
||||
wo.need_to_update_wallet_info = true;
|
||||
return API_RETURN_CODE_OK;
|
||||
}
|
||||
std::string daemon_backend::get_mining_history(uint64_t wallet_id, tools::wallet_public::mining_history& mh)
|
||||
std::string wallets_manager::get_mining_history(uint64_t wallet_id, tools::wallet_public::mining_history& mh)
|
||||
{
|
||||
GET_WALLET_OPT_BY_ID(wallet_id, wo);
|
||||
|
||||
|
|
@ -1307,21 +1417,21 @@ std::string daemon_backend::get_mining_history(uint64_t wallet_id, tools::wallet
|
|||
wo.w->get()->get_mining_history(mh);
|
||||
return API_RETURN_CODE_OK;
|
||||
}
|
||||
std::string daemon_backend::get_wallet_restore_info(uint64_t wallet_id, std::string& restore_key)
|
||||
std::string wallets_manager::get_wallet_restore_info(uint64_t wallet_id, std::string& restore_key)
|
||||
{
|
||||
GET_WALLET_OPT_BY_ID(wallet_id, wo);
|
||||
restore_key = wo.w->get()->get_account().get_restore_braindata();
|
||||
// restore_key = tools::base58::encode(rst_data);
|
||||
return API_RETURN_CODE_OK;
|
||||
}
|
||||
void daemon_backend::prepare_wallet_status_info(wallet_vs_options& wo, view::wallet_status_info& wsi)
|
||||
void wallets_manager::prepare_wallet_status_info(wallet_vs_options& wo, view::wallet_status_info& wsi)
|
||||
{
|
||||
wsi.is_mining = wo.do_mining;
|
||||
wsi.wallet_id = wo.wallet_id;
|
||||
wsi.is_alias_operations_available = !wo.has_related_alias_in_unconfirmed;
|
||||
wsi.balance = wo.w->get()->balance(wsi.unlocked_balance, wsi.awaiting_in, wsi.awaiting_out, wsi.minied_total);
|
||||
}
|
||||
std::string daemon_backend::check_available_sources(uint64_t wallet_id, std::list<uint64_t>& amounts)
|
||||
std::string wallets_manager::check_available_sources(uint64_t wallet_id, std::list<uint64_t>& amounts)
|
||||
{
|
||||
GET_WALLET_OPT_BY_ID(wallet_id, wo);
|
||||
if (wo.w->get()->check_available_sources(amounts))
|
||||
|
|
@ -1329,31 +1439,29 @@ std::string daemon_backend::check_available_sources(uint64_t wallet_id, std::lis
|
|||
else
|
||||
return API_RETURN_CODE_FALSE;
|
||||
}
|
||||
std::string daemon_backend::stop_pos_mining(uint64_t wallet_id)
|
||||
std::string wallets_manager::stop_pos_mining(uint64_t wallet_id)
|
||||
{
|
||||
GET_WALLET_OPT_BY_ID(wallet_id, wo);
|
||||
wo.do_mining = false;
|
||||
wo.need_to_update_wallet_info = true;
|
||||
return API_RETURN_CODE_OK;
|
||||
}
|
||||
std::string daemon_backend::run_wallet(uint64_t wallet_id)
|
||||
std::string wallets_manager::run_wallet(uint64_t wallet_id)
|
||||
{
|
||||
GET_WALLET_OPT_BY_ID(wallet_id, wo);
|
||||
wo.miner_thread = std::thread(boost::bind(&daemon_backend::wallet_vs_options::worker_func, &wo));
|
||||
return API_RETURN_CODE_OK;
|
||||
}
|
||||
std::string daemon_backend::get_wallet_info(wallet_vs_options& wo, view::wallet_info& wi)
|
||||
{
|
||||
wi = view::wallet_info();
|
||||
wi.address = wo.w->get()->get_account().get_public_address_str();
|
||||
wi.tracking_hey = string_tools::pod_to_hex(wo.w->get()->get_account().get_keys().m_view_secret_key);
|
||||
uint64_t fake = 0;
|
||||
wi.balance = wo.w->get()->balance(wi.unlocked_balance, fake, fake, wi.mined_total);
|
||||
wi.path = epee::string_encoding::wstring_to_utf8(wo.w->get()->get_wallet_path());
|
||||
wo.miner_thread = std::thread(boost::bind(&wallets_manager::wallet_vs_options::worker_func, &wo));
|
||||
return API_RETURN_CODE_OK;
|
||||
}
|
||||
|
||||
std::string daemon_backend::push_offer(size_t wallet_id, const bc_services::offer_details_ex& od, currency::transaction& res_tx)
|
||||
std::string wallets_manager::get_wallet_info(wallet_vs_options& wo, view::wallet_info& wi)
|
||||
{
|
||||
auto locker_object = wo.w.lock();
|
||||
tools::wallet2& rw = *(*(*locker_object)); //this looks a bit crazy, i know
|
||||
tools::get_wallet_info(rw, wi);
|
||||
return API_RETURN_CODE_OK;
|
||||
}
|
||||
|
||||
std::string wallets_manager::push_offer(size_t wallet_id, const bc_services::offer_details_ex& od, currency::transaction& res_tx)
|
||||
{
|
||||
GET_WALLET_BY_ID(wallet_id, w);
|
||||
|
||||
|
|
@ -1375,7 +1483,7 @@ std::string daemon_backend::push_offer(size_t wallet_id, const bc_services::offe
|
|||
return API_RETURN_CODE_INTERNAL_ERROR;
|
||||
}
|
||||
}
|
||||
std::string daemon_backend::cancel_offer(const view::cancel_offer_param& co, currency::transaction& res_tx)
|
||||
std::string wallets_manager::cancel_offer(const view::cancel_offer_param& co, currency::transaction& res_tx)
|
||||
{
|
||||
GET_WALLET_BY_ID(co.wallet_id, w);
|
||||
try
|
||||
|
|
@ -1397,7 +1505,7 @@ std::string daemon_backend::cancel_offer(const view::cancel_offer_param& co, cur
|
|||
}
|
||||
}
|
||||
|
||||
std::string daemon_backend::push_update_offer(const bc_services::update_offer_details& uo, currency::transaction& res_tx)
|
||||
std::string wallets_manager::push_update_offer(const bc_services::update_offer_details& uo, currency::transaction& res_tx)
|
||||
{
|
||||
GET_WALLET_BY_ID(uo.wallet_id, w);
|
||||
|
||||
|
|
@ -1428,18 +1536,22 @@ std::string daemon_backend::push_update_offer(const bc_services::update_offer_de
|
|||
// }
|
||||
|
||||
|
||||
std::string daemon_backend::get_offers_ex(const bc_services::core_offers_filter& cof, std::list<bc_services::offer_details_ex>& offers, uint64_t& total_count)
|
||||
std::string wallets_manager::get_offers_ex(const bc_services::core_offers_filter& cof, std::list<bc_services::offer_details_ex>& offers, uint64_t& total_count)
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
std::string daemon_backend::validate_address(const std::string& addr_str, std::string& payment_id)
|
||||
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))
|
||||
|
|
@ -1448,12 +1560,12 @@ std::string daemon_backend::validate_address(const std::string& addr_str, std::s
|
|||
return API_RETURN_CODE_FALSE;
|
||||
}
|
||||
|
||||
void daemon_backend::on_new_block(size_t wallet_id, uint64_t /*height*/, const currency::block& /*block*/)
|
||||
void wallets_manager::on_new_block(size_t wallet_id, uint64_t /*height*/, const currency::block& /*block*/)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void daemon_backend::on_transfer2(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined)
|
||||
void wallets_manager::on_transfer2(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined)
|
||||
{
|
||||
view::transfer_event_info tei = AUTO_VAL_INIT(tei);
|
||||
tei.ti = wti;
|
||||
|
|
@ -1462,11 +1574,11 @@ void daemon_backend::on_transfer2(size_t wallet_id, const tools::wallet_public::
|
|||
tei.wallet_id = wallet_id;
|
||||
m_pview->money_transfer(tei);
|
||||
}
|
||||
void daemon_backend::on_pos_block_found(size_t wallet_id, const currency::block& b)
|
||||
void wallets_manager::on_pos_block_found(size_t wallet_id, const currency::block& b)
|
||||
{
|
||||
m_pview->pos_block_found(b);
|
||||
}
|
||||
void daemon_backend::on_sync_progress(size_t wallet_id, const uint64_t& percents)
|
||||
void wallets_manager::on_sync_progress(size_t wallet_id, const uint64_t& percents)
|
||||
{
|
||||
// do not lock m_wallets_lock down the callstack! It will lead to a deadlock, because wallet locked_object is aready locked
|
||||
// and other threads are usually locks m_wallets_lock before locking wallet's locked_object
|
||||
|
|
@ -1476,7 +1588,7 @@ void daemon_backend::on_sync_progress(size_t wallet_id, const uint64_t& percents
|
|||
wspp.wallet_id = wallet_id;
|
||||
m_pview->wallet_sync_progress(wspp);
|
||||
}
|
||||
void daemon_backend::on_transfer_canceled(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti)
|
||||
void wallets_manager::on_transfer_canceled(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti)
|
||||
{
|
||||
view::transfer_event_info tei = AUTO_VAL_INIT(tei);
|
||||
tei.ti = wti;
|
||||
|
|
@ -1495,7 +1607,7 @@ void daemon_backend::on_transfer_canceled(size_t wallet_id, const tools::wallet_
|
|||
}
|
||||
m_pview->money_transfer_cancel(tei);
|
||||
}
|
||||
void daemon_backend::wallet_vs_options::worker_func()
|
||||
void wallets_manager::wallet_vs_options::worker_func()
|
||||
{
|
||||
LOG_PRINT_GREEN("[WALLET_HANDLER] Wallet handler thread started, addr: " << w->get()->get_account().get_public_address_str(), LOG_LEVEL_0);
|
||||
epee::math_helper::once_a_time_seconds<1> scan_pool_interval;
|
||||
|
|
@ -1524,6 +1636,13 @@ void daemon_backend::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;
|
||||
|
|
@ -1531,6 +1650,7 @@ void daemon_backend::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')
|
||||
|
|
@ -1625,7 +1745,7 @@ void daemon_backend::wallet_vs_options::worker_func()
|
|||
}
|
||||
LOG_PRINT_GREEN("[WALLET_HANDLER] Wallet thread thread stopped", LOG_LEVEL_0);
|
||||
}
|
||||
daemon_backend::wallet_vs_options::~wallet_vs_options()
|
||||
wallets_manager::wallet_vs_options::~wallet_vs_options()
|
||||
{
|
||||
do_mining = false;
|
||||
major_stop = true;
|
||||
|
|
@ -1635,7 +1755,7 @@ daemon_backend::wallet_vs_options::~wallet_vs_options()
|
|||
miner_thread.join();
|
||||
}
|
||||
|
||||
std::string daemon_backend::get_wallet_log_prefix(size_t wallet_id) const
|
||||
std::string wallets_manager::get_wallet_log_prefix(size_t wallet_id) const
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_wallet_log_prefixes_lock);
|
||||
|
||||
|
|
@ -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 <crtdbg.h>
|
||||
#endif
|
||||
|
||||
//TODO: need refactoring here. (template classes can't be used in BOOST_CLASS_VERSION)
|
||||
BOOST_CLASS_VERSION(nodetool::node_server<currency::t_currency_protocol_handler<currency::core> >, CURRENT_P2P_STORAGE_ARCHIVE_VER);
|
||||
|
||||
struct wallet_lock_time_watching_policy
|
||||
{
|
||||
|
|
@ -47,7 +48,7 @@ struct wallet_lock_time_watching_policy
|
|||
};
|
||||
|
||||
|
||||
class daemon_backend : public i_backend_wallet_callback
|
||||
class wallets_manager : public i_backend_wallet_callback
|
||||
{
|
||||
|
||||
public:
|
||||
|
|
@ -55,6 +56,7 @@ public:
|
|||
{
|
||||
currency::core_runtime_config core_conf;
|
||||
epee::locked_object<std::shared_ptr<tools::wallet2>, wallet_lock_time_watching_policy> w;
|
||||
std::shared_ptr<tools::wallet_rpc_server> rpc_wrapper; //500 bytes of extra data, we can afford it, to have rpc-like invoke map
|
||||
std::atomic<bool> do_mining;
|
||||
std::atomic<bool> major_stop;
|
||||
std::atomic<bool> stop_for_refresh; //use separate var for passing to "refresh" member function,
|
||||
|
|
@ -68,6 +70,10 @@ public:
|
|||
std::atomic<bool>* plast_daemon_is_disconnected;
|
||||
std::atomic<bool> has_related_alias_in_unconfirmed;
|
||||
std::atomic<bool> need_to_update_wallet_info;
|
||||
|
||||
std::atomic<bool> 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<std::list<bc_services::offer_details_ex>> offers;
|
||||
|
|
@ -78,8 +84,8 @@ public:
|
|||
~wallet_vs_options();
|
||||
};
|
||||
|
||||
daemon_backend();
|
||||
~daemon_backend();
|
||||
wallets_manager();
|
||||
~wallets_manager();
|
||||
bool init(int argc, char* argv[], view::i_view* pview_handler);
|
||||
bool start();
|
||||
bool stop();
|
||||
|
|
@ -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; }
|
||||
|
|
@ -152,6 +162,7 @@ private:
|
|||
void update_wallets_info();
|
||||
void init_wallet_entry(wallet_vs_options& wo, uint64_t id);
|
||||
static void prepare_wallet_status_info(wallet_vs_options& wo, view::wallet_status_info& wsi);
|
||||
bool get_is_remote_daemon_connected();
|
||||
//----- i_backend_wallet_callback ------
|
||||
virtual void on_new_block(size_t wallet_id, uint64_t height, const currency::block& block);
|
||||
virtual void on_transfer2(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined);
|
||||
|
|
@ -176,12 +187,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<currency::core> m_cprotocol;
|
||||
nodetool::node_server<currency::t_currency_protocol_handler<currency::core> > m_p2psrv;
|
||||
currency::core_rpc_server m_rpc_server;
|
||||
#endif
|
||||
|
||||
bool m_remote_node_mode;
|
||||
bool m_qt_logs_enbaled;
|
||||
|
|
@ -2047,9 +2047,11 @@ test_chain_unit_enchanced::test_chain_unit_enchanced()
|
|||
: m_invalid_block_index(std::numeric_limits<size_t>::max())
|
||||
, m_orphan_block_index(std::numeric_limits<size_t>::max())
|
||||
, m_invalid_tx_index(std::numeric_limits<size_t>::max())
|
||||
, m_unverifiable_tx_index(std::numeric_limits<size_t>::max())
|
||||
{
|
||||
REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, configure_core);
|
||||
REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, mark_invalid_tx);
|
||||
REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, mark_unverifiable_tx);
|
||||
REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, mark_invalid_block);
|
||||
REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, mark_orphan_block);
|
||||
REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, check_top_block);
|
||||
|
|
|
|||
|
|
@ -258,6 +258,9 @@ public:
|
|||
{
|
||||
if (m_invalid_tx_index == event_idx)
|
||||
return tvc.m_verification_failed;
|
||||
|
||||
if (m_unverifiable_tx_index == event_idx)
|
||||
return tvc.m_verification_impossible;
|
||||
|
||||
return !tvc.m_verification_failed && tx_added;
|
||||
}
|
||||
|
|
@ -291,6 +294,12 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
bool mark_unverifiable_tx(currency::core& /*c*/, size_t ev_index, const std::vector<test_event_entry>& /*events*/)
|
||||
{
|
||||
m_unverifiable_tx_index = ev_index + 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool configure_core(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
bool check_top_block(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
bool clear_tx_pool(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
|
|
@ -310,6 +319,7 @@ protected:
|
|||
};
|
||||
size_t m_invalid_block_index;
|
||||
size_t m_invalid_tx_index;
|
||||
size_t m_unverifiable_tx_index;
|
||||
size_t m_orphan_block_index;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#include "chaingen_tests_list.h"
|
||||
#include "common/command_line.h"
|
||||
#include "transaction_tests.h"
|
||||
#include "../../src/gui/qt-daemon/application/core_fast_rpc_proxy.h"
|
||||
#include "../../src/wallet/core_fast_rpc_proxy.h"
|
||||
#include "test_core_proxy.h"
|
||||
#include "currency_core/bc_offers_service.h"
|
||||
#include "random_helper.h"
|
||||
|
|
@ -809,6 +809,7 @@ int main(int argc, char* argv[])
|
|||
GENERATE_AND_PLAY(gen_checkpoints_prun_txs_after_blockchain_load);
|
||||
GENERATE_AND_PLAY(gen_checkpoints_reorganize);
|
||||
GENERATE_AND_PLAY(gen_checkpoints_pos_validation_on_altchain);
|
||||
GENERATE_AND_PLAY(gen_checkpoints_and_invalid_tx_to_pool);
|
||||
GENERATE_AND_PLAY(gen_no_attchments_in_coinbase);
|
||||
GENERATE_AND_PLAY(gen_no_attchments_in_coinbase_gentime);
|
||||
|
||||
|
|
|
|||
|
|
@ -81,7 +81,9 @@ bool gen_checkpoints_attachments_basic::generate(std::vector<test_event_entry>&
|
|||
REWIND_BLOCKS_N(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
|
||||
|
||||
// 0 ... N N+1 N+2 <- height (N = CURRENCY_MINED_MONEY_UNLOCK_WINDOW)
|
||||
// CP checkpoint
|
||||
// (0 )- (0r)- (1 )- (2 )
|
||||
// tx_0 txs
|
||||
|
||||
DO_CALLBACK_PARAMS(events, "set_checkpoint", params_checkpoint(CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 2));
|
||||
|
||||
|
|
@ -94,10 +96,13 @@ bool gen_checkpoints_attachments_basic::generate(std::vector<test_event_entry>&
|
|||
attachments.push_back(cm);
|
||||
attachments.push_back(ms);
|
||||
|
||||
MAKE_TX_LIST_START_WITH_ATTACHS(events, txs, miner_acc, miner_acc, MK_TEST_COINS(1), blk_0r, attachments);
|
||||
m_tx_hash = get_transaction_hash(txs.front());
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tx_0 goes with the block blk_1
|
||||
MAKE_TX_ATTACH(events, tx_0, miner_acc, miner_acc, MK_TEST_COINS(1), blk_0r, attachments);
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false));
|
||||
|
||||
m_tx_hash = get_transaction_hash(tx_0);
|
||||
|
||||
MAKE_NEXT_BLOCK_TX_LIST(events, blk_1, blk_0r, miner_acc, txs);
|
||||
MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_0);
|
||||
|
||||
MAKE_NEXT_BLOCK(events, blk_2, blk_1, miner_acc);
|
||||
|
||||
|
|
@ -150,7 +155,10 @@ bool gen_checkpoints_invalid_keyimage::generate(std::vector<test_event_entry>& e
|
|||
// don't sign at all
|
||||
// tb.step5_sign();
|
||||
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tb.m_tx goes with block blk_1
|
||||
events.push_back(tb.m_tx);
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false));
|
||||
|
||||
MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tb.m_tx);
|
||||
|
||||
MAKE_NEXT_BLOCK(events, blk_2, blk_1, miner_acc);
|
||||
|
|
@ -376,33 +384,40 @@ bool gen_checkpoints_prun_txs_after_blockchain_load::generate(std::vector<test_e
|
|||
MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, ts);
|
||||
REWIND_BLOCKS_N(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
|
||||
|
||||
// 0 ... N N+1 N+2 N+3 N+4 N+5 N+6 <- height (N = CURRENCY_MINED_MONEY_UNLOCK_WINDOW)
|
||||
// +------->CP1 +------->CP2 <- checkpoints
|
||||
// | | <- when CP are set up
|
||||
// (0 )- (0r)- (1 )- (2 )- (3 )- (4 )- (5 )- (6 ) <- main chain
|
||||
// tx_0 tx_1 <- txs included in blocks
|
||||
// 0 ... N N+1 N+2 N+3 N+4 N+5 N+6 N+7 <- height (N = CURRENCY_MINED_MONEY_UNLOCK_WINDOW)
|
||||
// +------->CP1 +------->CP2 <- checkpoints
|
||||
// | | <- when CP are set up
|
||||
// (0 )- (0r)- (1 )- (2 )- (3 )- (4 )- (5 )- (6 )- (7 ) <- main chain
|
||||
// tx_0 tx_1 <- txs included in blocks
|
||||
//
|
||||
// Expected: tx_0 and tx_1 are both pruned
|
||||
|
||||
DO_CALLBACK(events, "check_not_being_in_cp_zone");
|
||||
DO_CALLBACK_PARAMS(events, "set_checkpoint", params_checkpoint(CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 2));
|
||||
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tx_0 goes with blk_1_bad
|
||||
MAKE_TX(events, tx_0, miner_acc, alice, MK_TEST_COINS(1), blk_0r);
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false));
|
||||
MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_0);
|
||||
|
||||
DO_CALLBACK(events, "check_being_in_cp_zone");
|
||||
MAKE_NEXT_BLOCK(events, blk_2, blk_1, miner_acc);
|
||||
|
||||
MAKE_TX(events, tx_1, miner_acc, alice, MK_TEST_COINS(1), blk_2);
|
||||
MAKE_NEXT_BLOCK_TX1(events, blk_3, blk_2, miner_acc, tx_1);
|
||||
MAKE_NEXT_BLOCK(events, blk_3, blk_2, miner_acc);
|
||||
|
||||
DO_CALLBACK(events, "check_not_being_in_cp_zone");
|
||||
DO_CALLBACK_PARAMS(events, "set_checkpoint", params_checkpoint(CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 5));
|
||||
|
||||
MAKE_NEXT_BLOCK(events, blk_4, blk_3, miner_acc);
|
||||
MAKE_TX(events, tx_1, miner_acc, alice, MK_TEST_COINS(1), blk_3);
|
||||
MAKE_NEXT_BLOCK_TX1(events, blk_4, blk_3, miner_acc, tx_1);
|
||||
|
||||
DO_CALLBACK(events, "check_not_being_in_cp_zone");
|
||||
|
||||
DO_CALLBACK_PARAMS(events, "set_checkpoint", params_checkpoint(CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 6));
|
||||
|
||||
MAKE_NEXT_BLOCK(events, blk_5, blk_4, miner_acc);
|
||||
DO_CALLBACK(events, "check_being_in_cp_zone");
|
||||
MAKE_NEXT_BLOCK(events, blk_6, blk_5, miner_acc);
|
||||
MAKE_NEXT_BLOCK(events, blk_7, blk_6, miner_acc);
|
||||
DO_CALLBACK(events, "check_not_being_in_cp_zone");
|
||||
|
||||
m_tx0_id = get_transaction_hash(tx_0);
|
||||
|
|
@ -813,3 +828,70 @@ bool gen_no_attchments_in_coinbase_gentime::generate(std::vector<test_event_entr
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
gen_checkpoints_and_invalid_tx_to_pool::gen_checkpoints_and_invalid_tx_to_pool()
|
||||
{
|
||||
REGISTER_CALLBACK_METHOD(gen_checkpoints_and_invalid_tx_to_pool, c1);
|
||||
}
|
||||
|
||||
bool gen_checkpoints_and_invalid_tx_to_pool::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
// Test idea: make sure txs with invalid signatures rejected by the pool when the core is in CP zone
|
||||
// Mine a block aftewards to make sure everything is okay.
|
||||
|
||||
// 0 ... N N+1 N+2 <- height (N = CURRENCY_MINED_MONEY_UNLOCK_WINDOW)
|
||||
// +------->CP1 <- checkpoint
|
||||
// | <- when CP is set up
|
||||
// (0 )- (0r)- (1 )- (2 )- <- main chain
|
||||
// tx_0 CB
|
||||
|
||||
bool r = false;
|
||||
GENERATE_ACCOUNT(miner_acc);
|
||||
MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, test_core_time::get_time());
|
||||
DO_CALLBACK_PARAMS(events, "set_checkpoint", params_checkpoint(CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 1));
|
||||
|
||||
REWIND_BLOCKS_N(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
|
||||
|
||||
std::vector<tx_source_entry> sources;
|
||||
std::vector<tx_destination_entry> destinations;
|
||||
r = fill_tx_sources_and_destinations(events, blk_0r, miner_acc, miner_acc, MK_TEST_COINS(1), TESTS_DEFAULT_FEE, 0, sources, destinations);
|
||||
CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed");
|
||||
|
||||
transaction tx_0 = AUTO_VAL_INIT(tx_0);
|
||||
r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, 0);
|
||||
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
|
||||
|
||||
// invalidate tx_0 signature
|
||||
tx_0.signatures.clear();
|
||||
|
||||
DO_CALLBACK(events, "mark_unverifiable_tx");
|
||||
events.push_back(tx_0);
|
||||
|
||||
MAKE_NEXT_BLOCK(events, blk_1, blk_0r, miner_acc); // <-- CHECKPOINT
|
||||
MAKE_NEXT_BLOCK(events, blk_2, blk_1, miner_acc);
|
||||
|
||||
DO_CALLBACK(events, "check_not_being_in_cp_zone");
|
||||
|
||||
DO_CALLBACK(events, "check_tx_pool_empty");
|
||||
|
||||
// try to mine a block using default blocktemplate (all txs from the pool)
|
||||
DO_CALLBACK(events, "c1");
|
||||
|
||||
DO_CALLBACK(events, "check_tx_pool_empty");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool gen_checkpoints_and_invalid_tx_to_pool::c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
|
||||
{
|
||||
account_base acc;
|
||||
acc.generate();
|
||||
|
||||
bool r = mine_next_pow_block_in_playtime(acc.get_public_address(), c);
|
||||
CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -102,3 +102,10 @@ struct gen_no_attchments_in_coinbase_gentime : public checkpoints_test
|
|||
{
|
||||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
};
|
||||
|
||||
struct gen_checkpoints_and_invalid_tx_to_pool : public checkpoints_test
|
||||
{
|
||||
gen_checkpoints_and_invalid_tx_to_pool();
|
||||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -340,11 +340,13 @@ bool hard_fork_1_checkpoint_basic_test::generate(std::vector<test_event_entry>&
|
|||
r = construct_tx(miner_acc.get_keys(), sources, destinations, extra, empty_attachment, tx_0, tx_sec_key, 0 /* unlock time 1 is zero and thus will not be set */);
|
||||
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
|
||||
// tx_0 should be accepted
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tx_0 goes with blk_1_bad
|
||||
events.push_back(tx_0);
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false));
|
||||
|
||||
DO_CALLBACK(events, "mark_invalid_block");
|
||||
MAKE_NEXT_BLOCK_TX1(events, blk_1_bad, blk_0r, miner_acc, tx_0); // should be rejected because of tx_0
|
||||
DO_CALLBACK_PARAMS(events, "check_tx_pool_count", static_cast<size_t>(1));
|
||||
DO_CALLBACK(events, "check_tx_pool_empty"); // tx_0 won't be returned to the pool as it came with block blk_1_bad
|
||||
DO_CALLBACK(events, "clear_tx_pool");
|
||||
|
||||
MAKE_NEXT_BLOCK(events, blk_1, blk_0r, miner_acc);
|
||||
|
|
@ -360,7 +362,9 @@ bool hard_fork_1_checkpoint_basic_test::generate(std::vector<test_event_entry>&
|
|||
//
|
||||
|
||||
// now tx_0 is okay and can be added to the blockchain
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tx_0 goes with blk_5
|
||||
events.push_back(tx_0);
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false));
|
||||
MAKE_NEXT_BLOCK_TX1(events, blk_5, blk_4, miner_acc, tx_0);
|
||||
|
||||
REWIND_BLOCKS_N_WITH_TIME(events, blk_5r, blk_5, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
|
||||
|
|
|
|||
|
|
@ -1622,7 +1622,7 @@ multisig_and_checkpoints::multisig_and_checkpoints()
|
|||
bool multisig_and_checkpoints::set_cp(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
|
||||
{
|
||||
currency::checkpoints checkpoints;
|
||||
checkpoints.add_checkpoint(15, "a8e535abb31cd2c07ebd65dbb8d4160954677a0cebcd3dadf81642297cc557af");
|
||||
checkpoints.add_checkpoint(15, "72d63d6500c62d6783108f5a2e2c9f1dc1f0aae57011cf123583eec679a52cf9");
|
||||
c.set_checkpoints(std::move(checkpoints));
|
||||
|
||||
return true;
|
||||
|
|
@ -1674,7 +1674,10 @@ bool multisig_and_checkpoints::generate(std::vector<test_event_entry>& events) c
|
|||
transaction tx_1 = AUTO_VAL_INIT(tx_1);
|
||||
r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, 0, CURRENCY_TO_KEY_OUT_RELAXED, true);
|
||||
CHECK_AND_ASSERT_MES(r, false, "construct_tx");
|
||||
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tx_1 goes with the block blk_1
|
||||
events.push_back(tx_1);
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false));
|
||||
|
||||
MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_1);
|
||||
|
||||
|
|
@ -1695,7 +1698,9 @@ bool multisig_and_checkpoints::generate(std::vector<test_event_entry>& events) c
|
|||
bool tx_fully_signed = false;
|
||||
r = sign_multisig_input_in_tx(tx_2, 0, alice_acc.get_keys(), tx_1, &tx_fully_signed);
|
||||
CHECK_AND_ASSERT_MES(r & tx_fully_signed, false, "sign_multisig_input_in_tx failed, tx_fully_signed: " << tx_fully_signed);
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tx_2 goes with the block blk_2
|
||||
events.push_back(tx_2);
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false));
|
||||
MAKE_NEXT_BLOCK_TX1(events, blk_2, blk_1, miner_acc, tx_2);
|
||||
|
||||
ADJUST_TEST_CORE_TIME(blk_2.timestamp);
|
||||
|
|
@ -1708,7 +1713,10 @@ bool multisig_and_checkpoints::generate(std::vector<test_event_entry>& events) c
|
|||
transaction tx_3 = AUTO_VAL_INIT(tx_3);
|
||||
r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_3, 0, CURRENCY_TO_KEY_OUT_RELAXED, true);
|
||||
CHECK_AND_ASSERT_MES(r, false, "construct_tx");
|
||||
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tx_3 goes with the block blk_3
|
||||
events.push_back(tx_3);
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false));
|
||||
|
||||
MAKE_NEXT_BLOCK_TX1(events, blk_3, blk_2, miner_acc, tx_3); // <-- CP
|
||||
|
||||
|
|
@ -1732,7 +1740,9 @@ bool multisig_and_checkpoints::generate(std::vector<test_event_entry>& events) c
|
|||
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
|
||||
r = sign_multisig_input_in_tx(tx_4, 0, alice_acc.get_keys(), tx_3, &tx_fully_signed);
|
||||
CHECK_AND_ASSERT_MES(r & tx_fully_signed, false, "sign_multisig_input_in_tx failed, tx_fully_signed: " << tx_fully_signed);
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tx_4 goes with the block blk_4
|
||||
events.push_back(tx_4);
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false));
|
||||
MAKE_NEXT_BLOCK_TX1(events, blk_4, blk_3, miner_acc, tx_4);
|
||||
|
||||
// tx_5: normal input -> multisig output
|
||||
|
|
@ -1815,7 +1825,10 @@ bool multisig_and_checkpoints_bad_txs::generate(std::vector<test_event_entry>& e
|
|||
transaction tx_1 = AUTO_VAL_INIT(tx_1);
|
||||
r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, 0, CURRENCY_TO_KEY_OUT_RELAXED, true);
|
||||
CHECK_AND_ASSERT_MES(r, false, "construct_tx");
|
||||
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tx_1 goes with the block blk_1
|
||||
events.push_back(tx_1);
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false));
|
||||
|
||||
MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_1);
|
||||
|
||||
|
|
@ -1829,21 +1842,24 @@ bool multisig_and_checkpoints_bad_txs::generate(std::vector<test_event_entry>& e
|
|||
boost::get<txin_multisig>(tx_2.vin[0]).sigs_count = 10;
|
||||
|
||||
DO_CALLBACK(events, "mark_invalid_tx");
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true));
|
||||
events.push_back(tx_2);
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false));
|
||||
|
||||
MAKE_NEXT_BLOCK(events, blk_2, blk_1, miner_acc);
|
||||
|
||||
DO_CALLBACK_PARAMS(events, "check_balance", params_check_balance(BOB_ACC_IDX, 0, 0, 0, 0, 0));
|
||||
|
||||
// tx_3: no signatures, zero sigs_count in ms input (should FAIL)
|
||||
// tx_3: no signatures, zero sigs_count in ms input (should pass under CP zone)
|
||||
transaction tx_3 = AUTO_VAL_INIT(tx_3);
|
||||
r = make_tx_multisig_to_key(tx_1, get_tx_out_index_by_amount(tx_1, amount), std::list<account_keys>({ alice_acc.get_keys() }), bob_acc.get_public_address(), tx_3);
|
||||
CHECK_AND_ASSERT_MES(r, false, "make_tx_multisig_to_key failed");
|
||||
tx_3.signatures.clear();
|
||||
boost::get<txin_multisig>(tx_3.vin[0]).sigs_count = 0;
|
||||
|
||||
DO_CALLBACK(events, "mark_invalid_tx");
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true));
|
||||
events.push_back(tx_3);
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false));
|
||||
|
||||
// tx_4: zero ms out keys (should FAIL)
|
||||
r = fill_tx_sources_and_destinations(events, blk_0r, miner_acc.get_keys(), to_addrs, amount, TESTS_DEFAULT_FEE, 0, sources, destinations, true, true, 1);
|
||||
|
|
@ -1857,7 +1873,9 @@ bool multisig_and_checkpoints_bad_txs::generate(std::vector<test_event_entry>& e
|
|||
txb.step5_sign(sources);
|
||||
transaction tx_4 = txb.m_tx;
|
||||
DO_CALLBACK(events, "mark_invalid_tx");
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true));
|
||||
events.push_back(tx_4);
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false));
|
||||
|
||||
// tx_6: many ms out keys + no sigs (should pass due to CP zone)
|
||||
txb = AUTO_VAL_INIT(txb);
|
||||
|
|
@ -1870,7 +1888,9 @@ bool multisig_and_checkpoints_bad_txs::generate(std::vector<test_event_entry>& e
|
|||
txb.step5_sign(sources);
|
||||
txb.m_tx.signatures.clear();
|
||||
transaction tx_6 = txb.m_tx;
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true));
|
||||
events.push_back(tx_6);
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false));
|
||||
|
||||
MAKE_NEXT_BLOCK_TX1(events, blk_3, blk_2, miner_acc, tx_6);
|
||||
|
||||
|
|
@ -1880,7 +1900,9 @@ bool multisig_and_checkpoints_bad_txs::generate(std::vector<test_event_entry>& e
|
|||
transaction tx_7 = AUTO_VAL_INIT(tx_7);
|
||||
r = make_tx_multisig_to_key(tx_6, get_tx_out_index_by_amount(tx_6, amount), std::list<account_keys>({ alice_acc.get_keys() }), bob_acc.get_public_address(), tx_7);
|
||||
CHECK_AND_ASSERT_MES(r, false, "make_tx_multisig_to_key failed");
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true));
|
||||
events.push_back(tx_7);
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false));
|
||||
|
||||
MAKE_NEXT_BLOCK_TX1(events, blk_4, blk_3, miner_acc, tx_7);
|
||||
|
||||
|
|
|
|||
|
|
@ -1040,6 +1040,8 @@ bool pos_minting_tx_packing::pos_minting_tx_packing::generate(std::vector<test_e
|
|||
REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 5);
|
||||
|
||||
m_alice_start_amount = 10 * CURRENCY_BLOCK_REWARD * m_pos_mint_packing_size;// +TESTS_DEFAULT_FEE;
|
||||
|
||||
// 10 outputs each of (CURRENCY_BLOCK_REWARD * m_pos_mint_packing_size) coins
|
||||
|
||||
transaction tx_1 = AUTO_VAL_INIT(tx_1);
|
||||
r = construct_tx_with_many_outputs(events, blk_0r, miner_acc.get_keys(), alice_acc.get_public_address(), m_alice_start_amount, 10, TESTS_DEFAULT_FEE, tx_1);
|
||||
|
|
@ -1085,7 +1087,7 @@ bool pos_minting_tx_packing::c1(currency::core& c, size_t ev_index, const std::v
|
|||
|
||||
alice_wlt->set_pos_mint_packing_size(m_pos_mint_packing_size);
|
||||
|
||||
// no coinbase tx outputs should packed
|
||||
// no coinbase tx outputs should be packed
|
||||
r = alice_wlt->try_mint_pos();
|
||||
CHECK_AND_ASSERT_MES(r, false, "try_mint_pos failed");
|
||||
|
||||
|
|
@ -1112,12 +1114,24 @@ bool pos_minting_tx_packing::c1(currency::core& c, size_t ev_index, const std::v
|
|||
CHECK_AND_ASSERT_MES(r, false, "try_mint_pos failed");
|
||||
|
||||
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Alice", alice_wlt,
|
||||
m_alice_start_amount + CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 2), // total
|
||||
m_alice_start_amount + CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 2), // total (+1 one block reward)
|
||||
true,
|
||||
UINT64_MAX,
|
||||
m_alice_start_amount + CURRENCY_BLOCK_REWARD
|
||||
// CURRENCY_BLOCK_REWARD * m_pos_mint_packing_size locked for stake
|
||||
// CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 1) locked for packing tx
|
||||
m_alice_start_amount + CURRENCY_BLOCK_REWARD - CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 1) // unlocked
|
||||
), false, "");
|
||||
|
||||
r = alice_wlt->try_mint_pos();
|
||||
CHECK_AND_ASSERT_MES(r, false, "try_mint_pos failed");
|
||||
|
||||
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Alice", alice_wlt,
|
||||
m_alice_start_amount + CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 3), // total (+1 one block reward)
|
||||
true,
|
||||
UINT64_MAX,
|
||||
// CURRENCY_BLOCK_REWARD * m_pos_mint_packing_size locked for stake
|
||||
m_alice_start_amount + CURRENCY_BLOCK_REWARD - CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 1) - CURRENCY_BLOCK_REWARD * m_pos_mint_packing_size // unlocked
|
||||
), false, "");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ bool generate_blockchain_with_pruned_rs(std::vector<test_event_entry>& events)
|
|||
REWIND_BLOCKS_N(events, blk_5, blk_4, miner_account, 30);
|
||||
REWIND_BLOCKS(events, blk_5r, blk_5, miner_account);
|
||||
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true));
|
||||
MAKE_TX_LIST_START(events, txs_blk_6, miner_account, some_account_1, MK_TEST_COINS(1), blk_5r);
|
||||
MAKE_TX_LIST(events, txs_blk_6, miner_account, some_account_1, MK_TEST_COINS(1), blk_5r);
|
||||
MAKE_TX_LIST(events, txs_blk_6, miner_account, some_account_1, MK_TEST_COINS(1), blk_5r);
|
||||
|
|
@ -69,13 +70,16 @@ bool generate_blockchain_with_pruned_rs(std::vector<test_event_entry>& events)
|
|||
MAKE_TX_LIST(events, txs_blk_6, miner_account, some_account_1, MK_TEST_COINS(1), blk_5r);
|
||||
MAKE_TX_LIST(events, txs_blk_6, miner_account, some_account_1, MK_TEST_COINS(1), blk_5r);
|
||||
MAKE_TX_LIST(events, txs_blk_6, miner_account, some_account_1, MK_TEST_COINS(1), blk_5r);
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false));
|
||||
MAKE_NEXT_BLOCK_TX_LIST(events, blk_6, blk_5r, miner_account, txs_blk_6);
|
||||
REWIND_BLOCKS_N(events, blk_6r, blk_6, miner_account, 20);
|
||||
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true));
|
||||
MAKE_TX_LIST_START(events, txs_blk_7, some_account_1, some_account_1, MK_TEST_COINS(1) + TESTS_DEFAULT_FEE, blk_6r);
|
||||
MAKE_TX_MIX_LIST(events, txs_blk_7, some_account_1, some_account_1, MK_TEST_COINS(1) + TESTS_DEFAULT_FEE, 3, blk_6r, std::vector<currency::attachment_v>());
|
||||
MAKE_TX_MIX_LIST(events, txs_blk_7, some_account_1, some_account_1, MK_TEST_COINS(1) + TESTS_DEFAULT_FEE, 3, blk_6r, std::vector<currency::attachment_v>());
|
||||
MAKE_TX_MIX_LIST(events, txs_blk_7, some_account_1, some_account_1, MK_TEST_COINS(1) + TESTS_DEFAULT_FEE, 3, blk_6r, std::vector<currency::attachment_v>());
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false));
|
||||
MAKE_NEXT_BLOCK_TX_LIST(events, blk_7, blk_6r, miner_account, txs_blk_7);
|
||||
REWIND_BLOCKS(events, blk_7r, blk_7, miner_account);
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
@ -284,8 +284,10 @@ bool generate_events(currency::core& c, cct_events_t& events, const cct_wallets_
|
|||
bool clean_data_directory(boost::program_options::variables_map& vm)
|
||||
{
|
||||
std::string config_folder = command_line::get_arg(vm, command_line::arg_data_dir);
|
||||
const std::string bch_db_folder_path = config_folder + ("/" CURRENCY_BLOCKCHAINDATA_FOLDERNAME_PREFIX) + "lmdb" + CURRENCY_BLOCKCHAINDATA_FOLDERNAME_SUFFIX;
|
||||
const std::string pool_db_folder_path = config_folder + ("/" CURRENCY_POOLDATA_FOLDERNAME_PREFIX) + "lmdb" + CURRENCY_POOLDATA_FOLDERNAME_SUFFIX;
|
||||
|
||||
static const char* const files[] = { CURRENCY_BLOCKCHAINDATA_FOLDERNAME, CURRENCY_POOLDATA_FOLDERNAME, MINER_CONFIG_FILENAME };
|
||||
static const char* const files[] = { bch_db_folder_path.c_str(), pool_db_folder_path.c_str(), MINER_CONFIG_FILENAME };
|
||||
for (size_t i = 0; i < sizeof files / sizeof files[0]; ++i)
|
||||
{
|
||||
boost::filesystem::path filename(config_folder + "/" + files[i]);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ using namespace epee;
|
|||
#include "generate_test_genesis.h"
|
||||
#include "deadlock_guard_test.h"
|
||||
#include "difficulty_analysis.h"
|
||||
#include "plain_wallet_tests.h"
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
|
|
@ -53,6 +54,7 @@ namespace
|
|||
const command_line::arg_descriptor<size_t> arg_generate_test_genesis_json = { "generate-test-genesis-json", "generates test genesis json, specify amount of accounts", 0, true };
|
||||
const command_line::arg_descriptor<bool> arg_deadlock_guard = { "test-deadlock-guard", "Do deadlock guard test", false, true };
|
||||
const command_line::arg_descriptor<std::string> arg_difficulty_analysis = { "difficulty-analysis", "Do difficulty analysis", "", true };
|
||||
const command_line::arg_descriptor<bool> arg_test_plain_wallet = { "test-plainwallet", "Do testing of plain wallet interface", false, true };
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -66,11 +68,11 @@ int main(int argc, char* argv[])
|
|||
currency::get_block_reward(false, 500000, 589313, 10300000000000000, reward, 11030);
|
||||
|
||||
//set up logging options
|
||||
log_space::get_set_log_detalisation_level(true, LOG_LEVEL_1);
|
||||
log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2);
|
||||
log_space::log_singletone::add_logger(LOGGER_FILE,
|
||||
log_space::log_singletone::get_default_log_file().c_str(),
|
||||
log_space::log_singletone::get_default_log_folder().c_str());
|
||||
//log_space::get_set_log_detalisation_level(true, LOG_LEVEL_1);
|
||||
//log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2);
|
||||
//log_space::log_singletone::add_logger(LOGGER_FILE,
|
||||
// log_space::log_singletone::get_default_log_file().c_str(),
|
||||
// log_space::log_singletone::get_default_log_folder().c_str());
|
||||
|
||||
|
||||
po::options_description desc_options("Allowed options");
|
||||
|
|
@ -104,8 +106,7 @@ int main(int argc, char* argv[])
|
|||
command_line::add_arg(desc_options, arg_max_tx_in_pool);
|
||||
command_line::add_arg(desc_options, arg_deadlock_guard);
|
||||
command_line::add_arg(desc_options, arg_difficulty_analysis);
|
||||
|
||||
|
||||
command_line::add_arg(desc_options, arg_test_plain_wallet);
|
||||
|
||||
|
||||
test_serialization();
|
||||
|
|
@ -190,6 +191,11 @@ int main(int argc, char* argv[])
|
|||
do_deadlock_test_main();
|
||||
return 1;
|
||||
}
|
||||
else if (command_line::has_arg(vm, arg_test_plain_wallet))
|
||||
{
|
||||
run_plain_wallet_api_test();
|
||||
return 1;
|
||||
}
|
||||
else if (command_line::get_arg(vm, arg_test_core_concurrency))
|
||||
{
|
||||
for (size_t i = 0; i != repeat_count; i++)
|
||||
|
|
|
|||
244
tests/functional_tests/plain_wallet_tests.cpp
Normal file
244
tests/functional_tests/plain_wallet_tests.cpp
Normal file
|
|
@ -0,0 +1,244 @@
|
|||
// 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.
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/tokenizer.hpp>
|
||||
|
||||
#include "include_base_utils.h"
|
||||
using namespace epee;
|
||||
#include "misc_language.h"
|
||||
#include "wallet/plain_wallet_api.h"
|
||||
#include "wallet/wallet_helpers.h"
|
||||
#include "wallet/plain_wallet_api_defs.h"
|
||||
|
||||
|
||||
struct try_pull_result_open_response
|
||||
{
|
||||
bool delivered;
|
||||
epee::json_rpc::response<view::open_wallet_response, epee::json_rpc::dummy_error> result;
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(delivered)
|
||||
KV_SERIALIZE(result)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
||||
void run_plain_wallet_api_test()
|
||||
{
|
||||
LOG_PRINT_L0("Creating instance...");
|
||||
std::string s = plain_wallet::init("195.201.107.230", "11211");
|
||||
|
||||
LOG_PRINT_L0("Generating wallet...");
|
||||
view::open_wallet_request owr = AUTO_VAL_INIT(owr);
|
||||
owr.path = "E:\\tmp\\zano_testwallet_745ss65030.zan";
|
||||
owr.pass = "";
|
||||
std::string job_id_str = plain_wallet::async_call("open", 0, epee::serialization::store_t_to_json(owr));
|
||||
|
||||
|
||||
try_pull_result_open_response rsp = AUTO_VAL_INIT(rsp);
|
||||
|
||||
while (true)
|
||||
{
|
||||
std::string res = plain_wallet::try_pull_result(1);
|
||||
LOG_PRINT_L0("[try_pull_result] RESPONSE:" << ENDL << res);
|
||||
|
||||
if (!epee::serialization::load_t_from_json(rsp, res))
|
||||
{
|
||||
LOG_ERROR("Failed to parse try_pull_result response: " << res);
|
||||
return;
|
||||
}
|
||||
epee::misc_utils::sleep_no_w(1000);
|
||||
if(!rsp.delivered)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//std::string rsp = plain_wallet::open(std::string("E:\\tmp\\zano_testwallet_745ss65030.zan"), "");
|
||||
//LOG_PRINT_L0("RESPONSE:" << ENDL << rsp);
|
||||
//epee::json_rpc::response<view::open_wallet_response, epee::json_rpc::dummy_error> ok_response = AUTO_VAL_INIT(ok_response);
|
||||
//epee::serialization::load_t_from_json(ok_response, rsp);
|
||||
|
||||
size_t count = 0;
|
||||
while (count < 10)
|
||||
{
|
||||
std::string prog = plain_wallet::get_wallet_status(rsp.result.result.wallet_id);
|
||||
LOG_PRINT_L0("Progress: " << ENDL << prog);
|
||||
view::wallet_sync_status_info wsi = AUTO_VAL_INIT(wsi);
|
||||
if (!epee::serialization::load_t_from_json(wsi, prog))
|
||||
{
|
||||
LOG_ERROR("Failed to get_wallet_status()");
|
||||
return;
|
||||
}
|
||||
if (!wsi.is_in_long_refresh)
|
||||
break;
|
||||
epee::misc_utils::sleep_no_w(1000);
|
||||
}
|
||||
|
||||
std::string job_id_str2 = plain_wallet::async_call("close", rsp.result.result.wallet_id, "");
|
||||
try_pull_result_open_response rsp2 = AUTO_VAL_INIT(rsp2);
|
||||
|
||||
while (true)
|
||||
{
|
||||
std::string res = plain_wallet::try_pull_result(2);
|
||||
LOG_PRINT_L0("[try_pull_result] RESPONSE:" << ENDL << res);
|
||||
|
||||
if (!epee::serialization::load_t_from_json(rsp2, res))
|
||||
{
|
||||
LOG_ERROR("Failed to parse try_pull_result response: " << res);
|
||||
return;
|
||||
}
|
||||
epee::misc_utils::sleep_no_w(1000);
|
||||
if (!rsp2.delivered)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
LOG_PRINT_L0("OK");
|
||||
|
||||
}
|
||||
|
||||
// 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<plain_wallet::open_wallet_response, epee::json_rpc::dummy_error> 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<tools::wallet_public::COMMAND_RPC_GET_WALLET_INFO::request> gbreq = AUTO_VAL_INIT(gbreq);
|
||||
// gbreq.method = "get_wallet_info";
|
||||
// epee::json_rpc::response<tools::wallet_public::COMMAND_RPC_GET_WALLET_INFO::response, epee::json_rpc::error> 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<tools::wallet_public::COMMAND_RPC_GET_BALANCE::request> gbreq = AUTO_VAL_INIT(gbreq);
|
||||
// gbreq.method = "getbalance";
|
||||
// epee::json_rpc::response<tools::wallet_public::COMMAND_RPC_GET_BALANCE::response, epee::json_rpc::error> 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<tools::wallet_public::COMMAND_RPC_STORE::request> gbreq = AUTO_VAL_INIT(gbreq);
|
||||
// gbreq.method = "store";
|
||||
// epee::json_rpc::response<tools::wallet_public::COMMAND_RPC_STORE::response, epee::json_rpc::error> 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<plain_wallet::open_wallet_response, epee::json_rpc::dummy_error> 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<tools::wallet_public::COMMAND_RPC_GET_WALLET_INFO::request> gbreq = AUTO_VAL_INIT(gbreq);
|
||||
// gbreq.method = "get_wallet_info";
|
||||
// epee::json_rpc::response<tools::wallet_public::COMMAND_RPC_GET_WALLET_INFO::response, epee::json_rpc::error> 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<tools::wallet_public::COMMAND_RPC_GET_BALANCE::request> gbreq = AUTO_VAL_INIT(gbreq);
|
||||
// gbreq.method = "getbalance";
|
||||
// epee::json_rpc::response<tools::wallet_public::COMMAND_RPC_GET_BALANCE::response, epee::json_rpc::error> 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<tools::wallet_public::COMMAND_RPC_STORE::request> gbreq = AUTO_VAL_INIT(gbreq);
|
||||
// gbreq.method = "store";
|
||||
// epee::json_rpc::response<tools::wallet_public::COMMAND_RPC_STORE::response, epee::json_rpc::error> 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);
|
||||
// }
|
||||
// }}
|
||||
9
tests/functional_tests/plain_wallet_tests.h
Normal file
9
tests/functional_tests/plain_wallet_tests.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// 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.
|
||||
|
||||
|
||||
|
||||
void run_plain_wallet_api_test();
|
||||
|
||||
|
||||
|
|
@ -117,6 +117,9 @@ fi
|
|||
|
||||
echo "Build success"
|
||||
|
||||
if [ -z "$upload_build" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Uploading..."
|
||||
|
||||
|
|
|
|||
96
utils/docker/Dockerfile
Normal file
96
utils/docker/Dockerfile
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
###########################################################################################
|
||||
## zanod Dockerfile
|
||||
###########################################################################################
|
||||
|
||||
#
|
||||
# Usage:
|
||||
# (make sure you have correct permission for /var/data/zano-data prior to run!)
|
||||
#
|
||||
# docker run --restart=always -v /var/data/zano-data:/home/zano/.Zano -p 11121:11121 -p 11211:11211 --name=zanod -dit sowle/zano-full-node
|
||||
#
|
||||
# To get into container and interact with the daemon:
|
||||
# docker attach zanod
|
||||
#
|
||||
# To detach from container and left it running:
|
||||
# Ctrl+P, Ctrl+Q
|
||||
#
|
||||
# To stop container:
|
||||
# docker stop zanod
|
||||
#
|
||||
|
||||
#
|
||||
# Build Zano
|
||||
#
|
||||
|
||||
FROM ubuntu:18.04 as zano-build
|
||||
|
||||
RUN apt update && \
|
||||
apt install -y build-essential \
|
||||
libicu-dev \
|
||||
curl \
|
||||
g++ \
|
||||
git
|
||||
|
||||
|
||||
WORKDIR /root
|
||||
|
||||
# CMake 3.15.5
|
||||
|
||||
RUN curl https://github.com/Kitware/CMake/releases/download/v3.15.5/cmake-3.15.5-Linux-x86_64.sh -OL &&\
|
||||
echo '62e3e7d134a257e13521e306a9d3d1181ab99af8fcae66699c8f98754fc02dda cmake-3.15.5-Linux-x86_64.sh' | sha256sum -c - &&\
|
||||
mkdir /opt/cmake &&\
|
||||
sh cmake-3.15.5-Linux-x86_64.sh --prefix=/opt/cmake --skip-license &&\
|
||||
ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake &&\
|
||||
cmake --version &&\
|
||||
rm cmake-3.15.5-Linux-x86_64.sh
|
||||
|
||||
# Boost 1.68
|
||||
|
||||
RUN curl https://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.tar.bz2 -OL &&\
|
||||
echo '7f6130bc3cf65f56a618888ce9d5ea704fa10b462be126ad053e80e553d6d8b7 boost_1_68_0.tar.bz2' | sha256sum -c - &&\
|
||||
tar -xjf boost_1_68_0.tar.bz2 &&\
|
||||
rm boost_1_68_0.tar.bz2 &&\
|
||||
cd boost_1_68_0 &&\
|
||||
./bootstrap.sh --with-libraries=system,filesystem,thread,date_time,chrono,regex,serialization,atomic,program_options,locale,timer &&\
|
||||
./b2 &&\
|
||||
cd ..
|
||||
|
||||
ENV BOOST_ROOT=/root/boost_1_68_0
|
||||
|
||||
# Zano
|
||||
|
||||
RUN pwd && mem_avail_gb=$(( $(getconf _AVPHYS_PAGES) * $(getconf PAGE_SIZE) / (1024 * 1024 * 1024) )) &&\
|
||||
make_job_slots=$(( $mem_avail_gb < 4 ? 1 : $mem_avail_gb / 4)) &&\
|
||||
echo make_job_slots=$make_job_slots &&\
|
||||
set -x &&\
|
||||
git clone --single-branch https://github.com/hyle-team/zano.git &&\
|
||||
cd zano &&\
|
||||
git submodule update --init --recursive &&\
|
||||
mkdir build && cd build &&\
|
||||
cmake -D STATIC=TRUE .. &&\
|
||||
make -j $make_job_slots daemon simplewallet
|
||||
|
||||
|
||||
#
|
||||
# Run Zano
|
||||
#
|
||||
|
||||
FROM ubuntu:18.04
|
||||
|
||||
RUN useradd -ms /bin/bash zano &&\
|
||||
mkdir -p /home/zano/.Zano &&\
|
||||
chown -R zano:zano /home/zano/.Zano
|
||||
|
||||
USER zano:zano
|
||||
|
||||
WORKDIR /home/zano
|
||||
COPY --chown=zano:zano --from=zano-build /root/zano/build/src/zanod .
|
||||
COPY --chown=zano:zano --from=zano-build /root/zano/build/src/simplewallet .
|
||||
|
||||
# blockchain loaction
|
||||
VOLUME /home/zano/.Zano
|
||||
|
||||
EXPOSE 11121 11211
|
||||
|
||||
ENTRYPOINT ["./zanod"]
|
||||
CMD ["--disable-upnp", "--rpc-bind-ip=0.0.0.0", "--log-level=0"]
|
||||
125
utils/snap/snapcraft.yaml
Normal file
125
utils/snap/snapcraft.yaml
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
name: zano # you probably want to 'snapcraft register <name>'
|
||||
base: core18 # the base snap is the execution environment for this snap
|
||||
version: '1.1.5' # just for humans, typically '1.2+git' or '1.3.2'
|
||||
summary: "Zano coin: official wallet. Secure. Scalable. Easy to Use."
|
||||
description: |
|
||||
Zano is a scalable and secure coin, designed for use in e-commerce.
|
||||
The technology behind our blockchain provides reliability, security,
|
||||
and flexibility — a perfect option for P2P transactions.
|
||||
More info: http://zano.org
|
||||
grade: devel # must be 'stable' to release into candidate/stable channels
|
||||
confinement: devmode # use 'strict' once you have the right plugs and slots
|
||||
|
||||
parts:
|
||||
libboost:
|
||||
plugin: dump
|
||||
source: .
|
||||
|
||||
override-pull: |
|
||||
curl https://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.tar.bz2 -OL &&\
|
||||
echo '7f6130bc3cf65f56a618888ce9d5ea704fa10b462be126ad053e80e553d6d8b7 boost_1_68_0.tar.bz2' | sha256sum -c - &&\
|
||||
pwd && echo pulled ok
|
||||
|
||||
override-build: |
|
||||
tar -xjf $SNAPCRAFT_PART_SRC/boost_1_68_0.tar.bz2
|
||||
cd boost_1_68_0
|
||||
pwd
|
||||
./bootstrap.sh --with-libraries=system,filesystem,thread,date_time,chrono,regex,serialization,atomic,program_options,locale,timer
|
||||
./b2
|
||||
mkdir -p $SNAPCRAFT_PART_INSTALL/boost_1_68_0 $SNAPCRAFT_PART_INSTALL/boost_1_68_0/stage
|
||||
cp -pr boost $SNAPCRAFT_PART_INSTALL/boost_1_68_0/
|
||||
cp -pr stage/lib $SNAPCRAFT_PART_INSTALL/boost_1_68_0/stage/
|
||||
|
||||
build-packages:
|
||||
- curl
|
||||
- build-essential
|
||||
- g++
|
||||
- libicu-dev
|
||||
|
||||
stage-packages:
|
||||
- libicu60
|
||||
|
||||
qt:
|
||||
plugin: dump
|
||||
source: .
|
||||
override-pull: |
|
||||
curl https://download.qt.io/archive/qt/5.13/5.13.2/single/qt-everywhere-src-5.13.2.tar.xz -OL &&\
|
||||
echo '55e8273536be41f4f63064a79e552a22133848bb419400b6fa8e9fc0dc05de08 qt-everywhere-src-5.13.2.tar.xz' | sha256sum -c - &&\
|
||||
pwd && echo pulled ok
|
||||
|
||||
override-build: |
|
||||
tar -xJf $SNAPCRAFT_PART_SRC/qt-everywhere-src-5.13.2.tar.xz
|
||||
cd qt-everywhere-src-5.13.2
|
||||
pwd
|
||||
./configure -platform linux-g++ -prefix $SNAPCRAFT_PART_INSTALL/qt5132 -opensource -confirm-license -xcb -nomake examples -nomake tests -feature-webengine-embedded-build -feature-webengine-pepper-plugins -feature-webengine-printing-and-pdf -feature-webengine-proprietary-codecs -feature-webengine-spellchecker -feature-webengine-v8-snapshot -feature-webengine-webrtc -feature-thread -xkbcommon -no-feature-d3d12 -no-feature-qt3d-animation -no-feature-qt3d-extras -no-feature-qt3d-input -no-feature-qt3d-logic -no-feature-qt3d-opengl-renderer -no-feature-qt3d-render -no-feature-qt3d-simd-avx2 -no-feature-qt3d-simd-sse2 -no-feature-gestures
|
||||
make
|
||||
make install
|
||||
echo Qt was successfully built
|
||||
|
||||
build-packages:
|
||||
- g++
|
||||
- libicu-dev
|
||||
- bison
|
||||
- build-essential
|
||||
- flex
|
||||
- gperf
|
||||
- gyp
|
||||
- libasound2-dev
|
||||
- libavcodec-dev
|
||||
- libavformat-dev
|
||||
- libavutil-dev
|
||||
- libbz2-dev
|
||||
- libcap-dev
|
||||
- libcups2-dev
|
||||
- libdrm-dev
|
||||
- libegl1-mesa-dev
|
||||
- libevent-dev
|
||||
- libfontconfig1-dev
|
||||
- libgcrypt11-dev
|
||||
- libjsoncpp-dev
|
||||
- libminizip-dev
|
||||
- libnss3-dev
|
||||
- libopus-dev
|
||||
- libpci-dev
|
||||
- libpulse-dev
|
||||
- libsrtp0-dev
|
||||
- libssl-dev
|
||||
- libudev-dev
|
||||
- libwebp-dev
|
||||
- libxcb1
|
||||
- libxcb1-dev
|
||||
- libxcomposite-dev
|
||||
- libxcursor-dev
|
||||
- libxdamage-dev
|
||||
- libxkbcommon-dev
|
||||
- libxrandr-dev
|
||||
- libxss-dev
|
||||
- libxtst-dev
|
||||
- ninja-build
|
||||
- python
|
||||
- ruby
|
||||
|
||||
zano-bin:
|
||||
after: [ libboost, qt ]
|
||||
source: https://github.com/hyle-team/zano.git
|
||||
plugin: cmake
|
||||
|
||||
override-build: |
|
||||
cmake -DCMAKE_PREFIX_PATH=$SNAPCRAFT_PART_INSTALL/qt5132 -DBOOST_ROOT=$SNAPCRAFT_STAGE/boost_1_68_0 -DBOOST_LIBRARYDIR=$SNAPCRAFT_STAGE/boost_1_68_0/stage/lib -DSTATIC=True -DBUILD_GUI=True $SNAPCRAFT_PART_SRC
|
||||
make -j1 Zano
|
||||
#daemon simplewallet
|
||||
# cp src/zanod $SNAPCRAFT_PART_INSTALL
|
||||
# cp src/simplewallet $SNAPCRAFT_PART_INSTALL
|
||||
pwd
|
||||
echo CLI Zano binaries built
|
||||
|
||||
|
||||
build-packages:
|
||||
- build-essential
|
||||
- g++
|
||||
- libicu-dev
|
||||
|
||||
|
||||
apps:
|
||||
zano:
|
||||
command: pwd
|
||||
Loading…
Add table
Reference in a new issue