aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt8
-rw-r--r--README.md78
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.h6
-rw-r--r--[-rwxr-xr-x]contrib/epee/include/net/http_base.h0
-rw-r--r--[-rwxr-xr-x]contrib/epee/include/net/http_client.h2
-rw-r--r--[-rwxr-xr-x]contrib/epee/include/net/http_protocol_handler.h0
-rw-r--r--[-rwxr-xr-x]contrib/epee/include/net/http_protocol_handler.inl0
-rw-r--r--[-rwxr-xr-x]contrib/epee/include/net/http_server_handlers_map2.h0
-rw-r--r--[-rwxr-xr-x]contrib/epee/include/net/http_server_impl_base.h5
-rw-r--r--contrib/epee/include/storages/portable_storage_to_bin.h3
-rw-r--r--contrib/epee/src/CMakeLists.txt17
-rw-r--r--external/miniupnpc/CMakeLists.txt3
-rw-r--r--external/unbound/CMakeLists.txt14
-rw-r--r--external/unbound/configure_checks.cmake5
-rw-r--r--src/blockchain_db/blockchain_db.cpp2
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp7
-rw-r--r--src/blockchain_utilities/blockchain_export.cpp16
-rw-r--r--src/blockchain_utilities/blockchain_import.cpp11
-rw-r--r--src/blockchain_utilities/bootstrap_file.cpp6
-rw-r--r--src/blockchain_utilities/bootstrap_file.h2
-rw-r--r--src/checkpoints/checkpoints.cpp2
-rw-r--r--src/common/command_line.cpp63
-rw-r--r--src/common/command_line.h15
-rw-r--r--src/common/int-util.h4
-rw-r--r--src/common/password.cpp11
-rw-r--r--src/common/password.h2
-rw-r--r--src/common/threadpool.cpp4
-rw-r--r--src/common/updates.cpp2
-rw-r--r--src/common/util.cpp2
-rw-r--r--src/crypto/initializer.h5
-rw-r--r--src/cryptonote_basic/cryptonote_format_utils.cpp2
-rw-r--r--src/cryptonote_core/blockchain.cpp2
-rw-r--r--src/cryptonote_core/blockchain.h10
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp119
-rw-r--r--src/cryptonote_core/cryptonote_core.h5
-rw-r--r--src/cryptonote_core/cryptonote_tx_utils.cpp2
-rw-r--r--src/cryptonote_core/tx_pool.cpp2
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.inl4
-rw-r--r--src/daemon/CMakeLists.txt3
-rw-r--r--src/daemon/daemon.cpp2
-rw-r--r--src/daemon/main.cpp14
-rw-r--r--src/daemon/rpc_command_executor.cpp2
-rw-r--r--src/p2p/connection_basic.cpp4
-rw-r--r--src/p2p/net_node.inl5
-rw-r--r--src/ringct/rctOps.h11
-rw-r--r--src/ringct/rctSigs.h14
-rw-r--r--src/ringct/rctTypes.h19
-rw-r--r--[-rwxr-xr-x]src/rpc/core_rpc_server.cpp192
-rw-r--r--src/rpc/core_rpc_server_commands_defs.h6
-rw-r--r--[-rwxr-xr-x]src/rpc/rpc_args.cpp4
-rw-r--r--[-rwxr-xr-x]src/rpc/rpc_args.h0
-rw-r--r--src/simplewallet/CMakeLists.txt4
-rw-r--r--src/simplewallet/simplewallet.cpp593
-rw-r--r--src/wallet/CMakeLists.txt63
-rw-r--r--src/wallet/wallet2.cpp216
-rw-r--r--src/wallet/wallet2.h21
-rw-r--r--src/wallet/wallet_args.cpp33
-rw-r--r--src/wallet/wallet_args.h1
-rw-r--r--src/wallet/wallet_errors.h6
-rw-r--r--[-rwxr-xr-x]src/wallet/wallet_rpc_server.cpp48
-rw-r--r--tests/core_proxy/core_proxy.cpp8
-rw-r--r--tests/core_tests/chaingen.cpp1
-rw-r--r--tests/fuzz/block.cpp1
-rw-r--r--tests/fuzz/cold-transaction.cpp1
-rw-r--r--tests/fuzz/signature.cpp1
-rw-r--r--tests/fuzz/transaction.cpp1
-rw-r--r--tests/performance_tests/performance_utils.h4
-rw-r--r--tests/unit_tests/main.cpp2
-rw-r--r--tests/unit_tests/output_selection.cpp4
-rw-r--r--tests/unit_tests/ringct.cpp1
-rw-r--r--tests/unit_tests/serialization.cpp1
71 files changed, 805 insertions, 922 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 637e9c4e6..357719ffd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -331,6 +331,10 @@ if (UNIX AND NOT APPLE)
endif()
# Handle OpenSSL, used for sha256sum on binary updates and light wallet ssl http
+if (CMAKE_SYSTEM_NAME MATCHES "(SunOS|Solaris)")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthreads")
+endif ()
+
if (APPLE AND NOT IOS)
if (NOT OpenSSL_DIR)
EXECUTE_PROCESS(COMMAND brew --prefix openssl
@@ -675,6 +679,8 @@ elseif(FREEBSD)
elseif(DRAGONFLY)
find_library(COMPAT compat)
set(EXTRA_LIBRARIES execinfo ${COMPAT})
+elseif(CMAKE_SYSTEM_NAME MATCHES "(SunOS|Solaris)")
+ set(EXTRA_LIBRARIES socket nsl resolv)
elseif(NOT MSVC)
find_library(RT rt)
set(EXTRA_LIBRARIES ${RT})
@@ -688,8 +694,8 @@ if(USE_READLINE)
if(READLINE_FOUND AND GNU_READLINE_FOUND)
add_definitions(-DHAVE_READLINE)
include_directories(${Readline_INCLUDE_DIR})
- list(APPEND EXTRA_LIBRARIES ${Readline_LIBRARY})
message(STATUS "Found readline library at: ${Readline_ROOT_DIR}")
+ set(EPEE_READLINE epee_readline)
else()
message(STATUS "Could not find GNU readline library so building without readline support")
endif()
diff --git a/README.md b/README.md
index db72bd079..2dec65465 100644
--- a/README.md
+++ b/README.md
@@ -350,6 +350,8 @@ We expect to add Monero into the ports tree in the near future, which will aid i
### On OpenBSD:
+#### OpenBSD < 6.2
+
This has been tested on OpenBSD 5.8.
You will need to add a few packages to your system. `pkg_add db cmake gcc gcc-libs g++ miniupnpc gtest`.
@@ -363,6 +365,82 @@ You will have to add the serialization, date_time, and regex modules to Boost wh
To build: `env CC=egcc CXX=eg++ CPP=ecpp DEVELOPER_LOCAL_TOOLS=1 BOOST_ROOT=/path/to/the/boost/you/built make release-static-64`
+#### OpenBSD >= 6.2
+
+You will need to add a few packages to your system. Choose version 4 for db. `pkg_add db cmake miniupnpc zeromq`.
+
+The doxygen and graphviz packages are optional and require the xbase set.
+
+
+Build the Boost library using clang. This guide is derived from: https://github.com/bitcoin/bitcoin/blob/master/doc/build-openbsd.md
+
+We assume you are compiling with a non-root user and you have `doas` enabled.
+
+Note: do not use the boost package provided by OpenBSD, as we are installing boost to `/usr/local`.
+
+```
+# Create boost building directory
+mkdir ~/boost
+cd ~/boost
+
+# Fetch boost source
+ftp -o boost_1_64_0.tar.bz2 https://netcologne.dl.sourceforge.net/project/boost/boost/1.64.0/boost_1_64_0.tar.bz2
+
+# MUST output: (SHA256) boost_1_64_0.tar.bz2: OK
+echo "7bcc5caace97baa948931d712ea5f37038dbb1c5d89b43ad4def4ed7cb683332 boost_1_64_0.tar.bz2" | sha256 -c
+tar xfj boost_1_64_0.tar.bz2
+
+# Fetch a boost patch, required for OpenBSD
+ftp -o boost.patch https://raw.githubusercontent.com/openbsd/ports/bee9e6df517077a7269ff0dfd57995f5c6a10379/devel/boost/patches/patch-boost_test_impl_execution_monitor_ipp
+cd boost_1_64_0
+patch -p0 < ../boost.patch
+
+# Start building boost
+echo 'using clang : : c++ : <cxxflags>"-fvisibility=hidden -fPIC" <linkflags>"" <archiver>"ar" <striper>"strip" <ranlib>"ranlib" <rc>"" : ;' > user-config.jam
+./bootstrap.sh --without-icu --with-libraries=chrono,filesystem,program_options,system,thread,test,date_time,regex,serialization --with-toolset=clang
+./b2 toolset=clang cxxflags="-stdlib=libc++" linkflags="-stdlib=libc++"
+doas ./b2 -d0 runtime-link=shared threadapi=pthread threading=multi link=static variant=release --layout=tagged --build-type=complete --user-config=user-config.jam -sNO_BZIP2=1 --prefix=/usr/local install
+```
+
+Build cppzmq
+
+Build the cppzmq bindings.
+
+We assume you are compiling with a non-root user and you have `doas` enabled.
+
+```
+# Create cppzmq building directory
+mkdir ~/cppzmq
+cd ~/cppzmq
+
+# Fetch cppzmq source
+ftp -o cppzmq-4.2.2.tar.gz https://github.com/zeromq/cppzmq/archive/v4.2.2.tar.gz
+
+# MUST output: (SHA256) cppzmq-4.2.2.tar.gz: OK
+echo "3ef50070ac5877c06c6bb25091028465020e181bbfd08f110294ed6bc419737d cppzmq-4.2.2.tar.gz" | sha256 -c
+tar xfz cppzmq-4.2.2.tar.gz
+
+# Start building cppzmq
+cd cppzmq-4.2.2
+mkdir build
+cd build
+cmake ..
+doas make install
+```
+
+Build monero: `env DEVELOPER_LOCAL_TOOLS=1 BOOST_ROOT=/usr/local make release-static`
+
+### On Solaris:
+
+The default Solaris linker can't be used, you have to install GNU ld, then run cmake manually with the path to your copy of GNU ld:
+
+ mkdir -p build/release
+ cd build/release
+ cmake -DCMAKE_LINKER=/path/to/ld -D CMAKE_BUILD_TYPE=Release ../..
+ cd ../..
+
+Then you can run make as usual.
+
### On Linux for Android (using docker):
# Build image (select android64.Dockerfile for aarch64)
diff --git a/contrib/epee/include/net/abstract_tcp_server2.h b/contrib/epee/include/net/abstract_tcp_server2.h
index 03f143fe4..33fec8ec5 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.h
+++ b/contrib/epee/include/net/abstract_tcp_server2.h
@@ -213,6 +213,12 @@ namespace net_utils
int get_binded_port(){return m_port;}
+ long get_connections_count() const
+ {
+ auto connections_count = (m_sock_count > 0) ? (m_sock_count - 1) : 0; // Socket count minus listening socket
+ return connections_count;
+ }
+
boost::asio::io_service& get_io_service(){return io_service_;}
struct idle_callback_conext_base
diff --git a/contrib/epee/include/net/http_base.h b/contrib/epee/include/net/http_base.h
index a66fb7c23..a66fb7c23 100755..100644
--- a/contrib/epee/include/net/http_base.h
+++ b/contrib/epee/include/net/http_base.h
diff --git a/contrib/epee/include/net/http_client.h b/contrib/epee/include/net/http_client.h
index 80a4504e3..d77c84c28 100755..100644
--- a/contrib/epee/include/net/http_client.h
+++ b/contrib/epee/include/net/http_client.h
@@ -66,8 +66,6 @@ namespace epee
namespace net_utils
{
-using namespace std;
-
/*struct url
{
public:
diff --git a/contrib/epee/include/net/http_protocol_handler.h b/contrib/epee/include/net/http_protocol_handler.h
index 652d8ff6f..652d8ff6f 100755..100644
--- a/contrib/epee/include/net/http_protocol_handler.h
+++ b/contrib/epee/include/net/http_protocol_handler.h
diff --git a/contrib/epee/include/net/http_protocol_handler.inl b/contrib/epee/include/net/http_protocol_handler.inl
index c3350bf73..c3350bf73 100755..100644
--- a/contrib/epee/include/net/http_protocol_handler.inl
+++ b/contrib/epee/include/net/http_protocol_handler.inl
diff --git a/contrib/epee/include/net/http_server_handlers_map2.h b/contrib/epee/include/net/http_server_handlers_map2.h
index 429e3e1af..429e3e1af 100755..100644
--- a/contrib/epee/include/net/http_server_handlers_map2.h
+++ b/contrib/epee/include/net/http_server_handlers_map2.h
diff --git a/contrib/epee/include/net/http_server_impl_base.h b/contrib/epee/include/net/http_server_impl_base.h
index 0788c6a4b..8b8e31b51 100755..100644
--- a/contrib/epee/include/net/http_server_impl_base.h
+++ b/contrib/epee/include/net/http_server_impl_base.h
@@ -117,6 +117,11 @@ namespace epee
return m_net_server.get_binded_port();
}
+ long get_connections_count() const
+ {
+ return m_net_server.get_connections_count();
+ }
+
protected:
net_utils::boosted_tcp_server<net_utils::http::http_custom_handler<t_connection_context> > m_net_server;
};
diff --git a/contrib/epee/include/storages/portable_storage_to_bin.h b/contrib/epee/include/storages/portable_storage_to_bin.h
index 5695143b0..38e9f9098 100644
--- a/contrib/epee/include/storages/portable_storage_to_bin.h
+++ b/contrib/epee/include/storages/portable_storage_to_bin.h
@@ -47,6 +47,9 @@ namespace epee
PRAGMA_WARNING_PUSH
PRAGMA_GCC("GCC diagnostic ignored \"-Wstrict-aliasing\"")
+#ifdef __clang__
+ PRAGMA_GCC("GCC diagnostic ignored \"-Wtautological-constant-out-of-range-compare\"")
+#endif
template<class t_stream>
size_t pack_varint(t_stream& strm, size_t val)
{ //the first two bits always reserved for size information
diff --git a/contrib/epee/src/CMakeLists.txt b/contrib/epee/src/CMakeLists.txt
index 3b41f415e..bd6714791 100644
--- a/contrib/epee/src/CMakeLists.txt
+++ b/contrib/epee/src/CMakeLists.txt
@@ -26,10 +26,9 @@
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+add_library(epee STATIC hex.cpp http_auth.cpp mlog.cpp net_utils_base.cpp string_tools.cpp)
if (USE_READLINE AND GNU_READLINE_FOUND)
- add_library(epee STATIC hex.cpp http_auth.cpp mlog.cpp net_utils_base.cpp string_tools.cpp readline_buffer.cpp)
-else()
- add_library(epee STATIC hex.cpp http_auth.cpp mlog.cpp net_utils_base.cpp string_tools.cpp)
+ add_library(epee_readline STATIC readline_buffer.cpp)
endif()
# Build and install libepee if we're building for GUI
@@ -41,6 +40,10 @@ if (BUILD_GUI_DEPS)
endif()
install(TARGETS epee
ARCHIVE DESTINATION ${lib_folder})
+ if (USE_READLINE AND GNU_READLINE_FOUND)
+ install(TARGETS epee_readline
+ ARCHIVE DESTINATION ${lib_folder})
+ endif()
endif()
target_link_libraries(epee
@@ -51,3 +54,11 @@ target_link_libraries(epee
PRIVATE
${OPENSSL_LIBRARIES}
${EXTRA_LIBRARIES})
+
+if (USE_READLINE AND GNU_READLINE_FOUND)
+ target_link_libraries(epee_readline
+ PUBLIC
+ easylogging
+ PRIVATE
+ ${Readline_LIBRARY})
+endif()
diff --git a/external/miniupnpc/CMakeLists.txt b/external/miniupnpc/CMakeLists.txt
index 4c01b6d06..bc9685699 100644
--- a/external/miniupnpc/CMakeLists.txt
+++ b/external/miniupnpc/CMakeLists.txt
@@ -36,6 +36,9 @@ if (NOT WIN32)
# add_definitions (-D_POSIX_C_SOURCE=200112L)
add_definitions (-D_XOPEN_SOURCE=600)
endif (NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" AND NOT CMAKE_SYSTEM_NAME STREQUAL "DragonFly")
+ if (CMAKE_SYSTEM_NAME MATCHES "(SunOS|Solaris)")
+ add_definitions (-D__EXTENSIONS__ -std=c99)
+ endif ()
else (NOT WIN32)
add_definitions (-D_WIN32_WINNT=0x0501) # XP or higher for getnameinfo and friends
endif (NOT WIN32)
diff --git a/external/unbound/CMakeLists.txt b/external/unbound/CMakeLists.txt
index 3dae8b425..a2e475232 100644
--- a/external/unbound/CMakeLists.txt
+++ b/external/unbound/CMakeLists.txt
@@ -44,7 +44,12 @@ endif ()
set(RETSIGTYPE void)
+if(CMAKE_SYSTEM_NAME MATCHES "(SunOS|Solaris)")
+add_definitions(-D_XOPEN_SOURCE=600)
+else()
add_definitions(-D_GNU_SOURCE)
+endif()
+add_definitions(-std=c99)
option(USE_ECDSA "Use ECDSA algorithms" ON)
option(USE_SHA2 "Enable SHA2 support" ON)
@@ -60,6 +65,15 @@ if (CMAKE_USE_WIN32_THREADS_INIT)
else ()
set(HAVE_WINDOWS_THREADS 0)
endif ()
+
+# determine if we have libressl
+check_symbol_exists(LIBRESSL_VERSION_TEXT "openssl/opensslv.h" HAVE_LIBRESSL)
+# check if we have found HAVE_DECL_REALLOCARRAY already, so we can safely undefine and redefine it with value 1
+if (HAVE_LIBRESSL AND HAVE_DECL_REALLOCARRAY)
+ unset(HAVE_DECL_REALLOCARRAY CACHE)
+ add_definitions(-DHAVE_DECL_REALLOCARRAY=1)
+endif ()
+
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/config.h")
diff --git a/external/unbound/configure_checks.cmake b/external/unbound/configure_checks.cmake
index 258f28138..2acf556d1 100644
--- a/external/unbound/configure_checks.cmake
+++ b/external/unbound/configure_checks.cmake
@@ -49,6 +49,11 @@ if (WIN32)
iphlpapi
ws2_32)
endif ()
+if (CMAKE_SYSTEM_NAME MATCHES "(SunOS|Solaris)")
+ set(CMAKE_REQUIRED_LIBRARIES
+ socket
+ nsl)
+endif ()
check_function_exists(_beginthreadex HAVE__BEGINTHREADEX)
check_function_exists(arc4random HAVE_ARC4RANDOM)
diff --git a/src/blockchain_db/blockchain_db.cpp b/src/blockchain_db/blockchain_db.cpp
index d62a250ff..c3f6e3d87 100644
--- a/src/blockchain_db/blockchain_db.cpp
+++ b/src/blockchain_db/blockchain_db.cpp
@@ -208,7 +208,7 @@ uint64_t BlockchainDB::add_block( const block& blk
time1 = epee::misc_utils::get_tick_count();
add_transaction(blk_hash, blk.miner_tx);
int tx_i = 0;
- crypto::hash tx_hash = null_hash;
+ crypto::hash tx_hash = crypto::null_hash;
for (const transaction& tx : txs)
{
tx_hash = blk.tx_hashes[tx_i];
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index 6ebb35639..865558e07 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -34,6 +34,7 @@
#include <cstring> // memcpy
#include <random>
+#include "common/util.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "crypto/crypto.h"
#include "profile_tools.h"
@@ -48,6 +49,7 @@
#endif
using epee::string_tools::pod_to_hex;
+using namespace crypto;
// Increase when the DB changes in a non backward compatible way, and there
// is no automatic conversion, so that a full resync is needed.
@@ -1135,6 +1137,11 @@ void BlockchainLMDB::open(const std::string& filename, const int db_flags)
if ((result = mdb_env_set_maxdbs(m_env, 20)))
throw0(DB_ERROR(lmdb_error("Failed to set max number of dbs: ", result).c_str()));
+ int threads = tools::get_max_concurrency();
+ if (threads > 110 && /* maxreaders default is 126, leave some slots for other read processes */
+ (result = mdb_env_set_maxreaders(m_env, threads+16)))
+ throw0(DB_ERROR(lmdb_error("Failed to set max number of readers: ", result).c_str()));
+
size_t mapsize = DEFAULT_MAPSIZE;
if (db_flags & DBF_FAST)
diff --git a/src/blockchain_utilities/blockchain_export.cpp b/src/blockchain_utilities/blockchain_export.cpp
index 60672eeda..78bb51ab6 100644
--- a/src/blockchain_utilities/blockchain_export.cpp
+++ b/src/blockchain_utilities/blockchain_export.cpp
@@ -30,6 +30,7 @@
#include "blocksdat_file.h"
#include "common/command_line.h"
#include "cryptonote_core/tx_pool.h"
+#include "cryptonote_core/cryptonote_core.h"
#include "blockchain_db/blockchain_db.h"
#include "blockchain_db/db_types.h"
#include "version.h"
@@ -66,21 +67,16 @@ int main(int argc, char* argv[])
const command_line::arg_descriptor<std::string> arg_output_file = {"output-file", "Specify output file", "", true};
const command_line::arg_descriptor<std::string> arg_log_level = {"log-level", "0-4 or categories", ""};
const command_line::arg_descriptor<uint64_t> arg_block_stop = {"block-stop", "Stop at block number", block_stop};
- const command_line::arg_descriptor<bool> arg_testnet_on = {
- "testnet"
- , "Run on testnet."
- , false
- };
const command_line::arg_descriptor<std::string> arg_database = {
"database", available_dbs.c_str(), default_db_type
};
const command_line::arg_descriptor<bool> arg_blocks_dat = {"blocksdat", "Output in blocks.dat format", blocks_dat};
- command_line::add_arg(desc_cmd_sett, command_line::arg_data_dir, default_data_path.string());
- command_line::add_arg(desc_cmd_sett, command_line::arg_testnet_data_dir, default_testnet_data_path.string());
+ command_line::add_arg(desc_cmd_sett, cryptonote::arg_data_dir, default_data_path.string());
+ command_line::add_arg(desc_cmd_sett, cryptonote::arg_testnet_data_dir, default_testnet_data_path.string());
command_line::add_arg(desc_cmd_sett, arg_output_file);
- command_line::add_arg(desc_cmd_sett, arg_testnet_on);
+ command_line::add_arg(desc_cmd_sett, cryptonote::arg_testnet_on);
command_line::add_arg(desc_cmd_sett, arg_log_level);
command_line::add_arg(desc_cmd_sett, arg_database);
command_line::add_arg(desc_cmd_sett, arg_block_stop);
@@ -117,12 +113,12 @@ int main(int argc, char* argv[])
LOG_PRINT_L0("Starting...");
- bool opt_testnet = command_line::get_arg(vm, arg_testnet_on);
+ bool opt_testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on);
bool opt_blocks_dat = command_line::get_arg(vm, arg_blocks_dat);
std::string m_config_folder;
- auto data_dir_arg = opt_testnet ? command_line::arg_testnet_data_dir : command_line::arg_data_dir;
+ auto data_dir_arg = opt_testnet ? cryptonote::arg_testnet_data_dir : cryptonote::arg_data_dir;
m_config_folder = command_line::get_arg(vm, data_dir_arg);
std::string db_type = command_line::get_arg(vm, arg_database);
diff --git a/src/blockchain_utilities/blockchain_import.cpp b/src/blockchain_utilities/blockchain_import.cpp
index 2a956dbdb..a50b0bad6 100644
--- a/src/blockchain_utilities/blockchain_import.cpp
+++ b/src/blockchain_utilities/blockchain_import.cpp
@@ -256,7 +256,7 @@ int import_from_file(cryptonote::core& core, const std::string& import_file_path
seek_height = start_height;
BootstrapFile bootstrap;
- streampos pos;
+ std::streampos pos;
// BootstrapFile bootstrap(import_file_path);
uint64_t total_source_blocks = bootstrap.count_blocks(import_file_path, pos, seek_height);
MINFO("bootstrap file last block number: " << total_source_blocks-1 << " (zero-based height) total blocks: " << total_source_blocks);
@@ -585,11 +585,6 @@ int main(int argc, char* argv[])
const command_line::arg_descriptor<uint64_t> arg_batch_size = {"batch-size", "", db_batch_size};
const command_line::arg_descriptor<uint64_t> arg_pop_blocks = {"pop-blocks", "Remove blocks from end of blockchain", num_blocks};
const command_line::arg_descriptor<bool> arg_drop_hf = {"drop-hard-fork", "Drop hard fork subdbs", false};
- const command_line::arg_descriptor<bool> arg_testnet_on = {
- "testnet"
- , "Run on testnet."
- , false
- };
const command_line::arg_descriptor<bool> arg_count_blocks = {
"count-blocks"
, "Count blocks in bootstrap file and exit"
@@ -674,8 +669,8 @@ int main(int argc, char* argv[])
}
}
- opt_testnet = command_line::get_arg(vm, arg_testnet_on);
- auto data_dir_arg = opt_testnet ? command_line::arg_testnet_data_dir : command_line::arg_data_dir;
+ opt_testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on);
+ auto data_dir_arg = opt_testnet ? cryptonote::arg_testnet_data_dir : cryptonote::arg_data_dir;
m_config_folder = command_line::get_arg(vm, data_dir_arg);
db_arg_str = command_line::get_arg(vm, arg_database);
diff --git a/src/blockchain_utilities/bootstrap_file.cpp b/src/blockchain_utilities/bootstrap_file.cpp
index a004d3547..2c993460a 100644
--- a/src/blockchain_utilities/bootstrap_file.cpp
+++ b/src/blockchain_utilities/bootstrap_file.cpp
@@ -221,7 +221,7 @@ void BootstrapFile::write_block(block& block)
// now add all regular transactions
for (const auto& tx_id : block.tx_hashes)
{
- if (tx_id == null_hash)
+ if (tx_id == crypto::null_hash)
{
throw std::runtime_error("Aborting: tx == null_hash");
}
@@ -433,7 +433,7 @@ uint64_t BootstrapFile::count_bytes(std::ifstream& import_file, uint64_t blocks,
uint64_t BootstrapFile::count_blocks(const std::string& import_file_path)
{
- streampos dummy_pos;
+ std::streampos dummy_pos;
uint64_t dummy_height = 0;
return count_blocks(import_file_path, dummy_pos, dummy_height);
}
@@ -441,7 +441,7 @@ uint64_t BootstrapFile::count_blocks(const std::string& import_file_path)
// If seek_height is non-zero on entry, return a stream position <= this height when finished.
// And return the actual height corresponding to this position. Allows the caller to locate its
// starting position without having to reread the entire file again.
-uint64_t BootstrapFile::count_blocks(const std::string& import_file_path, streampos &start_pos, uint64_t& seek_height)
+uint64_t BootstrapFile::count_blocks(const std::string& import_file_path, std::streampos &start_pos, uint64_t& seek_height)
{
boost::filesystem::path raw_file_path(import_file_path);
boost::system::error_code ec;
diff --git a/src/blockchain_utilities/bootstrap_file.h b/src/blockchain_utilities/bootstrap_file.h
index c3969a357..0926ee2e5 100644
--- a/src/blockchain_utilities/bootstrap_file.h
+++ b/src/blockchain_utilities/bootstrap_file.h
@@ -57,7 +57,7 @@ class BootstrapFile
public:
uint64_t count_bytes(std::ifstream& import_file, uint64_t blocks, uint64_t& h, bool& quit);
- uint64_t count_blocks(const std::string& dir_path, streampos& start_pos, uint64_t& seek_height);
+ uint64_t count_blocks(const std::string& dir_path, std::streampos& start_pos, uint64_t& seek_height);
uint64_t count_blocks(const std::string& dir_path);
uint64_t seek_to_first_chunk(std::ifstream& import_file);
diff --git a/src/checkpoints/checkpoints.cpp b/src/checkpoints/checkpoints.cpp
index bea392db0..9be08958c 100644
--- a/src/checkpoints/checkpoints.cpp
+++ b/src/checkpoints/checkpoints.cpp
@@ -140,8 +140,8 @@ namespace cryptonote
{
if (testnet)
{
- // just use the genesis block on testnet
ADD_CHECKPOINT(0, "48ca7cd3c8de5b6a4d53d2861fbdaedca141553559f9be9520068053cda8430b");
+ ADD_CHECKPOINT(1000000, "46b690b710a07ea051bc4a6b6842ac37be691089c0f7758cfeec4d5fc0b4a258");
return true;
}
ADD_CHECKPOINT(1, "771fbcd656ec1464d3a02ead5e18644030007a0fc664c0a964d30922821a8148");
diff --git a/src/common/command_line.cpp b/src/common/command_line.cpp
index d4a28fc85..4b9ca9559 100644
--- a/src/common/command_line.cpp
+++ b/src/common/command_line.cpp
@@ -36,10 +36,6 @@
#include "cryptonote_config.h"
#include "string_tools.h"
-#ifdef HAVE_READLINE
- #include "readline_buffer.h"
-#endif
-
namespace command_line
{
namespace
@@ -50,20 +46,6 @@ namespace command_line
}
}
- std::string input_line(const std::string& prompt)
- {
-#ifdef HAVE_READLINE
- rdln::suspend_readline pause_readline;
-#endif
- std::cout << prompt;
-
- std::string buf;
- std::getline(std::cin, buf);
-
- return epee::string_tools::trim(buf);
-
- }
-
bool is_yes(const std::string& str)
{
if (str == "y" || str == "Y")
@@ -94,49 +76,4 @@ namespace command_line
const arg_descriptor<bool> arg_help = {"help", "Produce help message"};
const arg_descriptor<bool> arg_version = {"version", "Output version information"};
- const arg_descriptor<std::string> arg_data_dir = {"data-dir", "Specify data directory"};
- const arg_descriptor<std::string> arg_testnet_data_dir = {"testnet-data-dir", "Specify testnet data directory"};
- const arg_descriptor<bool> arg_test_drop_download = {"test-drop-download", "For net tests: in download, discard ALL blocks instead checking/saving them (very fast)"};
- const arg_descriptor<uint64_t> arg_test_drop_download_height = {"test-drop-download-height", "Like test-drop-download but disards only after around certain height", 0};
- const arg_descriptor<int> arg_test_dbg_lock_sleep = {"test-dbg-lock-sleep", "Sleep time in ms, defaults to 0 (off), used to debug before/after locking mutex. Values 100 to 1000 are good for tests."};
- const arg_descriptor<bool, false> arg_testnet_on = {
- "testnet"
- , "Run on testnet. The wallet must be launched with --testnet flag."
- , false
- };
- const arg_descriptor<bool> arg_dns_checkpoints = {
- "enforce-dns-checkpointing"
- , "checkpoints from DNS server will be enforced"
- , false
- };
- const command_line::arg_descriptor<uint64_t> arg_fast_block_sync = {
- "fast-block-sync"
- , "Sync up most of the way by using embedded, known block hashes."
- , 1
- };
- const command_line::arg_descriptor<uint64_t> arg_prep_blocks_threads = {
- "prep-blocks-threads"
- , "Max number of threads to use when preparing block hashes in groups."
- , 4
- };
- const command_line::arg_descriptor<uint64_t> arg_show_time_stats = {
- "show-time-stats"
- , "Show time-stats when processing blocks/txs and disk synchronization."
- , 0
- };
- const command_line::arg_descriptor<size_t> arg_block_sync_size = {
- "block-sync-size"
- , "How many blocks to sync at once during chain synchronization (0 = adaptive)."
- , 0
- };
- const command_line::arg_descriptor<std::string> arg_check_updates = {
- "check-updates"
- , "Check for new versions of monero: [disabled|notify|download|update]"
- , "notify"
- };
- const arg_descriptor<bool> arg_fluffy_blocks = {
- "fluffy-blocks"
- , "Relay blocks as fluffy blocks where possible (automatic on testnet)"
- , false
- };
}
diff --git a/src/common/command_line.h b/src/common/command_line.h
index bfc8b19c6..c2bac9cc8 100644
--- a/src/common/command_line.h
+++ b/src/common/command_line.h
@@ -41,8 +41,6 @@
namespace command_line
{
- std::string input_line(const std::string& prompt);
-
//! \return True if `str` is `is_iequal("y" || "yes" || `tr("yes"))`.
bool is_yes(const std::string& str);
//! \return True if `str` is `is_iequal("n" || "no" || `tr("no"))`.
@@ -213,17 +211,4 @@ namespace command_line
extern const arg_descriptor<bool> arg_help;
extern const arg_descriptor<bool> arg_version;
- extern const arg_descriptor<std::string> arg_data_dir;
- extern const arg_descriptor<std::string> arg_testnet_data_dir;
- extern const arg_descriptor<bool> arg_test_drop_download;
- extern const arg_descriptor<uint64_t> arg_test_drop_download_height;
- extern const arg_descriptor<int> arg_test_dbg_lock_sleep;
- extern const arg_descriptor<bool, false> arg_testnet_on;
- extern const arg_descriptor<bool> arg_dns_checkpoints;
- extern const arg_descriptor<uint64_t> arg_fast_block_sync;
- extern const arg_descriptor<uint64_t> arg_prep_blocks_threads;
- extern const arg_descriptor<uint64_t> arg_show_time_stats;
- extern const arg_descriptor<size_t> arg_block_sync_size;
- extern const arg_descriptor<std::string> arg_check_updates;
- extern const arg_descriptor<bool> arg_fluffy_blocks;
}
diff --git a/src/common/int-util.h b/src/common/int-util.h
index 34288805a..7cec571ad 100644
--- a/src/common/int-util.h
+++ b/src/common/int-util.h
@@ -40,6 +40,10 @@
#include <byteswap.h>
#endif
+#if defined(__sun) && defined(__SVR4)
+#include <endian.h>
+#endif
+
#if defined(_MSC_VER)
#include <stdlib.h>
diff --git a/src/common/password.cpp b/src/common/password.cpp
index 5c04023f4..5d56464a5 100644
--- a/src/common/password.cpp
+++ b/src/common/password.cpp
@@ -88,13 +88,11 @@ namespace
{
pass.back() = '\0';
pass.resize(pass.size() - 1);
- std::cout << "\b \b";
}
}
else
{
pass.push_back(ch);
- std::cout << '*';
}
}
@@ -150,13 +148,11 @@ namespace
{
aPass.back() = '\0';
aPass.resize(aPass.size() - 1);
- std::cout << "\b \b";
}
}
else
{
aPass.push_back(ch);
- std::cout << '*';
}
}
@@ -242,9 +238,6 @@ namespace tools
boost::optional<password_container> password_container::prompt(const bool verify, const char *message)
{
-#ifdef HAVE_READLINE
- rdln::suspend_readline pause_readline;
-#endif
password_container pass1{};
password_container pass2{};
if (is_cin_tty() ? read_from_tty(verify, message, pass1.m_password, pass2.m_password) : read_from_file(pass1.m_password))
@@ -253,7 +246,7 @@ namespace tools
return boost::none;
}
- boost::optional<login> login::parse(std::string&& userpass, bool verify, const char* message)
+ boost::optional<login> login::parse(std::string&& userpass, bool verify, const std::function<boost::optional<password_container>(bool)> &prompt)
{
login out{};
password_container wipe{std::move(userpass)};
@@ -261,7 +254,7 @@ namespace tools
const auto loc = wipe.password().find(':');
if (loc == std::string::npos)
{
- auto result = tools::password_container::prompt(verify, message);
+ auto result = prompt(verify);
if (!result)
return boost::none;
diff --git a/src/common/password.h b/src/common/password.h
index 12f715df4..ba1c30a28 100644
--- a/src/common/password.h
+++ b/src/common/password.h
@@ -82,7 +82,7 @@ namespace tools
\return The username and password, or boost::none if
`password_container::prompt` fails.
*/
- static boost::optional<login> parse(std::string&& userpass, bool verify, const char* message = "Password");
+ static boost::optional<login> parse(std::string&& userpass, bool verify, const std::function<boost::optional<password_container>(bool)> &prompt);
login(const login&) = delete;
login(login&&) = default;
diff --git a/src/common/threadpool.cpp b/src/common/threadpool.cpp
index 41d0c25e0..20c5765b0 100644
--- a/src/common/threadpool.cpp
+++ b/src/common/threadpool.cpp
@@ -39,7 +39,7 @@ namespace tools
threadpool::threadpool() : running(true), active(0) {
boost::thread::attributes attrs;
attrs.set_stack_size(THREAD_STACK_SIZE);
- max = tools::get_max_concurrency() * 2;
+ max = tools::get_max_concurrency();
size_t i = max;
while(i--) {
threads.push_back(boost::thread(attrs, boost::bind(&threadpool::run, this)));
@@ -74,7 +74,7 @@ void threadpool::submit(waiter *obj, std::function<void()> f) {
}
int threadpool::get_max_concurrency() {
- return max / 2;
+ return max;
}
void threadpool::waiter::wait() {
diff --git a/src/common/updates.cpp b/src/common/updates.cpp
index 8a057b1cf..141330c2c 100644
--- a/src/common/updates.cpp
+++ b/src/common/updates.cpp
@@ -100,7 +100,7 @@ namespace tools
{
const char *base = user ? "https://downloads.getmonero.org/" : "http://updates.getmonero.org/";
#ifdef _WIN32
- static const char extension[] = ".zip";
+ static const char *extension = strncmp(buildtag.c_str(), "install-", 8) ? ".zip" : ".exe";
#else
static const char extension[] = ".tar.bz2";
#endif
diff --git a/src/common/util.cpp b/src/common/util.cpp
index 1e180d325..a13ac6e50 100644
--- a/src/common/util.cpp
+++ b/src/common/util.cpp
@@ -405,7 +405,7 @@ namespace tools
#else
std::string get_nix_version_display_string()
{
- utsname un;
+ struct utsname un;
if(uname(&un) < 0)
return std::string("*nix: failed to get os version");
diff --git a/src/crypto/initializer.h b/src/crypto/initializer.h
index 619038ae6..eb1d1c069 100644
--- a/src/crypto/initializer.h
+++ b/src/crypto/initializer.h
@@ -31,8 +31,13 @@
#pragma once
#if defined(__GNUC__)
+#if defined(__sun) && defined(__SVR4)
+#define INITIALIZER(name) __attribute__((constructor)) static void name(void)
+#define FINALIZER(name) __attribute__((destructor)) static void name(void)
+#else
#define INITIALIZER(name) __attribute__((constructor(101))) static void name(void)
#define FINALIZER(name) __attribute__((destructor(101))) static void name(void)
+#endif
#define REGISTER_FINALIZER(name) ((void) 0)
#elif defined(_MSC_VER)
diff --git a/src/cryptonote_basic/cryptonote_format_utils.cpp b/src/cryptonote_basic/cryptonote_format_utils.cpp
index d09f4c432..1c28ca4d8 100644
--- a/src/cryptonote_basic/cryptonote_format_utils.cpp
+++ b/src/cryptonote_basic/cryptonote_format_utils.cpp
@@ -45,6 +45,8 @@ using namespace epee;
// #define ENABLE_HASH_CASH_INTEGRITY_CHECK
+using namespace crypto;
+
static const uint64_t valid_decomposed_outputs[] = {
(uint64_t)1, (uint64_t)2, (uint64_t)3, (uint64_t)4, (uint64_t)5, (uint64_t)6, (uint64_t)7, (uint64_t)8, (uint64_t)9, // 1 piconero
(uint64_t)10, (uint64_t)20, (uint64_t)30, (uint64_t)40, (uint64_t)50, (uint64_t)60, (uint64_t)70, (uint64_t)80, (uint64_t)90,
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 4e1ab8a48..3d586a704 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -61,6 +61,8 @@
#define FIND_BLOCKCHAIN_SUPPLEMENT_MAX_SIZE (100*1024*1024) // 100 MB
+using namespace crypto;
+
//#include "serialization/json_archive.h"
/* TODO:
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index 3f2930fb0..e0936da8f 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -635,16 +635,6 @@ namespace cryptonote
uint64_t get_current_cumulative_blocksize_limit() const;
/**
- * @brief checks if the blockchain is currently being stored
- *
- * Note: this should be meaningless in cases where Blockchain is not
- * directly managing saving the blockchain to disk.
- *
- * @return true if Blockchain is having the chain stored currently, else false
- */
- bool is_storing_blockchain()const{return false;}
-
- /**
* @brief gets the difficulty of the block with a given height
*
* @param i the height
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 3f56ffac7..acc76a8d6 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -38,6 +38,7 @@ using namespace epee;
#include "common/updates.h"
#include "common/download.h"
#include "common/threadpool.h"
+#include "common/command_line.h"
#include "warnings.h"
#include "crypto/crypto.h"
#include "cryptonote_config.h"
@@ -61,6 +62,69 @@ DISABLE_VS_WARNINGS(4355)
namespace cryptonote
{
+ const command_line::arg_descriptor<std::string> arg_data_dir = {
+ "data-dir"
+ , "Specify data directory"
+ };
+ const command_line::arg_descriptor<std::string> arg_testnet_data_dir = {
+ "testnet-data-dir"
+ , "Specify testnet data directory"
+ };
+ const command_line::arg_descriptor<bool, false> arg_testnet_on = {
+ "testnet"
+ , "Run on testnet. The wallet must be launched with --testnet flag."
+ , false
+ };
+
+ static const command_line::arg_descriptor<bool> arg_test_drop_download = {
+ "test-drop-download"
+ , "For net tests: in download, discard ALL blocks instead checking/saving them (very fast)"
+ };
+ static const command_line::arg_descriptor<uint64_t> arg_test_drop_download_height = {
+ "test-drop-download-height"
+ , "Like test-drop-download but disards only after around certain height"
+ , 0
+ };
+ static const command_line::arg_descriptor<int> arg_test_dbg_lock_sleep = {
+ "test-dbg-lock-sleep"
+ , "Sleep time in ms, defaults to 0 (off), used to debug before/after locking mutex. Values 100 to 1000 are good for tests."
+ , 0
+ };
+ static const command_line::arg_descriptor<bool> arg_dns_checkpoints = {
+ "enforce-dns-checkpointing"
+ , "checkpoints from DNS server will be enforced"
+ , false
+ };
+ static const command_line::arg_descriptor<uint64_t> arg_fast_block_sync = {
+ "fast-block-sync"
+ , "Sync up most of the way by using embedded, known block hashes."
+ , 1
+ };
+ static const command_line::arg_descriptor<uint64_t> arg_prep_blocks_threads = {
+ "prep-blocks-threads"
+ , "Max number of threads to use when preparing block hashes in groups."
+ , 4
+ };
+ static const command_line::arg_descriptor<uint64_t> arg_show_time_stats = {
+ "show-time-stats"
+ , "Show time-stats when processing blocks/txs and disk synchronization."
+ , 0
+ };
+ static const command_line::arg_descriptor<size_t> arg_block_sync_size = {
+ "block-sync-size"
+ , "How many blocks to sync at once during chain synchronization (0 = adaptive)."
+ , 0
+ };
+ static const command_line::arg_descriptor<std::string> arg_check_updates = {
+ "check-updates"
+ , "Check for new versions of monero: [disabled|notify|download|update]"
+ , "notify"
+ };
+ static const command_line::arg_descriptor<bool> arg_fluffy_blocks = {
+ "fluffy-blocks"
+ , "Relay blocks as fluffy blocks where possible (automatic on testnet)"
+ , false
+ };
//-----------------------------------------------------------------------------------------------
core::core(i_cryptonote_protocol* pprotocol):
@@ -148,20 +212,21 @@ namespace cryptonote
//-----------------------------------------------------------------------------------
void core::init_options(boost::program_options::options_description& desc)
{
- command_line::add_arg(desc, command_line::arg_data_dir, tools::get_default_data_dir());
- command_line::add_arg(desc, command_line::arg_testnet_data_dir, (boost::filesystem::path(tools::get_default_data_dir()) / "testnet").string());
+ command_line::add_arg(desc, arg_data_dir, tools::get_default_data_dir());
+ command_line::add_arg(desc, arg_testnet_data_dir, (boost::filesystem::path(tools::get_default_data_dir()) / "testnet").string());
- command_line::add_arg(desc, command_line::arg_test_drop_download);
- command_line::add_arg(desc, command_line::arg_test_drop_download_height);
+ command_line::add_arg(desc, arg_test_drop_download);
+ command_line::add_arg(desc, arg_test_drop_download_height);
- command_line::add_arg(desc, command_line::arg_testnet_on);
- command_line::add_arg(desc, command_line::arg_dns_checkpoints);
- command_line::add_arg(desc, command_line::arg_prep_blocks_threads);
- command_line::add_arg(desc, command_line::arg_fast_block_sync);
- command_line::add_arg(desc, command_line::arg_show_time_stats);
- command_line::add_arg(desc, command_line::arg_block_sync_size);
- command_line::add_arg(desc, command_line::arg_check_updates);
- command_line::add_arg(desc, command_line::arg_fluffy_blocks);
+ command_line::add_arg(desc, arg_testnet_on);
+ command_line::add_arg(desc, arg_dns_checkpoints);
+ command_line::add_arg(desc, arg_prep_blocks_threads);
+ command_line::add_arg(desc, arg_fast_block_sync);
+ command_line::add_arg(desc, arg_show_time_stats);
+ command_line::add_arg(desc, arg_block_sync_size);
+ command_line::add_arg(desc, arg_check_updates);
+ command_line::add_arg(desc, arg_fluffy_blocks);
+ command_line::add_arg(desc, arg_test_dbg_lock_sleep);
// we now also need some of net_node's options (p2p bind arg, for separate data dir)
command_line::add_arg(desc, nodetool::arg_testnet_p2p_bind_port, false);
@@ -173,9 +238,9 @@ namespace cryptonote
//-----------------------------------------------------------------------------------------------
bool core::handle_command_line(const boost::program_options::variables_map& vm)
{
- m_testnet = command_line::get_arg(vm, command_line::arg_testnet_on);
+ m_testnet = command_line::get_arg(vm, arg_testnet_on);
- auto data_dir_arg = m_testnet ? command_line::arg_testnet_data_dir : command_line::arg_data_dir;
+ auto data_dir_arg = m_testnet ? arg_testnet_data_dir : arg_data_dir;
m_config_folder = command_line::get_arg(vm, data_dir_arg);
auto data_dir = boost::filesystem::path(m_config_folder);
@@ -196,13 +261,15 @@ namespace cryptonote
}
- set_enforce_dns_checkpoints(command_line::get_arg(vm, command_line::arg_dns_checkpoints));
- test_drop_download_height(command_line::get_arg(vm, command_line::arg_test_drop_download_height));
- m_fluffy_blocks_enabled = m_testnet || get_arg(vm, command_line::arg_fluffy_blocks);
+ set_enforce_dns_checkpoints(command_line::get_arg(vm, arg_dns_checkpoints));
+ test_drop_download_height(command_line::get_arg(vm, arg_test_drop_download_height));
+ m_fluffy_blocks_enabled = m_testnet || get_arg(vm, arg_fluffy_blocks);
- if (command_line::get_arg(vm, command_line::arg_test_drop_download) == true)
+ if (command_line::get_arg(vm, arg_test_drop_download) == true)
test_drop_download();
+ epee::debug::g_test_dbg_lock_sleep() = command_line::get_arg(vm, arg_test_dbg_lock_sleep);
+
return true;
}
//-----------------------------------------------------------------------------------------------
@@ -268,7 +335,7 @@ namespace cryptonote
m_fakechain = test_options != NULL;
bool r = handle_command_line(vm);
- bool testnet = command_line::get_arg(vm, command_line::arg_testnet_on);
+ bool testnet = command_line::get_arg(vm, arg_testnet_on);
auto p2p_bind_arg = testnet ? nodetool::arg_testnet_p2p_bind_port : nodetool::arg_p2p_bind_port;
std::string m_port = command_line::get_arg(vm, p2p_bind_arg);
std::string m_config_folder_mempool = m_config_folder;
@@ -281,9 +348,9 @@ namespace cryptonote
std::string db_type = command_line::get_arg(vm, cryptonote::arg_db_type);
std::string db_sync_mode = command_line::get_arg(vm, cryptonote::arg_db_sync_mode);
bool db_salvage = command_line::get_arg(vm, cryptonote::arg_db_salvage) != 0;
- bool fast_sync = command_line::get_arg(vm, command_line::arg_fast_block_sync) != 0;
- uint64_t blocks_threads = command_line::get_arg(vm, command_line::arg_prep_blocks_threads);
- std::string check_updates_string = command_line::get_arg(vm, command_line::arg_check_updates);
+ bool fast_sync = command_line::get_arg(vm, arg_fast_block_sync) != 0;
+ uint64_t blocks_threads = command_line::get_arg(vm, arg_prep_blocks_threads);
+ std::string check_updates_string = command_line::get_arg(vm, arg_check_updates);
boost::filesystem::path folder(m_config_folder);
if (m_fakechain)
@@ -409,11 +476,11 @@ namespace cryptonote
// transactions in the pool that do not conform to the current fork
m_mempool.validate(m_blockchain_storage.get_current_hard_fork_version());
- bool show_time_stats = command_line::get_arg(vm, command_line::arg_show_time_stats) != 0;
+ bool show_time_stats = command_line::get_arg(vm, arg_show_time_stats) != 0;
m_blockchain_storage.set_show_time_stats(show_time_stats);
CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage");
- block_sync_size = command_line::get_arg(vm, command_line::arg_block_sync_size);
+ block_sync_size = command_line::get_arg(vm, arg_block_sync_size);
MGINFO("Loading checkpoints");
@@ -498,8 +565,8 @@ namespace cryptonote
return false;
}
- tx_hash = null_hash;
- tx_prefixt_hash = null_hash;
+ tx_hash = crypto::null_hash;
+ tx_prefixt_hash = crypto::null_hash;
if(!parse_tx_from_blob(tx, tx_hash, tx_prefixt_hash, tx_blob))
{
diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h
index a3d47280a..dc014206d 100644
--- a/src/cryptonote_core/cryptonote_core.h
+++ b/src/cryptonote_core/cryptonote_core.h
@@ -41,6 +41,7 @@
#include "storages/portable_storage_template_helper.h"
#include "common/download.h"
#include "common/threadpool.h"
+#include "common/command_line.h"
#include "tx_pool.h"
#include "blockchain.h"
#include "cryptonote_basic/miner.h"
@@ -58,6 +59,10 @@ namespace cryptonote
const std::pair<uint8_t, uint64_t> *hard_forks;
};
+ extern const command_line::arg_descriptor<std::string> arg_data_dir;
+ extern const command_line::arg_descriptor<std::string> arg_testnet_data_dir;
+ extern const command_line::arg_descriptor<bool, false> arg_testnet_on;
+
/************************************************************************/
/* */
/************************************************************************/
diff --git a/src/cryptonote_core/cryptonote_tx_utils.cpp b/src/cryptonote_core/cryptonote_tx_utils.cpp
index 9409a60a5..feefc1592 100644
--- a/src/cryptonote_core/cryptonote_tx_utils.cpp
+++ b/src/cryptonote_core/cryptonote_tx_utils.cpp
@@ -40,6 +40,8 @@ using namespace epee;
#include "crypto/hash.h"
#include "ringct/rctSigs.h"
+using namespace crypto;
+
namespace cryptonote
{
//---------------------------------------------------------------
diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp
index 6bfcfe529..e6f217463 100644
--- a/src/cryptonote_core/tx_pool.cpp
+++ b/src/cryptonote_core/tx_pool.cpp
@@ -51,6 +51,8 @@
DISABLE_VS_WARNINGS(4244 4345 4503) //'boost::foreach_detail_::or_' : decorated name length exceeded, name was truncated
+using namespace crypto;
+
namespace cryptonote
{
namespace
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
index e41491954..73433a8d8 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -297,9 +297,9 @@ namespace cryptonote
m_core.set_target_blockchain_height((hshd.current_height));
int64_t diff = static_cast<int64_t>(hshd.current_height) - static_cast<int64_t>(m_core.get_current_blockchain_height());
uint64_t abs_diff = std::abs(diff);
- uint64_t max_block_height = max(hshd.current_height,m_core.get_current_blockchain_height());
+ uint64_t max_block_height = std::max(hshd.current_height,m_core.get_current_blockchain_height());
uint64_t last_block_v1 = m_core.get_testnet() ? 624633 : 1009826;
- uint64_t diff_v2 = max_block_height > last_block_v1 ? min(abs_diff, max_block_height - last_block_v1) : 0;
+ uint64_t diff_v2 = max_block_height > last_block_v1 ? std::min(abs_diff, max_block_height - last_block_v1) : 0;
MCLOG(is_inital ? el::Level::Info : el::Level::Debug, "global", context << "Sync data returned a new top block candidate: " << m_core.get_current_blockchain_height() << " -> " << hshd.current_height
<< " [Your node is " << abs_diff << " blocks (" << ((abs_diff - diff_v2) / (24 * 60 * 60 / DIFFICULTY_TARGET_V1)) + (diff_v2 / (24 * 60 * 60 / DIFFICULTY_TARGET_V2)) << " days) "
<< (0 <= diff ? std::string("behind") : std::string("ahead"))
diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt
index d0fc1d846..2f9c2b2f9 100644
--- a/src/daemon/CMakeLists.txt
+++ b/src/daemon/CMakeLists.txt
@@ -94,6 +94,8 @@ target_link_libraries(daemon
daemonizer
serialization
daemon_rpc_server
+ epee
+ ${EPEE_READLINE}
version
${Boost_CHRONO_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
@@ -102,6 +104,7 @@ target_link_libraries(daemon
${Boost_SYSTEM_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
${ZMQ_LIB}
+ ${Readline_LIBRARY}
${EXTRA_LIBRARIES})
set_property(TARGET daemon
PROPERTY
diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp
index faa620c54..cf7d5f8ab 100644
--- a/src/daemon/daemon.cpp
+++ b/src/daemon/daemon.cpp
@@ -88,7 +88,7 @@ t_daemon::t_daemon(
)
: mp_internals{new t_internals{vm}}
{
- bool testnet = command_line::get_arg(vm, command_line::arg_testnet_on);
+ bool testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on);
if (testnet)
{
zmq_rpc_bind_port = command_line::get_arg(vm, daemon_args::arg_zmq_testnet_rpc_bind_port);
diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp
index 5d548f410..ae83943b6 100644
--- a/src/daemon/main.cpp
+++ b/src/daemon/main.cpp
@@ -82,7 +82,6 @@ int main(int argc, char const * argv[])
command_line::add_arg(visible_options, daemon_args::arg_os_version);
bf::path default_conf = default_data_dir / std::string(CRYPTONOTE_NAME ".conf");
command_line::add_arg(visible_options, daemon_args::arg_config_file, default_conf.string());
- command_line::add_arg(visible_options, command_line::arg_test_dbg_lock_sleep);
// Settings
bf::path default_log = default_data_dir / std::string(CRYPTONOTE_NAME ".log");
@@ -144,8 +143,6 @@ int main(int argc, char const * argv[])
return 0;
}
- epee::debug::g_test_dbg_lock_sleep() = command_line::get_arg(vm, command_line::arg_test_dbg_lock_sleep);
-
std::string db_type = command_line::get_arg(vm, cryptonote::arg_db_type);
// verify that blockchaindb type is valid
@@ -156,9 +153,9 @@ int main(int argc, char const * argv[])
return 0;
}
- bool testnet_mode = command_line::get_arg(vm, command_line::arg_testnet_on);
+ bool testnet_mode = command_line::get_arg(vm, cryptonote::arg_testnet_on);
- auto data_dir_arg = testnet_mode ? command_line::arg_testnet_data_dir : command_line::arg_data_dir;
+ auto data_dir_arg = testnet_mode ? cryptonote::arg_testnet_data_dir : cryptonote::arg_data_dir;
// data_dir
// default: e.g. ~/.bitmonero/ or ~/.bitmonero/testnet
@@ -250,7 +247,12 @@ int main(int argc, char const * argv[])
if (command_line::has_arg(vm, arg.rpc_login))
{
login = tools::login::parse(
- command_line::get_arg(vm, arg.rpc_login), false, "Daemon client password"
+ command_line::get_arg(vm, arg.rpc_login), false, [](bool verify) {
+#ifdef HAVE_READLINE
+ rdln::suspend_readline pause_readline;
+#endif
+ return tools::password_container::prompt(verify, "Daemon client password");
+ }
);
if (!login)
{
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index 83b04bff5..230b9f090 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -1011,7 +1011,7 @@ bool t_rpc_command_executor::print_transaction_pool_stats() {
tools::msg_writer() << " Age Txes Bytes";
for (i=0; i<n; i++)
{
- tools::msg_writer() << get_time_hms(times[i]) << setw(8) << res.pool_stats.histo[i].txs << setw(12) << res.pool_stats.histo[i].bytes;
+ tools::msg_writer() << get_time_hms(times[i]) << std::setw(8) << res.pool_stats.histo[i].txs << std::setw(12) << res.pool_stats.histo[i].bytes;
}
}
tools::msg_writer();
diff --git a/src/p2p/connection_basic.cpp b/src/p2p/connection_basic.cpp
index b95f36b99..8edd75b3e 100644
--- a/src/p2p/connection_basic.cpp
+++ b/src/p2p/connection_basic.cpp
@@ -158,7 +158,7 @@ connection_basic::connection_basic(boost::asio::io_service& io_service, std::ato
++ref_sock_count; // increase the global counter
mI->m_peer_number = sock_number.fetch_add(1); // use, and increase the generated number
- string remote_addr_str = "?";
+ std::string remote_addr_str = "?";
try { boost::system::error_code e; remote_addr_str = socket_.remote_endpoint(e).address().to_string(); } catch(...){} ;
_note("Spawned connection p2p#"<<mI->m_peer_number<<" to " << remote_addr_str << " currently we have sockets count:" << m_ref_sock_count);
@@ -166,7 +166,7 @@ connection_basic::connection_basic(boost::asio::io_service& io_service, std::ato
}
connection_basic::~connection_basic() noexcept(false) {
- string remote_addr_str = "?";
+ std::string remote_addr_str = "?";
m_ref_sock_count--;
try { boost::system::error_code e; remote_addr_str = socket_.remote_endpoint(e).address().to_string(); } catch(...){} ;
_note("Destructing connection p2p#"<<mI->m_peer_number << " to " << remote_addr_str);
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index ee3ff160a..f64b29c1f 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -48,6 +48,7 @@
#include "net/local_ip.h"
#include "crypto/crypto.h"
#include "storages/levin_abstract_invoke2.h"
+#include "cryptonote_core/cryptonote_core.h"
// We have to look for miniupnpc headers in different places, dependent on if its compiled or external
#ifdef UPNP_STATIC
@@ -434,7 +435,7 @@ namespace nodetool
bool node_server<t_payload_net_handler>::init(const boost::program_options::variables_map& vm)
{
std::set<std::string> full_addrs;
- m_testnet = command_line::get_arg(vm, command_line::arg_testnet_on);
+ m_testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on);
if (m_testnet)
{
@@ -535,7 +536,7 @@ namespace nodetool
bool res = handle_command_line(vm);
CHECK_AND_ASSERT_MES(res, false, "Failed to handle command line");
- auto config_arg = m_testnet ? command_line::arg_testnet_data_dir : command_line::arg_data_dir;
+ auto config_arg = m_testnet ? cryptonote::arg_testnet_data_dir : cryptonote::arg_data_dir;
m_config_folder = command_line::get_arg(vm, config_arg);
if ((!m_testnet && m_port != std::to_string(::config::P2P_DEFAULT_PORT))
diff --git a/src/ringct/rctOps.h b/src/ringct/rctOps.h
index cb19bbbd6..412450c18 100644
--- a/src/ringct/rctOps.h
+++ b/src/ringct/rctOps.h
@@ -35,8 +35,6 @@
#define RCTOPS_H
#include <cstddef>
-#include <mutex>
-#include <vector>
#include <tuple>
#include "crypto/generic-ops.h"
@@ -57,9 +55,6 @@ extern "C" {
#define DP(x)
#endif
-using namespace std;
-using namespace crypto;
-
namespace rct {
//Various key initialization functions
@@ -99,13 +94,13 @@ namespace rct {
key pkGen();
//generates a random secret and corresponding public key
void skpkGen(key &sk, key &pk);
- tuple<key, key> skpkGen();
+ std::tuple<key, key> skpkGen();
//generates a <secret , public> / Pedersen commitment to the amount
- tuple<ctkey, ctkey> ctskpkGen(xmr_amount amount);
+ std::tuple<ctkey, ctkey> ctskpkGen(xmr_amount amount);
//generates C =aG + bH from b, a is random
void genC(key & C, const key & a, xmr_amount amount);
//this one is mainly for testing, can take arbitrary amounts..
- tuple<ctkey, ctkey> ctskpkGen(const key &bH);
+ std::tuple<ctkey, ctkey> ctskpkGen(const key &bH);
// make a pedersen commitment with given key
key commit(xmr_amount amount, const key &mask);
// make a pedersen commitment with zero key
diff --git a/src/ringct/rctSigs.h b/src/ringct/rctSigs.h
index ca40ddd85..d158f06f0 100644
--- a/src/ringct/rctSigs.h
+++ b/src/ringct/rctSigs.h
@@ -36,7 +36,6 @@
#define RCTSIGS_H
#include <cstddef>
-#include <mutex>
#include <vector>
#include <tuple>
@@ -61,9 +60,6 @@ extern "C" {
-using namespace std;
-using namespace crypto;
-
namespace rct {
boroSig genBorromean(const key64 x, const key64 P1, const key64 P2, const bits indices);
@@ -110,7 +106,7 @@ namespace rct {
//populateFromBlockchain creates a keymatrix with "mixin" columns and one of the columns is inPk
// the return value are the key matrix, and the index where inPk was put (random).
void getKeyFromBlockchain(ctkey & a, size_t reference_index);
- tuple<ctkeyM, xmr_amount> populateFromBlockchain(ctkeyV inPk, int mixin);
+ std::tuple<ctkeyM, xmr_amount> populateFromBlockchain(ctkeyV inPk, int mixin);
//RingCT protocol
//genRct:
@@ -122,10 +118,10 @@ namespace rct {
//decodeRct: (c.f. http://eprint.iacr.org/2015/1098 section 5.1.1)
// uses the attached ecdh info to find the amounts represented by each output commitment
// must know the destination private key to find the correct amount, else will return a random number
- rctSig genRct(const key &message, const ctkeyV & inSk, const keyV & destinations, const vector<xmr_amount> & amounts, const ctkeyM &mixRing, const keyV &amount_keys, unsigned int index, ctkeyV &outSk);
- rctSig genRct(const key &message, const ctkeyV & inSk, const ctkeyV & inPk, const keyV & destinations, const vector<xmr_amount> & amounts, const keyV &amount_keys, const int mixin);
- rctSig genRctSimple(const key & message, const ctkeyV & inSk, const ctkeyV & inPk, const keyV & destinations, const vector<xmr_amount> & inamounts, const vector<xmr_amount> & outamounts, const keyV &amount_keys, xmr_amount txnFee, unsigned int mixin);
- rctSig genRctSimple(const key & message, const ctkeyV & inSk, const keyV & destinations, const vector<xmr_amount> & inamounts, const vector<xmr_amount> & outamounts, xmr_amount txnFee, const ctkeyM & mixRing, const keyV &amount_keys, const std::vector<unsigned int> & index, ctkeyV &outSk);
+ rctSig genRct(const key &message, const ctkeyV & inSk, const keyV & destinations, const std::vector<xmr_amount> & amounts, const ctkeyM &mixRing, const keyV &amount_keys, unsigned int index, ctkeyV &outSk);
+ rctSig genRct(const key &message, const ctkeyV & inSk, const ctkeyV & inPk, const keyV & destinations, const std::vector<xmr_amount> & amounts, const keyV &amount_keys, const int mixin);
+ rctSig genRctSimple(const key & message, const ctkeyV & inSk, const ctkeyV & inPk, const keyV & destinations, const std::vector<xmr_amount> & inamounts, const std::vector<xmr_amount> & outamounts, const keyV &amount_keys, xmr_amount txnFee, unsigned int mixin);
+ rctSig genRctSimple(const key & message, const ctkeyV & inSk, const keyV & destinations, const std::vector<xmr_amount> & inamounts, const std::vector<xmr_amount> & outamounts, xmr_amount txnFee, const ctkeyM & mixRing, const keyV &amount_keys, const std::vector<unsigned int> & index, ctkeyV &outSk);
bool verRct(const rctSig & rv, bool semantics);
static inline bool verRct(const rctSig & rv) { return verRct(rv, true) && verRct(rv, false); }
bool verRctSimple(const rctSig & rv, bool semantics);
diff --git a/src/ringct/rctTypes.h b/src/ringct/rctTypes.h
index cc0000ad6..8147cb602 100644
--- a/src/ringct/rctTypes.h
+++ b/src/ringct/rctTypes.h
@@ -33,9 +33,7 @@
#define RCT_TYPES_H
#include <cstddef>
-#include <mutex>
#include <vector>
-#include <tuple>
#include <iostream>
#include <cinttypes>
@@ -67,9 +65,6 @@ extern "C" {
//for printing large ints
-using namespace std;
-using namespace crypto;
-
//Namespace specifically for ring ct code
namespace rct {
//basic ops containers
@@ -89,8 +84,8 @@ namespace rct {
bool operator==(const key &k) const { return !memcmp(bytes, k.bytes, sizeof(bytes)); }
unsigned char bytes[32];
};
- typedef vector<key> keyV; //vector of keys
- typedef vector<keyV> keyM; //matrix of keys (indexed by column first)
+ typedef std::vector<key> keyV; //vector of keys
+ typedef std::vector<keyV> keyM; //matrix of keys (indexed by column first)
//containers For CT operations
//if it's representing a private ctkey then "dest" contains the secret key of the address
@@ -101,8 +96,8 @@ namespace rct {
key dest;
key mask; //C here if public
};
- typedef vector<ctkey> ctkeyV;
- typedef vector<ctkeyV> ctkeyM;
+ typedef std::vector<ctkey> ctkeyV;
+ typedef std::vector<ctkeyV> ctkeyM;
//data for passing the amount to the receiver secretly
// If the pedersen commitment to an amount is C = aG + bH,
@@ -184,7 +179,7 @@ namespace rct {
ctkeyM mixRing; //the set of all pubkeys / copy
//pairs that you mix with
keyV pseudoOuts; //C - for simple rct
- vector<ecdhTuple> ecdhInfo;
+ std::vector<ecdhTuple> ecdhInfo;
ctkeyV outPk;
xmr_amount txnFee; // contains b
@@ -245,8 +240,8 @@ namespace rct {
}
};
struct rctSigPrunable {
- vector<rangeSig> rangeSigs;
- vector<mgSig> MGs; // simple rct has N, full has 1
+ std::vector<rangeSig> rangeSigs;
+ std::vector<mgSig> MGs; // simple rct has N, full has 1
template<bool W, template <bool> class Archive>
bool serialize_rctsig_prunable(Archive<W> &ar, uint8_t type, size_t inputs, size_t outputs, size_t mixin)
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index 9094ec732..6e7fb7e8e 100755..100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -36,6 +36,7 @@ using namespace epee;
#include "common/updates.h"
#include "common/download.h"
#include "common/util.h"
+#include "common/perf_timer.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "cryptonote_basic/account.h"
#include "cryptonote_basic/cryptonote_basic_impl.h"
@@ -84,7 +85,7 @@ namespace cryptonote
const boost::program_options::variables_map& vm
)
{
- m_testnet = command_line::get_arg(vm, command_line::arg_testnet_on);
+ m_testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on);
m_net_server.set_threads_prefix("RPC");
auto p2p_bind_arg = m_testnet ? arg_testnet_rpc_bind_port : arg_rpc_bind_port;
@@ -105,30 +106,20 @@ namespace cryptonote
);
}
//------------------------------------------------------------------------------------------------------------------------------
- bool core_rpc_server::check_core_busy()
- {
- if(m_p2p.get_payload_object().get_core().get_blockchain_storage().is_storing_blockchain())
- {
- return false;
- }
- return true;
- }
-#define CHECK_CORE_BUSY() do { if(!check_core_busy()){res.status = CORE_RPC_STATUS_BUSY;return true;} } while(0)
- //------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::check_core_ready()
{
if(!m_p2p.get_payload_object().is_synchronized())
{
return false;
}
- return check_core_busy();
+ return true;
}
#define CHECK_CORE_READY() do { if(!check_core_ready()){res.status = CORE_RPC_STATUS_BUSY;return true;} } while(0)
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_height(const COMMAND_RPC_GET_HEIGHT::request& req, COMMAND_RPC_GET_HEIGHT::response& res)
{
- CHECK_CORE_BUSY();
+ PERF_TIMER(on_get_height);
res.height = m_core.get_current_blockchain_height();
res.status = CORE_RPC_STATUS_OK;
return true;
@@ -136,7 +127,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_info(const COMMAND_RPC_GET_INFO::request& req, COMMAND_RPC_GET_INFO::response& res)
{
- CHECK_CORE_BUSY();
+ PERF_TIMER(on_get_info);
crypto::hash top_hash;
m_core.get_blockchain_top(res.height, top_hash);
++res.height; // turn top block height into blockchain height
@@ -150,6 +141,7 @@ namespace cryptonote
uint64_t total_conn = m_p2p.get_connections_count();
res.outgoing_connections_count = m_p2p.get_outgoing_connections_count();
res.incoming_connections_count = total_conn - res.outgoing_connections_count;
+ res.rpc_connections_count = get_connections_count();
res.white_peerlist_size = m_p2p.get_peerlist_manager().get_white_peers_count();
res.grey_peerlist_size = m_p2p.get_peerlist_manager().get_gray_peers_count();
res.testnet = m_testnet;
@@ -179,7 +171,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_blocks(const COMMAND_RPC_GET_BLOCKS_FAST::request& req, COMMAND_RPC_GET_BLOCKS_FAST::response& res)
{
- CHECK_CORE_BUSY();
+ PERF_TIMER(on_get_blocks);
std::list<std::pair<cryptonote::blobdata, std::list<cryptonote::blobdata> > > bs;
if(!m_core.find_blockchain_supplement(req.start_height, req.block_ids, bs, res.current_height, res.start_height, COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT))
@@ -238,7 +230,7 @@ namespace cryptonote
}
bool core_rpc_server::on_get_alt_blocks_hashes(const COMMAND_RPC_GET_ALT_BLOCKS_HASHES::request& req, COMMAND_RPC_GET_ALT_BLOCKS_HASHES::response& res)
{
- CHECK_CORE_BUSY();
+ PERF_TIMER(on_get_alt_blocks_hashes);
std::list<block> blks;
if(!m_core.get_alternative_blocks(blks))
@@ -261,7 +253,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_blocks_by_height(const COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::request& req, COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::response& res)
{
- CHECK_CORE_BUSY();
+ PERF_TIMER(on_get_blocks_by_height);
res.status = "Failed";
res.blocks.clear();
res.blocks.reserve(req.heights.size());
@@ -291,7 +283,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_hashes(const COMMAND_RPC_GET_HASHES_FAST::request& req, COMMAND_RPC_GET_HASHES_FAST::response& res)
{
- CHECK_CORE_BUSY();
+ PERF_TIMER(on_get_hashes);
NOTIFY_RESPONSE_CHAIN_ENTRY::request resp;
resp.start_height = req.start_height;
@@ -310,7 +302,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_random_outs(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res)
{
- CHECK_CORE_BUSY();
+ PERF_TIMER(on_get_random_outs);
res.status = "Failed";
if (m_restricted)
@@ -349,7 +341,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_outs_bin(const COMMAND_RPC_GET_OUTPUTS_BIN::request& req, COMMAND_RPC_GET_OUTPUTS_BIN::response& res)
{
- CHECK_CORE_BUSY();
+ PERF_TIMER(on_get_outs_bin);
res.status = "Failed";
if (m_restricted)
@@ -372,7 +364,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_outs(const COMMAND_RPC_GET_OUTPUTS::request& req, COMMAND_RPC_GET_OUTPUTS::response& res)
{
- CHECK_CORE_BUSY();
+ PERF_TIMER(on_get_outs);
res.status = "Failed";
if (m_restricted)
@@ -410,7 +402,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_random_rct_outs(const COMMAND_RPC_GET_RANDOM_RCT_OUTPUTS::request& req, COMMAND_RPC_GET_RANDOM_RCT_OUTPUTS::response& res)
{
- CHECK_CORE_BUSY();
+ PERF_TIMER(on_get_random_rct_outs);
res.status = "Failed";
if(!m_core.get_random_rct_outs(req, res))
{
@@ -434,7 +426,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_indexes(const COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request& req, COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response& res)
{
- CHECK_CORE_BUSY();
+ PERF_TIMER(on_get_indexes);
bool r = m_core.get_tx_outputs_gindexs(req.txid, res.o_indexes);
if(!r)
{
@@ -448,7 +440,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_transactions(const COMMAND_RPC_GET_TRANSACTIONS::request& req, COMMAND_RPC_GET_TRANSACTIONS::response& res)
{
- CHECK_CORE_BUSY();
+ PERF_TIMER(on_get_transactions);
std::vector<crypto::hash> vh;
for(const auto& tx_hex_str: req.txs_hashes)
{
@@ -593,7 +585,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_is_key_image_spent(const COMMAND_RPC_IS_KEY_IMAGE_SPENT::request& req, COMMAND_RPC_IS_KEY_IMAGE_SPENT::response& res, bool request_has_rpc_origin)
{
- CHECK_CORE_BUSY();
+ PERF_TIMER(on_is_key_image_spent);
std::vector<crypto::key_image> key_images;
for(const auto& ki_hex_str: req.key_images)
{
@@ -656,6 +648,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_send_raw_tx(const COMMAND_RPC_SEND_RAW_TX::request& req, COMMAND_RPC_SEND_RAW_TX::response& res)
{
+ PERF_TIMER(on_send_raw_tx);
CHECK_CORE_READY();
std::string tx_blob;
@@ -719,6 +712,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_start_mining(const COMMAND_RPC_START_MINING::request& req, COMMAND_RPC_START_MINING::response& res)
{
+ PERF_TIMER(on_start_mining);
CHECK_CORE_READY();
cryptonote::address_parse_info info;
if(!get_account_address_from_str(info, m_testnet, req.miner_address))
@@ -766,6 +760,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_stop_mining(const COMMAND_RPC_STOP_MINING::request& req, COMMAND_RPC_STOP_MINING::response& res)
{
+ PERF_TIMER(on_stop_mining);
if(!m_core.get_miner().stop())
{
res.status = "Failed, mining not stopped";
@@ -778,7 +773,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_mining_status(const COMMAND_RPC_MINING_STATUS::request& req, COMMAND_RPC_MINING_STATUS::response& res)
{
- CHECK_CORE_BUSY();
+ PERF_TIMER(on_mining_status);
const miner& lMiner = m_core.get_miner();
res.active = lMiner.is_mining();
@@ -797,7 +792,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_save_bc(const COMMAND_RPC_SAVE_BC::request& req, COMMAND_RPC_SAVE_BC::response& res)
{
- CHECK_CORE_BUSY();
+ PERF_TIMER(on_save_bc);
if( !m_core.get_blockchain_storage().store_blockchain() )
{
res.status = "Error while storing blockhain";
@@ -809,6 +804,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_peer_list(const COMMAND_RPC_GET_PEER_LIST::request& req, COMMAND_RPC_GET_PEER_LIST::response& res)
{
+ PERF_TIMER(on_get_peer_list);
std::list<nodetool::peerlist_entry> white_list;
std::list<nodetool::peerlist_entry> gray_list;
m_p2p.get_peerlist_manager().get_peerlist_full(gray_list, white_list);
@@ -838,6 +834,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_set_log_hash_rate(const COMMAND_RPC_SET_LOG_HASH_RATE::request& req, COMMAND_RPC_SET_LOG_HASH_RATE::response& res)
{
+ PERF_TIMER(on_set_log_hash_rate);
if(m_core.get_miner().is_mining())
{
m_core.get_miner().do_print_hashrate(req.visible);
@@ -852,6 +849,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_set_log_level(const COMMAND_RPC_SET_LOG_LEVEL::request& req, COMMAND_RPC_SET_LOG_LEVEL::response& res)
{
+ PERF_TIMER(on_set_log_level);
if (req.level < 0 || req.level > 4)
{
res.status = "Error: log level not valid";
@@ -864,6 +862,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_set_log_categories(const COMMAND_RPC_SET_LOG_CATEGORIES::request& req, COMMAND_RPC_SET_LOG_CATEGORIES::response& res)
{
+ PERF_TIMER(on_set_log_categories);
mlog_set_log(req.categories.c_str());
res.categories = mlog_get_categories();
res.status = CORE_RPC_STATUS_OK;
@@ -872,7 +871,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_transaction_pool(const COMMAND_RPC_GET_TRANSACTION_POOL::request& req, COMMAND_RPC_GET_TRANSACTION_POOL::response& res, bool request_has_rpc_origin)
{
- CHECK_CORE_BUSY();
+ PERF_TIMER(on_get_transaction_pool);
m_core.get_pool_transactions_and_spent_keys_info(res.transactions, res.spent_key_images, !request_has_rpc_origin || !m_restricted);
res.status = CORE_RPC_STATUS_OK;
return true;
@@ -880,7 +879,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_transaction_pool_hashes(const COMMAND_RPC_GET_TRANSACTION_POOL_HASHES::request& req, COMMAND_RPC_GET_TRANSACTION_POOL_HASHES::response& res, bool request_has_rpc_origin)
{
- CHECK_CORE_BUSY();
+ PERF_TIMER(on_get_transaction_pool_hashes);
m_core.get_pool_transaction_hashes(res.tx_hashes, !request_has_rpc_origin || !m_restricted);
res.status = CORE_RPC_STATUS_OK;
return true;
@@ -888,7 +887,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_transaction_pool_stats(const COMMAND_RPC_GET_TRANSACTION_POOL_STATS::request& req, COMMAND_RPC_GET_TRANSACTION_POOL_STATS::response& res, bool request_has_rpc_origin)
{
- CHECK_CORE_BUSY();
+ PERF_TIMER(on_get_transaction_pool_stats);
m_core.get_pool_transaction_stats(res.pool_stats, !request_has_rpc_origin || !m_restricted);
res.status = CORE_RPC_STATUS_OK;
return true;
@@ -896,6 +895,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_stop_daemon(const COMMAND_RPC_STOP_DAEMON::request& req, COMMAND_RPC_STOP_DAEMON::response& res)
{
+ PERF_TIMER(on_stop_daemon);
// FIXME: replace back to original m_p2p.send_stop_signal() after
// investigating why that isn't working quite right.
m_p2p.send_stop_signal();
@@ -905,7 +905,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res)
{
- CHECK_CORE_BUSY();
+ PERF_TIMER(on_getblockcount);
res.count = m_core.get_current_blockchain_height();
res.status = CORE_RPC_STATUS_OK;
return true;
@@ -913,12 +913,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_getblockhash(const COMMAND_RPC_GETBLOCKHASH::request& req, COMMAND_RPC_GETBLOCKHASH::response& res, epee::json_rpc::error& error_resp)
{
- if(!check_core_busy())
- {
- error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
- error_resp.message = "Core is busy";
- return false;
- }
+ PERF_TIMER(on_getblockhash);
if(req.size() != 1)
{
error_resp.code = CORE_RPC_ERROR_CODE_WRONG_PARAM;
@@ -954,6 +949,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_getblocktemplate(const COMMAND_RPC_GETBLOCKTEMPLATE::request& req, COMMAND_RPC_GETBLOCKTEMPLATE::response& res, epee::json_rpc::error& error_resp)
{
+ PERF_TIMER(on_getblocktemplate);
if(!check_core_ready())
{
error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
@@ -995,7 +991,7 @@ namespace cryptonote
}
blobdata block_blob = t_serializable_object_to_blob(b);
crypto::public_key tx_pub_key = cryptonote::get_tx_pub_key_from_extra(b.miner_tx);
- if(tx_pub_key == null_pkey)
+ if(tx_pub_key == crypto::null_pkey)
{
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
error_resp.message = "Internal error: failed to create block template";
@@ -1028,6 +1024,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_submitblock(const COMMAND_RPC_SUBMITBLOCK::request& req, COMMAND_RPC_SUBMITBLOCK::response& res, epee::json_rpc::error& error_resp)
{
+ PERF_TIMER(on_submitblock);
CHECK_CORE_READY();
if(req.size()!=1)
{
@@ -1084,6 +1081,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::fill_block_header_response(const block& blk, bool orphan_status, uint64_t height, const crypto::hash& hash, block_header_response& response)
{
+ PERF_TIMER(fill_block_header_response);
response.major_version = blk.major_version;
response.minor_version = blk.minor_version;
response.timestamp = blk.timestamp;
@@ -1102,12 +1100,8 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_last_block_header(const COMMAND_RPC_GET_LAST_BLOCK_HEADER::request& req, COMMAND_RPC_GET_LAST_BLOCK_HEADER::response& res, epee::json_rpc::error& error_resp)
{
- if(!check_core_busy())
- {
- error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
- error_resp.message = "Core is busy.";
- return false;
- }
+ PERF_TIMER(on_get_last_block_header);
+ CHECK_CORE_READY();
uint64_t last_block_height;
crypto::hash last_block_hash;
m_core.get_blockchain_top(last_block_height, last_block_hash);
@@ -1131,12 +1125,7 @@ namespace cryptonote
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_block_header_by_hash(const COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::request& req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::response& res, epee::json_rpc::error& error_resp){
- if(!check_core_busy())
- {
- error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
- error_resp.message = "Core is busy.";
- return false;
- }
+ PERF_TIMER(on_get_block_header_by_hash);
crypto::hash block_hash;
bool hash_parsed = parse_hash256(req.hash, block_hash);
if(!hash_parsed)
@@ -1173,12 +1162,7 @@ namespace cryptonote
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_block_headers_range(const COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::request& req, COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::response& res, epee::json_rpc::error& error_resp){
- if(!check_core_busy())
- {
- error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
- error_resp.message = "Core is busy.";
- return false;
- }
+ PERF_TIMER(on_get_block_headers_range);
const uint64_t bc_height = m_core.get_current_blockchain_height();
if (req.start_height >= bc_height || req.end_height >= bc_height || req.start_height > req.end_height)
{
@@ -1224,12 +1208,7 @@ namespace cryptonote
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_block_header_by_height(const COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::request& req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::response& res, epee::json_rpc::error& error_resp){
- if(!check_core_busy())
- {
- error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
- error_resp.message = "Core is busy.";
- return false;
- }
+ PERF_TIMER(on_get_block_header_by_height);
if(m_core.get_current_blockchain_height() <= req.height)
{
error_resp.code = CORE_RPC_ERROR_CODE_TOO_BIG_HEIGHT;
@@ -1257,12 +1236,7 @@ namespace cryptonote
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_block(const COMMAND_RPC_GET_BLOCK::request& req, COMMAND_RPC_GET_BLOCK::response& res, epee::json_rpc::error& error_resp){
- if(!check_core_busy())
- {
- error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
- error_resp.message = "Core is busy.";
- return false;
- }
+ PERF_TIMER(on_get_block);
crypto::hash block_hash;
if (!req.hash.empty())
{
@@ -1307,6 +1281,7 @@ namespace cryptonote
error_resp.message = "Internal error: can't produce valid response.";
return false;
}
+ res.miner_tx_hash = epee::string_tools::pod_to_hex(cryptonote::get_transaction_hash(blk.miner_tx));
for (size_t n = 0; n < blk.tx_hashes.size(); ++n)
{
res.tx_hashes.push_back(epee::string_tools::pod_to_hex(blk.tx_hashes[n]));
@@ -1319,12 +1294,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_connections(const COMMAND_RPC_GET_CONNECTIONS::request& req, COMMAND_RPC_GET_CONNECTIONS::response& res, epee::json_rpc::error& error_resp)
{
- if(!check_core_busy())
- {
- error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
- error_resp.message = "Core is busy.";
- return false;
- }
+ PERF_TIMER(on_get_connections);
res.connections = m_p2p.get_payload_object().get_connections();
@@ -1335,12 +1305,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_info_json(const COMMAND_RPC_GET_INFO::request& req, COMMAND_RPC_GET_INFO::response& res, epee::json_rpc::error& error_resp)
{
- if(!check_core_busy())
- {
- error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
- error_resp.message = "Core is busy.";
- return false;
- }
+ PERF_TIMER(on_get_info_json);
crypto::hash top_hash;
m_core.get_blockchain_top(res.height, top_hash);
@@ -1355,6 +1320,7 @@ namespace cryptonote
uint64_t total_conn = m_p2p.get_connections_count();
res.outgoing_connections_count = m_p2p.get_outgoing_connections_count();
res.incoming_connections_count = total_conn - res.outgoing_connections_count;
+ res.rpc_connections_count = get_connections_count();
res.white_peerlist_size = m_p2p.get_peerlist_manager().get_white_peers_count();
res.grey_peerlist_size = m_p2p.get_peerlist_manager().get_gray_peers_count();
res.testnet = m_testnet;
@@ -1367,12 +1333,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_hard_fork_info(const COMMAND_RPC_HARD_FORK_INFO::request& req, COMMAND_RPC_HARD_FORK_INFO::response& res, epee::json_rpc::error& error_resp)
{
- if(!check_core_busy())
- {
- error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
- error_resp.message = "Core is busy.";
- return false;
- }
+ PERF_TIMER(on_hard_fork_info);
const Blockchain &blockchain = m_core.get_blockchain_storage();
uint8_t version = req.version > 0 ? req.version : blockchain.get_next_hard_fork_version();
@@ -1385,12 +1346,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_bans(const COMMAND_RPC_GETBANS::request& req, COMMAND_RPC_GETBANS::response& res, epee::json_rpc::error& error_resp)
{
- if(!check_core_busy())
- {
- error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
- error_resp.message = "Core is busy.";
- return false;
- }
+ PERF_TIMER(on_get_bans);
auto now = time(nullptr);
std::map<std::string, time_t> blocked_hosts = m_p2p.get_blocked_hosts();
@@ -1414,12 +1370,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_set_bans(const COMMAND_RPC_SETBANS::request& req, COMMAND_RPC_SETBANS::response& res, epee::json_rpc::error& error_resp)
{
- if(!check_core_busy())
- {
- error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
- error_resp.message = "Core is busy.";
- return false;
- }
+ PERF_TIMER(on_set_bans);
for (auto i = req.bans.begin(); i != req.bans.end(); ++i)
{
@@ -1449,12 +1400,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_flush_txpool(const COMMAND_RPC_FLUSH_TRANSACTION_POOL::request& req, COMMAND_RPC_FLUSH_TRANSACTION_POOL::response& res, epee::json_rpc::error& error_resp)
{
- if(!check_core_busy())
- {
- error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
- error_resp.message = "Core is busy.";
- return false;
- }
+ PERF_TIMER(on_flush_txpool);
bool failed = false;
std::list<crypto::hash> txids;
@@ -1503,12 +1449,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_output_histogram(const COMMAND_RPC_GET_OUTPUT_HISTOGRAM::request& req, COMMAND_RPC_GET_OUTPUT_HISTOGRAM::response& res, epee::json_rpc::error& error_resp)
{
- if(!check_core_busy())
- {
- error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
- error_resp.message = "Core is busy.";
- return false;
- }
+ PERF_TIMER(on_get_output_histogram);
std::map<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t>> histogram;
try
@@ -1535,6 +1476,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_version(const COMMAND_RPC_GET_VERSION::request& req, COMMAND_RPC_GET_VERSION::response& res, epee::json_rpc::error& error_resp)
{
+ PERF_TIMER(on_get_version);
res.version = CORE_RPC_VERSION;
res.status = CORE_RPC_STATUS_OK;
return true;
@@ -1542,6 +1484,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_coinbase_tx_sum(const COMMAND_RPC_GET_COINBASE_TX_SUM::request& req, COMMAND_RPC_GET_COINBASE_TX_SUM::response& res, epee::json_rpc::error& error_resp)
{
+ PERF_TIMER(on_get_coinbase_tx_sum);
std::pair<uint64_t, uint64_t> amounts = m_core.get_coinbase_tx_sum(req.height, req.count);
res.emission_amount = amounts.first;
res.fee_amount = amounts.second;
@@ -1551,6 +1494,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_per_kb_fee_estimate(const COMMAND_RPC_GET_PER_KB_FEE_ESTIMATE::request& req, COMMAND_RPC_GET_PER_KB_FEE_ESTIMATE::response& res, epee::json_rpc::error& error_resp)
{
+ PERF_TIMER(on_get_per_kb_fee_estimate);
res.fee = m_core.get_blockchain_storage().get_dynamic_per_kb_fee_estimate(req.grace_blocks);
res.status = CORE_RPC_STATUS_OK;
return true;
@@ -1558,6 +1502,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_alternate_chains(const COMMAND_RPC_GET_ALTERNATE_CHAINS::request& req, COMMAND_RPC_GET_ALTERNATE_CHAINS::response& res, epee::json_rpc::error& error_resp)
{
+ PERF_TIMER(on_get_alternate_chains);
try
{
std::list<std::pair<Blockchain::block_extended_info, uint64_t>> chains = m_core.get_blockchain_storage().get_alternative_chains();
@@ -1576,6 +1521,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_limit(const COMMAND_RPC_GET_LIMIT::request& req, COMMAND_RPC_GET_LIMIT::response& res)
{
+ PERF_TIMER(on_get_limit);
res.limit_down = epee::net_utils::connection_basic::get_rate_down_limit();
res.limit_up = epee::net_utils::connection_basic::get_rate_up_limit();
res.status = CORE_RPC_STATUS_OK;
@@ -1584,6 +1530,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_set_limit(const COMMAND_RPC_SET_LIMIT::request& req, COMMAND_RPC_SET_LIMIT::response& res)
{
+ PERF_TIMER(on_set_limit);
// -1 = reset to default
// 0 = do not modify
@@ -1623,6 +1570,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_out_peers(const COMMAND_RPC_OUT_PEERS::request& req, COMMAND_RPC_OUT_PEERS::response& res)
{
+ PERF_TIMER(on_out_peers);
size_t n_connections = m_p2p.get_outgoing_connections_count();
size_t n_delete = (n_connections > req.out_peers) ? n_connections - req.out_peers : 0;
m_p2p.m_config.m_net_config.connections_count = req.out_peers;
@@ -1634,6 +1582,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_start_save_graph(const COMMAND_RPC_START_SAVE_GRAPH::request& req, COMMAND_RPC_START_SAVE_GRAPH::response& res)
{
+ PERF_TIMER(on_start_save_graph);
m_p2p.set_save_graph(true);
res.status = CORE_RPC_STATUS_OK;
return true;
@@ -1641,6 +1590,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_stop_save_graph(const COMMAND_RPC_STOP_SAVE_GRAPH::request& req, COMMAND_RPC_STOP_SAVE_GRAPH::response& res)
{
+ PERF_TIMER(on_stop_save_graph);
m_p2p.set_save_graph(false);
res.status = CORE_RPC_STATUS_OK;
return true;
@@ -1648,6 +1598,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_update(const COMMAND_RPC_UPDATE::request& req, COMMAND_RPC_UPDATE::response& res)
{
+ PERF_TIMER(on_update);
static const char software[] = "monero";
#ifdef BUILD_TAG
static const char buildtag[] = BOOST_PP_STRINGIZE(BUILD_TAG);
@@ -1742,12 +1693,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_relay_tx(const COMMAND_RPC_RELAY_TX::request& req, COMMAND_RPC_RELAY_TX::response& res, epee::json_rpc::error& error_resp)
{
- if(!check_core_busy())
- {
- error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
- error_resp.message = "Core is busy.";
- return false;
- }
+ PERF_TIMER(on_relay_tx);
bool failed = false;
for (const auto &str: req.txids)
@@ -1788,12 +1734,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_sync_info(const COMMAND_RPC_SYNC_INFO::request& req, COMMAND_RPC_SYNC_INFO::response& res, epee::json_rpc::error& error_resp)
{
- if(!check_core_busy())
- {
- error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
- error_resp.message = "Core is busy.";
- return false;
- }
+ PERF_TIMER(on_sync_info);
crypto::hash top_hash;
m_core.get_blockchain_top(res.height, top_hash);
@@ -1819,12 +1760,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_txpool_backlog(const COMMAND_RPC_GET_TRANSACTION_POOL_BACKLOG::request& req, COMMAND_RPC_GET_TRANSACTION_POOL_BACKLOG::response& res, epee::json_rpc::error& error_resp)
{
- if(!check_core_busy())
- {
- error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
- error_resp.message = "Core is busy.";
- return false;
- }
+ PERF_TIMER(on_get_txpool_backlog);
if (!m_core.get_txpool_backlog(res.backlog))
{
diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h
index 57799bb81..15b4b503a 100644
--- a/src/rpc/core_rpc_server_commands_defs.h
+++ b/src/rpc/core_rpc_server_commands_defs.h
@@ -49,7 +49,7 @@ namespace cryptonote
// advance which version they will stop working with
// Don't go over 32767 for any of these
#define CORE_RPC_VERSION_MAJOR 1
-#define CORE_RPC_VERSION_MINOR 15
+#define CORE_RPC_VERSION_MINOR 16
#define MAKE_CORE_RPC_VERSION(major,minor) (((major)<<16)|(minor))
#define CORE_RPC_VERSION MAKE_CORE_RPC_VERSION(CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR)
@@ -919,6 +919,7 @@ namespace cryptonote
uint64_t alt_blocks_count;
uint64_t outgoing_connections_count;
uint64_t incoming_connections_count;
+ uint64_t rpc_connections_count;
uint64_t white_peerlist_size;
uint64_t grey_peerlist_size;
bool testnet;
@@ -938,6 +939,7 @@ namespace cryptonote
KV_SERIALIZE(alt_blocks_count)
KV_SERIALIZE(outgoing_connections_count)
KV_SERIALIZE(incoming_connections_count)
+ KV_SERIALIZE(rpc_connections_count)
KV_SERIALIZE(white_peerlist_size)
KV_SERIALIZE(grey_peerlist_size)
KV_SERIALIZE(testnet)
@@ -1219,12 +1221,14 @@ namespace cryptonote
{
std::string status;
block_header_response block_header;
+ std::string miner_tx_hash;
std::vector<std::string> tx_hashes;
std::string blob;
std::string json;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(block_header)
+ KV_SERIALIZE(miner_tx_hash)
KV_SERIALIZE(tx_hashes)
KV_SERIALIZE(status)
KV_SERIALIZE(blob)
diff --git a/src/rpc/rpc_args.cpp b/src/rpc/rpc_args.cpp
index 93309bf3c..e03c5472d 100755..100644
--- a/src/rpc/rpc_args.cpp
+++ b/src/rpc/rpc_args.cpp
@@ -83,7 +83,9 @@ namespace cryptonote
if (command_line::has_arg(vm, arg.rpc_login))
{
- config.login = tools::login::parse(command_line::get_arg(vm, arg.rpc_login), true, "RPC server password");
+ config.login = tools::login::parse(command_line::get_arg(vm, arg.rpc_login), true, [](bool verify) {
+ return tools::password_container::prompt(verify, "RPC server password");
+ });
if (!config.login)
return boost::none;
diff --git a/src/rpc/rpc_args.h b/src/rpc/rpc_args.h
index 72b5aa706..72b5aa706 100755..100644
--- a/src/rpc/rpc_args.h
+++ b/src/rpc/rpc_args.h
diff --git a/src/simplewallet/CMakeLists.txt b/src/simplewallet/CMakeLists.txt
index b56085b8f..3ff4466fc 100644
--- a/src/simplewallet/CMakeLists.txt
+++ b/src/simplewallet/CMakeLists.txt
@@ -48,12 +48,14 @@ target_link_libraries(simplewallet
cncrypto
common
mnemonics
- p2p
+ epee
+ ${EPEE_READLINE}
version
${Boost_CHRONO_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY}
+ ${Readline_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
${EXTRA_LIBRARIES})
set_property(TARGET simplewallet
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 24e7d54dd..abf2f2aef 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -49,7 +49,6 @@
#include "common/dns_utils.h"
#include "common/base58.h"
#include "common/scoped_message_writer.h"
-#include "p2p/net_node.h"
#include "cryptonote_protocol/cryptonote_protocol_handler.h"
#include "simplewallet.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
@@ -126,6 +125,37 @@ namespace
const command_line::arg_descriptor< std::vector<std::string> > arg_command = {"command", ""};
+ std::string input_line(const std::string& prompt)
+ {
+#ifdef HAVE_READLINE
+ rdln::suspend_readline pause_readline;
+#endif
+ std::cout << prompt;
+
+ std::string buf;
+ std::getline(std::cin, buf);
+
+ return epee::string_tools::trim(buf);
+ }
+
+ boost::optional<tools::password_container> password_prompter(const char *prompt, bool verify)
+ {
+#ifdef HAVE_READLINE
+ rdln::suspend_readline pause_readline;
+#endif
+ auto pwd_container = tools::password_container::prompt(verify, prompt);
+ if (!pwd_container)
+ {
+ tools::fail_msg_writer() << tr("failed to read wallet password");
+ }
+ return pwd_container;
+ }
+
+ boost::optional<tools::password_container> default_password_prompter(bool verify)
+ {
+ return password_prompter(verify ? tr("Enter new wallet password") : tr("Wallet password"), verify);
+ }
+
inline std::string interpret_rpc_response(bool ok, const std::string& status)
{
std::string err;
@@ -271,7 +301,7 @@ namespace
<< tr("Is this OK? (Y/n) ")
;
// prompt the user for confirmation given the dns query and dnssec status
- std::string confirm_dns_ok = command_line::input_line(prompt.str());
+ std::string confirm_dns_ok = input_line(prompt.str());
if (std::cin.eof())
{
return {};
@@ -449,7 +479,7 @@ bool simple_wallet::change_password(const std::vector<std::string> &args)
}
// prompts for a new password, pass true to verify the password
- const auto pwd_container = tools::wallet2::password_prompt(true);
+ const auto pwd_container = default_password_prompter(true);
try
{
@@ -1021,7 +1051,7 @@ bool simple_wallet::ask_wallet_create_if_needed()
do{
LOG_PRINT_L3("User asked to specify wallet file name.");
- wallet_path = command_line::input_line(
+ wallet_path = input_line(
tr(m_restoring ? "Specify a new wallet file name for your restored wallet (e.g., MyWallet).\n"
"Wallet file name (or Ctrl-C to quit): " :
"Specify wallet file name (e.g., MyWallet). If the wallet doesn't exist, it will be created.\n"
@@ -1072,7 +1102,7 @@ bool simple_wallet::ask_wallet_create_if_needed()
if (!m_restoring)
{
message_writer() << tr("No wallet found with that name. Confirm creation of new wallet named: ") << wallet_path;
- confirm_creation = command_line::input_line(tr("(Y/Yes/N/No): "));
+ confirm_creation = input_line(tr("(Y/Yes/N/No): "));
if(std::cin.eof())
{
LOG_ERROR("Unexpected std::cin.eof() - Exited simple_wallet::ask_wallet_create_if_needed()");
@@ -1156,7 +1186,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
do
{
const char *prompt = m_electrum_seed.empty() ? "Specify Electrum seed: " : "Electrum seed continued: ";
- std::string electrum_seed = command_line::input_line(prompt);
+ std::string electrum_seed = input_line(prompt);
if (std::cin.eof())
return false;
if (electrum_seed.empty())
@@ -1185,7 +1215,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
{
m_wallet_file = m_generate_from_view_key;
// parse address
- std::string address_string = command_line::input_line("Standard address: ");
+ std::string address_string = input_line("Standard address: ");
if (std::cin.eof())
return false;
if (address_string.empty()) {
@@ -1205,7 +1235,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
}
// parse view secret key
- std::string viewkey_string = command_line::input_line("View key: ");
+ std::string viewkey_string = input_line("View key: ");
if (std::cin.eof())
return false;
if (viewkey_string.empty()) {
@@ -1240,7 +1270,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
{
m_wallet_file = m_generate_from_spend_key;
// parse spend secret key
- std::string spendkey_string = command_line::input_line("Secret spend key: ");
+ std::string spendkey_string = input_line("Secret spend key: ");
if (std::cin.eof())
return false;
if (spendkey_string.empty()) {
@@ -1259,7 +1289,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
{
m_wallet_file = m_generate_from_keys;
// parse address
- std::string address_string = command_line::input_line("Standard address: ");
+ std::string address_string = input_line("Standard address: ");
if (std::cin.eof())
return false;
if (address_string.empty()) {
@@ -1279,7 +1309,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
}
// parse spend secret key
- std::string spendkey_string = command_line::input_line("Secret spend key: ");
+ std::string spendkey_string = input_line("Secret spend key: ");
if (std::cin.eof())
return false;
if (spendkey_string.empty()) {
@@ -1295,7 +1325,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
crypto::secret_key spendkey = *reinterpret_cast<const crypto::secret_key*>(spendkey_data.data());
// parse view secret key
- std::string viewkey_string = command_line::input_line("Secret view key: ");
+ std::string viewkey_string = input_line("Secret view key: ");
if (std::cin.eof())
return false;
if (viewkey_string.empty()) {
@@ -1342,7 +1372,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
unsigned int multisig_n;
// parse multisig type
- std::string multisig_type_string = command_line::input_line("Multisig type (input as M/N with M <= N and M > 1): ");
+ std::string multisig_type_string = input_line("Multisig type (input as M/N with M <= N and M > 1): ");
if (std::cin.eof())
return false;
if (multisig_type_string.empty())
@@ -1368,7 +1398,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
message_writer() << boost::format(tr("Generating master wallet from %u of %u multisig wallet keys")) % multisig_m % multisig_n;
// parse multisig address
- std::string address_string = command_line::input_line("Multisig wallet address: ");
+ std::string address_string = input_line("Multisig wallet address: ");
if (std::cin.eof())
return false;
if (address_string.empty()) {
@@ -1383,7 +1413,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
}
// parse secret view key
- std::string viewkey_string = command_line::input_line("Secret view key: ");
+ std::string viewkey_string = input_line("Secret view key: ");
if (std::cin.eof())
return false;
if (viewkey_string.empty())
@@ -1423,7 +1453,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
// get N secret spend keys from user
for(unsigned int i=0; i<multisig_n; ++i)
{
- spendkey_string = command_line::input_line(tr((boost::format(tr("Secret spend key (%u of %u):")) % (i+i) % multisig_m).str().c_str()));
+ spendkey_string = input_line(tr((boost::format(tr("Secret spend key (%u of %u):")) % (i+i) % multisig_m).str().c_str()));
if (std::cin.eof())
return false;
if (spendkey_string.empty())
@@ -1471,7 +1501,15 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
else if (!m_generate_from_json.empty())
{
m_wallet_file = m_generate_from_json;
- m_wallet = tools::wallet2::make_from_json(vm, m_wallet_file);
+ try
+ {
+ m_wallet = tools::wallet2::make_from_json(vm, m_wallet_file, password_prompter);
+ }
+ catch (const std::exception &e)
+ {
+ fail_msg_writer() << e.what();
+ return false;
+ }
if (!m_wallet)
return false;
}
@@ -1493,9 +1531,9 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
{
std::string heightstr;
if (!connected || version < MAKE_CORE_RPC_VERSION(1, 6))
- heightstr = command_line::input_line("Restore from specific blockchain height (optional, default 0): ");
+ heightstr = input_line("Restore from specific blockchain height (optional, default 0): ");
else
- heightstr = command_line::input_line("Restore from specific blockchain height (optional, default 0),\nor alternatively from specific date (YYYY-MM-DD): ");
+ heightstr = input_line("Restore from specific blockchain height (optional, default 0),\nor alternatively from specific date (YYYY-MM-DD): ");
if (std::cin.eof())
return false;
if (heightstr.empty())
@@ -1531,7 +1569,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
day = boost::lexical_cast<uint16_t>(heightstr.substr(8,2));
m_restore_height = m_wallet->get_blockchain_height_by_date(year, month, day);
success_msg_writer() << tr("Restore height is: ") << m_restore_height;
- std::string confirm = command_line::input_line(tr("Is this okay? (Y/Yes/N/No): "));
+ std::string confirm = input_line(tr("Is this okay? (Y/Yes/N/No): "));
if (std::cin.eof())
return false;
if(command_line::is_yes(confirm))
@@ -1662,7 +1700,7 @@ std::string simple_wallet::get_mnemonic_language()
}
while (language_number < 0)
{
- language_choice = command_line::input_line(tr("Enter the number corresponding to the language of your choice: "));
+ language_choice = input_line(tr("Enter the number corresponding to the language of your choice: "));
if (std::cin.eof())
return std::string();
try
@@ -1684,7 +1722,7 @@ std::string simple_wallet::get_mnemonic_language()
//----------------------------------------------------------------------------------------------------
boost::optional<tools::password_container> simple_wallet::get_and_verify_password() const
{
- auto pwd_container = tools::wallet2::password_prompt(m_wallet_file.empty());
+ auto pwd_container = default_password_prompter(m_wallet_file.empty());
if (!pwd_container)
return boost::none;
@@ -1699,7 +1737,7 @@ boost::optional<tools::password_container> simple_wallet::get_and_verify_passwor
bool simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
const crypto::secret_key& recovery_key, bool recover, bool two_random, const std::string &old_language)
{
- auto rc = tools::wallet2::make_new(vm);
+ auto rc = tools::wallet2::make_new(vm, password_prompter);
m_wallet = std::move(rc.first);
if (!m_wallet)
{
@@ -1780,7 +1818,7 @@ bool simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
const cryptonote::account_public_address& address, const boost::optional<crypto::secret_key>& spendkey,
const crypto::secret_key& viewkey)
{
- auto rc = tools::wallet2::make_new(vm);
+ auto rc = tools::wallet2::make_new(vm, password_prompter);
m_wallet = std::move(rc.first);
if (!m_wallet)
{
@@ -1822,7 +1860,7 @@ bool simple_wallet::open_wallet(const boost::program_options::variables_map& vm)
std::string password;
try
{
- auto rc = tools::wallet2::make_from_file(vm, m_wallet_file);
+ auto rc = tools::wallet2::make_from_file(vm, m_wallet_file, password_prompter);
m_wallet = std::move(rc.first);
password = std::move(rc.second).password();
if (!m_wallet)
@@ -2553,6 +2591,101 @@ bool simple_wallet::print_ring_members(const std::vector<tools::wallet2::pending
return true;
}
//----------------------------------------------------------------------------------------------------
+static void handle_transfer_exception(const std::exception_ptr &e)
+{
+ try
+ {
+ std::rethrow_exception(e);
+ }
+ catch (const tools::error::daemon_busy&)
+ {
+ fail_msg_writer() << tr("daemon is busy. Please try again later.");
+ }
+ catch (const tools::error::no_connection_to_daemon&)
+ {
+ fail_msg_writer() << tr("no connection to daemon. Please make sure daemon is running.");
+ }
+ catch (const tools::error::wallet_rpc_error& e)
+ {
+ LOG_ERROR("RPC error: " << e.to_string());
+ fail_msg_writer() << tr("RPC error: ") << e.what();
+ }
+ catch (const tools::error::get_random_outs_error &e)
+ {
+ fail_msg_writer() << tr("failed to get random outputs to mix: ") << e.what();
+ }
+ catch (const tools::error::not_enough_unlocked_money& e)
+ {
+ LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, sent amount %s") %
+ print_money(e.available()) %
+ print_money(e.tx_amount()));
+ fail_msg_writer() << tr("Not enough money in unlocked balance");
+ }
+ catch (const tools::error::not_enough_money& e)
+ {
+ LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, sent amount %s") %
+ print_money(e.available()) %
+ print_money(e.tx_amount()));
+ fail_msg_writer() << tr("Not enough money in unlocked balance");
+ }
+ catch (const tools::error::tx_not_possible& e)
+ {
+ LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee)") %
+ print_money(e.available()) %
+ print_money(e.tx_amount() + e.fee()) %
+ print_money(e.tx_amount()) %
+ print_money(e.fee()));
+ fail_msg_writer() << tr("Failed to find a way to create transactions. This is usually due to dust which is so small it cannot pay for itself in fees, or trying to send more money than the unlocked balance, or not leaving enough for fees");
+ }
+ catch (const tools::error::not_enough_outs_to_mix& e)
+ {
+ auto writer = fail_msg_writer();
+ writer << tr("not enough outputs for specified ring size") << " = " << (e.mixin_count() + 1) << ":";
+ for (std::pair<uint64_t, uint64_t> outs_for_amount : e.scanty_outs())
+ {
+ writer << "\n" << tr("output amount") << " = " << print_money(outs_for_amount.first) << ", " << tr("found outputs to use") << " = " << outs_for_amount.second;
+ }
+ }
+ catch (const tools::error::tx_not_constructed&)
+ {
+ fail_msg_writer() << tr("transaction was not constructed");
+ }
+ catch (const tools::error::tx_rejected& e)
+ {
+ fail_msg_writer() << (boost::format(tr("transaction %s was rejected by daemon with status: ")) % get_transaction_hash(e.tx())) << e.status();
+ std::string reason = e.reason();
+ if (!reason.empty())
+ fail_msg_writer() << tr("Reason: ") << reason;
+ }
+ catch (const tools::error::tx_sum_overflow& e)
+ {
+ fail_msg_writer() << e.what();
+ }
+ catch (const tools::error::zero_destination&)
+ {
+ fail_msg_writer() << tr("one of destinations is zero");
+ }
+ catch (const tools::error::tx_too_big& e)
+ {
+ fail_msg_writer() << tr("failed to find a suitable way to split transactions");
+ }
+ catch (const tools::error::transfer_error& e)
+ {
+ LOG_ERROR("unknown transfer error: " << e.to_string());
+ fail_msg_writer() << tr("unknown transfer error: ") << e.what();
+ }
+ catch (const tools::error::wallet_internal_error& e)
+ {
+ LOG_ERROR("internal error: " << e.to_string());
+ fail_msg_writer() << tr("internal error: ") << e.what();
+ }
+ catch (const std::exception& e)
+ {
+ LOG_ERROR("unexpected error: " << e.what());
+ fail_msg_writer() << tr("unexpected error: ") << e.what();
+ }
+}
+//----------------------------------------------------------------------------------------------------
bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::string> &args_)
{
// "transfer [index=<N1>[,<N2>,...]] [<priority>] [<ring_size>] <address> <amount> [<payment_id>]"
@@ -2585,12 +2718,23 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
if (fake_outs_count == 0)
fake_outs_count = DEFAULT_MIX;
}
+ else if (ring_size == 0)
+ {
+ fail_msg_writer() << tr("Ring size must not be 0");
+ return true;
+ }
else
{
fake_outs_count = ring_size - 1;
local_args.erase(local_args.begin());
}
}
+ uint64_t adjusted_fake_outs_count = m_wallet->adjust_mixin(fake_outs_count);
+ if (adjusted_fake_outs_count > fake_outs_count)
+ {
+ fail_msg_writer() << (boost::format(tr("ring size %u is too small, minimum is %u")) % (fake_outs_count+1) % (adjusted_fake_outs_count+1)).str();
+ return true;
+ }
const size_t min_args = (transfer_type == TransferLocked) ? 3 : 2;
if(local_args.size() < min_args)
@@ -2701,7 +2845,7 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
// prompt is there is no payment id and confirmation is required
if (!payment_id_seen && m_wallet->confirm_missing_payment_id())
{
- std::string accepted = command_line::input_line(tr("No payment id is included with this transaction. Is this okay? (Y/Yes/N/No): "));
+ std::string accepted = input_line(tr("No payment id is included with this transaction. Is this okay? (Y/Yes/N/No): "));
if (std::cin.eof())
return true;
if (!command_line::is_yes(accepted))
@@ -2785,7 +2929,7 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
std::string prompt_str = prompt.str();
if (!prompt_str.empty())
{
- std::string accepted = command_line::input_line(prompt_str);
+ std::string accepted = input_line(prompt_str);
if (std::cin.eof())
return true;
if (!command_line::is_yes(accepted))
@@ -2856,7 +3000,7 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
}
prompt << ENDL << tr("Is this okay? (Y/Yes/N/No): ");
- std::string accepted = command_line::input_line(prompt.str());
+ std::string accepted = input_line(prompt.str());
if (std::cin.eof())
return true;
if (!command_line::is_yes(accepted))
@@ -2885,92 +3029,9 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
commit_or_save(ptx_vector, m_do_not_relay);
}
}
- catch (const tools::error::daemon_busy&)
- {
- fail_msg_writer() << tr("daemon is busy. Please try again later.");
- }
- catch (const tools::error::no_connection_to_daemon&)
- {
- fail_msg_writer() << tr("no connection to daemon. Please make sure daemon is running.");
- }
- catch (const tools::error::wallet_rpc_error& e)
- {
- LOG_ERROR("RPC error: " << e.to_string());
- fail_msg_writer() << tr("RPC error: ") << e.what();
- }
- catch (const tools::error::get_random_outs_error &e)
- {
- fail_msg_writer() << tr("failed to get random outputs to mix: ") << e.what();
- }
- catch (const tools::error::not_enough_unlocked_money& e)
- {
- LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, sent amount %s") %
- print_money(e.available()) %
- print_money(e.tx_amount()));
- fail_msg_writer() << tr("Not enough money in unlocked balance");
- }
- catch (const tools::error::not_enough_money& e)
- {
- LOG_PRINT_L0(boost::format("not enough money to transfer, overall balance only %s, sent amount %s") %
- print_money(e.available()) %
- print_money(e.tx_amount()));
- fail_msg_writer() << tr("Not enough money in overall balance");
- }
- catch (const tools::error::tx_not_possible& e)
- {
- LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee)") %
- print_money(e.available()) %
- print_money(e.tx_amount() + e.fee()) %
- print_money(e.tx_amount()) %
- print_money(e.fee()));
- fail_msg_writer() << tr("Failed to find a way to create transactions. This is usually due to dust which is so small it cannot pay for itself in fees, or trying to send more money than the unlocked balance, or not leaving enough for fees");
- }
- catch (const tools::error::not_enough_outs_to_mix& e)
- {
- auto writer = fail_msg_writer();
- writer << tr("not enough outputs for specified ring size") << " = " << (e.mixin_count() + 1) << ":";
- for (std::pair<uint64_t, uint64_t> outs_for_amount : e.scanty_outs())
- {
- writer << "\n" << tr("output amount") << " = " << print_money(outs_for_amount.first) << ", " << tr("found outputs to use") << " = " << outs_for_amount.second;
- }
- }
- catch (const tools::error::tx_not_constructed&)
- {
- fail_msg_writer() << tr("transaction was not constructed");
- }
- catch (const tools::error::tx_rejected& e)
- {
- fail_msg_writer() << (boost::format(tr("transaction %s was rejected by daemon with status: ")) % get_transaction_hash(e.tx())) << e.status();
- std::string reason = e.reason();
- if (!reason.empty())
- fail_msg_writer() << tr("Reason: ") << reason;
- }
- catch (const tools::error::tx_sum_overflow& e)
- {
- fail_msg_writer() << e.what();
- }
- catch (const tools::error::zero_destination&)
- {
- fail_msg_writer() << tr("one of destinations is zero");
- }
- catch (const tools::error::tx_too_big& e)
- {
- fail_msg_writer() << tr("failed to find a suitable way to split transactions");
- }
- catch (const tools::error::transfer_error& e)
- {
- LOG_ERROR("unknown transfer error: " << e.to_string());
- fail_msg_writer() << tr("unknown transfer error: ") << e.what();
- }
- catch (const tools::error::wallet_internal_error& e)
- {
- LOG_ERROR("internal error: " << e.to_string());
- fail_msg_writer() << tr("internal error: ") << e.what();
- }
- catch (const std::exception& e)
+ catch (const std::exception &e)
{
- LOG_ERROR("unexpected error: " << e.what());
- fail_msg_writer() << tr("unexpected error: ") << e.what();
+ handle_transfer_exception(std::current_exception());
}
catch (...)
{
@@ -3036,7 +3097,7 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
print_money(total_unmixable) %
print_money(total_fee)).str();
}
- std::string accepted = command_line::input_line(prompt_str);
+ std::string accepted = input_line(prompt_str);
if (std::cin.eof())
return true;
if (!command_line::is_yes(accepted))
@@ -3064,92 +3125,9 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
commit_or_save(ptx_vector, m_do_not_relay);
}
}
- catch (const tools::error::daemon_busy&)
- {
- fail_msg_writer() << tr("daemon is busy. Please try again later.");
- }
- catch (const tools::error::no_connection_to_daemon&)
- {
- fail_msg_writer() << tr("no connection to daemon. Please make sure daemon is running.");
- }
- catch (const tools::error::wallet_rpc_error& e)
- {
- LOG_ERROR("RPC error: " << e.to_string());
- fail_msg_writer() << tr("RPC error: ") << e.what();
- }
- catch (const tools::error::get_random_outs_error &e)
- {
- fail_msg_writer() << tr("failed to get random outputs to mix: ") << e.what();
- }
- catch (const tools::error::not_enough_unlocked_money& e)
- {
- LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, sent amount %s") %
- print_money(e.available()) %
- print_money(e.tx_amount()));
- fail_msg_writer() << tr("Not enough money in unlocked balance");
- }
- catch (const tools::error::not_enough_money& e)
- {
- LOG_PRINT_L0(boost::format("not enough money to transfer, overall balance only %s, sent amount %s") %
- print_money(e.available()) %
- print_money(e.tx_amount()));
- fail_msg_writer() << tr("Not enough money in overall balance");
- }
- catch (const tools::error::tx_not_possible& e)
- {
- LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee)") %
- print_money(e.available()) %
- print_money(e.tx_amount() + e.fee()) %
- print_money(e.tx_amount()) %
- print_money(e.fee()));
- fail_msg_writer() << tr("Failed to find a way to create transactions. This is usually due to dust which is so small it cannot pay for itself in fees, or trying to send more money than the unlocked balance, or not leaving enough for fees");
- }
- catch (const tools::error::not_enough_outs_to_mix& e)
- {
- auto writer = fail_msg_writer();
- writer << tr("not enough outputs for specified ring size") << " = " << (e.mixin_count() + 1) << ":";
- for (std::pair<uint64_t, uint64_t> outs_for_amount : e.scanty_outs())
- {
- writer << "\n" << tr("output amount") << " = " << print_money(outs_for_amount.first) << ", " << tr("found outputs to use") << " = " << outs_for_amount.second;
- }
- }
- catch (const tools::error::tx_not_constructed&)
- {
- fail_msg_writer() << tr("transaction was not constructed");
- }
- catch (const tools::error::tx_rejected& e)
- {
- fail_msg_writer() << (boost::format(tr("transaction %s was rejected by daemon with status: ")) % get_transaction_hash(e.tx())) << e.status();
- std::string reason = e.reason();
- if (!reason.empty())
- fail_msg_writer() << tr("Reason: ") << reason;
- }
- catch (const tools::error::tx_sum_overflow& e)
- {
- fail_msg_writer() << e.what();
- }
- catch (const tools::error::zero_destination&)
- {
- fail_msg_writer() << tr("one of destinations is zero");
- }
- catch (const tools::error::tx_too_big& e)
- {
- fail_msg_writer() << tr("failed to find a suitable way to split transactions");
- }
- catch (const tools::error::transfer_error& e)
- {
- LOG_ERROR("unknown transfer error: " << e.to_string());
- fail_msg_writer() << tr("unknown transfer error: ") << e.what();
- }
- catch (const tools::error::wallet_internal_error& e)
- {
- LOG_ERROR("internal error: " << e.to_string());
- fail_msg_writer() << tr("internal error: ") << e.what();
- }
- catch (const std::exception& e)
+ catch (const std::exception &e)
{
- LOG_ERROR("unexpected error: " << e.what());
- fail_msg_writer() << tr("unexpected error: ") << e.what();
+ handle_transfer_exception(std::current_exception());
}
catch (...)
{
@@ -3163,6 +3141,12 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
bool simple_wallet::sweep_main(uint64_t below, const std::vector<std::string> &args_)
{
// sweep_all [index=<N1>[,<N2>,...]] [<ring_size>] <address> [<payment_id>]
+ if (args_.size() == 0)
+ {
+ fail_msg_writer() << tr("No address given");
+ return true;
+ }
+
if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
if (!try_connect_to_daemon())
return true;
@@ -3190,12 +3174,23 @@ bool simple_wallet::sweep_main(uint64_t below, const std::vector<std::string> &a
if (fake_outs_count == 0)
fake_outs_count = DEFAULT_MIX;
}
+ else if (ring_size == 0)
+ {
+ fail_msg_writer() << tr("Ring size must not be 0");
+ return true;
+ }
else
{
fake_outs_count = ring_size - 1;
local_args.erase(local_args.begin());
}
}
+ uint64_t adjusted_fake_outs_count = m_wallet->adjust_mixin(fake_outs_count);
+ if (adjusted_fake_outs_count > fake_outs_count)
+ {
+ fail_msg_writer() << (boost::format(tr("ring size %u is too small, minimum is %u")) % (fake_outs_count+1) % (adjusted_fake_outs_count+1)).str();
+ return true;
+ }
std::vector<uint8_t> extra;
bool payment_id_seen = false;
@@ -3234,12 +3229,6 @@ bool simple_wallet::sweep_main(uint64_t below, const std::vector<std::string> &a
local_args.pop_back();
}
- if (local_args.size() == 0)
- {
- fail_msg_writer() << tr("No address given");
- return true;
- }
-
cryptonote::address_parse_info info;
if (!cryptonote::get_account_address_from_str_or_url(info, m_wallet->testnet(), local_args[0], oa_prompter))
{
@@ -3269,7 +3258,7 @@ bool simple_wallet::sweep_main(uint64_t below, const std::vector<std::string> &a
// prompt is there is no payment id and confirmation is required
if (!payment_id_seen && m_wallet->confirm_missing_payment_id())
{
- std::string accepted = command_line::input_line(tr("No payment id is included with this transaction. Is this okay? (Y/Yes/N/No): "));
+ std::string accepted = input_line(tr("No payment id is included with this transaction. Is this okay? (Y/Yes/N/No): "));
if (std::cin.eof())
return true;
if (!command_line::is_yes(accepted))
@@ -3327,7 +3316,7 @@ bool simple_wallet::sweep_main(uint64_t below, const std::vector<std::string> &a
print_money(total_sent) %
print_money(total_fee);
}
- std::string accepted = command_line::input_line(prompt.str());
+ std::string accepted = input_line(prompt.str());
if (std::cin.eof())
return true;
if (!command_line::is_yes(accepted))
@@ -3355,92 +3344,9 @@ bool simple_wallet::sweep_main(uint64_t below, const std::vector<std::string> &a
commit_or_save(ptx_vector, m_do_not_relay);
}
}
- catch (const tools::error::daemon_busy&)
- {
- fail_msg_writer() << tr("daemon is busy. Please try again later.");
- }
- catch (const tools::error::no_connection_to_daemon&)
- {
- fail_msg_writer() << tr("no connection to daemon. Please make sure daemon is running.");
- }
- catch (const tools::error::wallet_rpc_error& e)
- {
- LOG_ERROR("RPC error: " << e.to_string());
- fail_msg_writer() << tr("RPC error: ") << e.what();
- }
- catch (const tools::error::get_random_outs_error &e)
- {
- fail_msg_writer() << tr("failed to get random outputs to mix: ") << e.what();
- }
- catch (const tools::error::not_enough_unlocked_money& e)
- {
- LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, sent amount %s") %
- print_money(e.available()) %
- print_money(e.tx_amount()));
- fail_msg_writer() << tr("Not enough money in unlocked balance");
- }
- catch (const tools::error::not_enough_money& e)
- {
- LOG_PRINT_L0(boost::format("not enough money to transfer, overall balance only %s, sent amount %s") %
- print_money(e.available()) %
- print_money(e.tx_amount()));
- fail_msg_writer() << tr("Not enough money in overall balance");
- }
- catch (const tools::error::tx_not_possible& e)
- {
- LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee)") %
- print_money(e.available()) %
- print_money(e.tx_amount() + e.fee()) %
- print_money(e.tx_amount()) %
- print_money(e.fee()));
- fail_msg_writer() << tr("Failed to find a way to create transactions. This is usually due to dust which is so small it cannot pay for itself in fees, or trying to send more money than the unlocked balance, or not leaving enough for fees");
- }
- catch (const tools::error::not_enough_outs_to_mix& e)
- {
- auto writer = fail_msg_writer();
- writer << tr("not enough outputs for specified ring size") << " = " << (e.mixin_count() + 1) << ":";
- for (std::pair<uint64_t, uint64_t> outs_for_amount : e.scanty_outs())
- {
- writer << "\n" << tr("output amount") << " = " << print_money(outs_for_amount.first) << ", " << tr("found outputs to use") << " = " << outs_for_amount.second;
- }
- }
- catch (const tools::error::tx_not_constructed&)
- {
- fail_msg_writer() << tr("transaction was not constructed");
- }
- catch (const tools::error::tx_rejected& e)
- {
- fail_msg_writer() << (boost::format(tr("transaction %s was rejected by daemon with status: ")) % get_transaction_hash(e.tx())) << e.status();
- std::string reason = e.reason();
- if (!reason.empty())
- fail_msg_writer() << tr("Reason: ") << reason;
- }
- catch (const tools::error::tx_sum_overflow& e)
- {
- fail_msg_writer() << e.what();
- }
- catch (const tools::error::zero_destination&)
- {
- fail_msg_writer() << tr("one of destinations is zero");
- }
- catch (const tools::error::tx_too_big& e)
- {
- fail_msg_writer() << tr("failed to find a suitable way to split transactions");
- }
- catch (const tools::error::transfer_error& e)
- {
- LOG_ERROR("unknown transfer error: " << e.to_string());
- fail_msg_writer() << tr("unknown transfer error: ") << e.what();
- }
- catch (const tools::error::wallet_internal_error& e)
- {
- LOG_ERROR("internal error: " << e.to_string());
- fail_msg_writer() << tr("internal error: ") << e.what();
- }
catch (const std::exception& e)
{
- LOG_ERROR("unexpected error: " << e.what());
- fail_msg_writer() << tr("unexpected error: ") << e.what();
+ handle_transfer_exception(std::current_exception());
}
catch (...)
{
@@ -3623,7 +3529,7 @@ bool simple_wallet::accept_loaded_tx(const std::function<size_t()> get_num_txes,
uint64_t fee = amount - amount_to_dests;
std::string prompt_str = (boost::format(tr("Loaded %lu transactions, for %s, fee %s, %s, %s, with min ring size %lu, %s. %sIs this okay? (Y/Yes/N/No): ")) % (unsigned long)get_num_txes() % print_money(amount) % print_money(fee) % dest_string % change_string % (unsigned long)min_ring_size % payment_id_string % extra_message).str();
- return command_line::is_yes(command_line::input_line(prompt_str));
+ return command_line::is_yes(input_line(prompt_str));
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::accept_loaded_tx(const tools::wallet2::unsigned_tx_set &txs)
@@ -3712,92 +3618,9 @@ bool simple_wallet::submit_transfer(const std::vector<std::string> &args_)
commit_or_save(ptx_vector, false);
}
- catch (const tools::error::daemon_busy&)
- {
- fail_msg_writer() << tr("daemon is busy. Please try later");
- }
- catch (const tools::error::no_connection_to_daemon&)
- {
- fail_msg_writer() << tr("no connection to daemon. Please, make sure daemon is running.");
- }
- catch (const tools::error::wallet_rpc_error& e)
- {
- LOG_ERROR("Unknown RPC error: " << e.to_string());
- fail_msg_writer() << tr("RPC error: ") << e.what();
- }
- catch (const tools::error::get_random_outs_error &e)
- {
- fail_msg_writer() << tr("failed to get random outputs to mix: ") << e.what();
- }
- catch (const tools::error::not_enough_unlocked_money& e)
- {
- LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, sent amount %s") %
- print_money(e.available()) %
- print_money(e.tx_amount()));
- fail_msg_writer() << tr("Not enough money in unlocked balance");
- }
- catch (const tools::error::not_enough_money& e)
- {
- LOG_PRINT_L0(boost::format("not enough money to transfer, overall balance only %s, sent amount %s") %
- print_money(e.available()) %
- print_money(e.tx_amount()));
- fail_msg_writer() << tr("Not enough money in overall balance");
- }
- catch (const tools::error::tx_not_possible& e)
- {
- LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee)") %
- print_money(e.available()) %
- print_money(e.tx_amount() + e.fee()) %
- print_money(e.tx_amount()) %
- print_money(e.fee()));
- fail_msg_writer() << tr("Failed to find a way to create transactions. This is usually due to dust which is so small it cannot pay for itself in fees, or trying to send more money than the unlocked balance, or not leaving enough for fees");
- }
- catch (const tools::error::not_enough_outs_to_mix& e)
- {
- auto writer = fail_msg_writer();
- writer << tr("not enough outputs for specified ring size") << " = " << (e.mixin_count() + 1) << ":";
- for (std::pair<uint64_t, uint64_t> outs_for_amount : e.scanty_outs())
- {
- writer << "\n" << tr("output amount") << " = " << print_money(outs_for_amount.first) << ", " << tr("found outputs to use") << " = " << outs_for_amount.second;
- }
- }
- catch (const tools::error::tx_not_constructed&)
- {
- fail_msg_writer() << tr("transaction was not constructed");
- }
- catch (const tools::error::tx_rejected& e)
- {
- fail_msg_writer() << (boost::format(tr("transaction %s was rejected by daemon with status: ")) % get_transaction_hash(e.tx())) << e.status();
- std::string reason = e.reason();
- if (!reason.empty())
- fail_msg_writer() << tr("Reason: ") << reason;
- }
- catch (const tools::error::tx_sum_overflow& e)
- {
- fail_msg_writer() << e.what();
- }
- catch (const tools::error::zero_destination&)
- {
- fail_msg_writer() << tr("one of destinations is zero");
- }
- catch (const tools::error::tx_too_big& e)
- {
- fail_msg_writer() << tr("Failed to find a suitable way to split transactions");
- }
- catch (const tools::error::transfer_error& e)
- {
- LOG_ERROR("unknown transfer error: " << e.to_string());
- fail_msg_writer() << tr("unknown transfer error: ") << e.what();
- }
- catch (const tools::error::wallet_internal_error& e)
- {
- LOG_ERROR("internal error: " << e.to_string());
- fail_msg_writer() << tr("internal error: ") << e.what();
- }
catch (const std::exception& e)
{
- LOG_ERROR("unexpected error: " << e.what());
- fail_msg_writer() << tr("unexpected error: ") << e.what();
+ handle_transfer_exception(std::current_exception());
}
catch (...)
{
@@ -3929,7 +3752,7 @@ bool simple_wallet::get_tx_proof(const std::vector<std::string> &args)
// fetch tx pubkey
crypto::public_key tx_pub_key = get_tx_pub_key_from_extra(tx);
- if (tx_pub_key == null_pkey)
+ if (tx_pub_key == crypto::null_pkey)
{
fail_msg_writer() << tr("Tx pubkey was not found");
return true;
@@ -4266,7 +4089,7 @@ bool simple_wallet::check_tx_proof(const std::vector<std::string> &args)
return true;
}
crypto::public_key tx_pub_key = get_tx_pub_key_from_extra(tx);
- if (tx_pub_key == null_pkey)
+ if (tx_pub_key == crypto::null_pkey)
{
fail_msg_writer() << tr("Tx pubkey was not found");
return true;
@@ -4821,10 +4644,11 @@ bool simple_wallet::account(const std::vector<std::string> &args/* = std::vector
//----------------------------------------------------------------------------------------------------
void simple_wallet::print_accounts()
{
- success_msg_writer() << boost::format("%15s %21s %21s %21s") % tr("Account") % tr("Balance") % tr("Unlocked balance") % tr("Label");
+ success_msg_writer() << boost::format(" %15s %21s %21s %21s") % tr("Account") % tr("Balance") % tr("Unlocked balance") % tr("Label");
for (uint32_t account_index = 0; account_index < m_wallet->get_num_subaddress_accounts(); ++account_index)
{
- success_msg_writer() << boost::format(tr("%8u %6s %21s %21s %21s"))
+ success_msg_writer() << boost::format(tr(" %c%8u %6s %21s %21s %21s"))
+ % (m_current_subaddress_account == account_index ? '*' : ' ')
% account_index
% m_wallet->get_subaddress_as_str({account_index, 0}).substr(0, 6)
% print_money(m_wallet->balance(account_index))
@@ -4993,7 +4817,7 @@ bool simple_wallet::address_book(const std::vector<std::string> &args/* = std::v
fail_msg_writer() << tr("failed to parse address");
return true;
}
- crypto::hash payment_id = null_hash;
+ crypto::hash payment_id = crypto::null_hash;
size_t description_start = 2;
if (info.has_payment_id)
{
@@ -5447,7 +5271,7 @@ bool simple_wallet::show_transfer(const std::vector<std::string> &args)
const uint64_t last_block_height = m_wallet->get_blockchain_current_height();
std::list<std::pair<crypto::hash, tools::wallet2::payment_details>> payments;
- m_wallet->get_payments(payments, 0, m_current_subaddress_account);
+ m_wallet->get_payments(payments, 0, (uint64_t)-1, m_current_subaddress_account);
for (std::list<std::pair<crypto::hash, tools::wallet2::payment_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) {
const tools::wallet2::payment_details &pd = i->second;
if (pd.m_tx_hash == txid) {
@@ -5518,7 +5342,7 @@ bool simple_wallet::show_transfer(const std::vector<std::string> &args)
{
m_wallet->update_pool_state();
std::list<std::pair<crypto::hash, tools::wallet2::pool_payment_details>> pool_payments;
- m_wallet->get_unconfirmed_payments(pool_payments);
+ m_wallet->get_unconfirmed_payments(pool_payments, m_current_subaddress_account);
for (std::list<std::pair<crypto::hash, tools::wallet2::pool_payment_details>>::const_iterator i = pool_payments.begin(); i != pool_payments.end(); ++i) {
const tools::wallet2::payment_details &pd = i->second.m_pd;
if (pd.m_tx_hash == txid)
@@ -5545,7 +5369,7 @@ bool simple_wallet::show_transfer(const std::vector<std::string> &args)
}
std::list<std::pair<crypto::hash, tools::wallet2::unconfirmed_transfer_details>> upayments;
- m_wallet->get_unconfirmed_payments_out(upayments);
+ m_wallet->get_unconfirmed_payments_out(upayments, m_current_subaddress_account);
for (std::list<std::pair<crypto::hash, tools::wallet2::unconfirmed_transfer_details>>::const_iterator i = upayments.begin(); i != upayments.end(); ++i) {
if (i->first == txid)
{
@@ -5649,6 +5473,7 @@ int main(int argc, char* argv[])
"monero-wallet-cli [--wallet-file=<file>|--generate-new-wallet=<file>] [<COMMAND>]",
desc_params,
positional_options,
+ [](const std::string &s, bool emphasis){ tools::scoped_message_writer(emphasis ? epee::console_color_white : epee::console_color_default, true) << s; },
"monero-wallet-cli.log"
);
diff --git a/src/wallet/CMakeLists.txt b/src/wallet/CMakeLists.txt
index 24399790c..e5c79a447 100644
--- a/src/wallet/CMakeLists.txt
+++ b/src/wallet/CMakeLists.txt
@@ -79,7 +79,6 @@ target_link_libraries(wallet
common
cryptonote_core
mnemonics
- p2p
${Boost_CHRONO_LIBRARY}
${Boost_SERIALIZATION_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
@@ -89,42 +88,40 @@ target_link_libraries(wallet
PRIVATE
${EXTRA_LIBRARIES})
-if (NOT BUILD_GUI_DEPS)
- set(wallet_rpc_sources
- wallet_rpc_server.cpp)
+set(wallet_rpc_sources
+ wallet_rpc_server.cpp)
- set(wallet_rpc_headers)
+set(wallet_rpc_headers)
- set(wallet_rpc_private_headers
- wallet_rpc_server.h)
+set(wallet_rpc_private_headers
+ wallet_rpc_server.h)
- monero_private_headers(wallet_rpc_server
- ${wallet_rpc_private_headers})
- monero_add_executable(wallet_rpc_server
- ${wallet_rpc_sources}
- ${wallet_rpc_headers}
- ${wallet_rpc_private_headers})
+monero_private_headers(wallet_rpc_server
+ ${wallet_rpc_private_headers})
+monero_add_executable(wallet_rpc_server
+ ${wallet_rpc_sources}
+ ${wallet_rpc_headers}
+ ${wallet_rpc_private_headers})
- target_link_libraries(wallet_rpc_server
- PRIVATE
- wallet
- epee
- rpc
- cryptonote_core
- cncrypto
- common
- version
- ${Boost_CHRONO_LIBRARY}
- ${Boost_PROGRAM_OPTIONS_LIBRARY}
- ${Boost_FILESYSTEM_LIBRARY}
- ${Boost_THREAD_LIBRARY}
- ${CMAKE_THREAD_LIBS_INIT}
- ${EXTRA_LIBRARIES})
- set_property(TARGET wallet_rpc_server
- PROPERTY
- OUTPUT_NAME "monero-wallet-rpc")
- install(TARGETS wallet_rpc_server DESTINATION bin)
-endif()
+target_link_libraries(wallet_rpc_server
+ PRIVATE
+ wallet
+ epee
+ rpc
+ cryptonote_core
+ cncrypto
+ common
+ version
+ ${Boost_CHRONO_LIBRARY}
+ ${Boost_PROGRAM_OPTIONS_LIBRARY}
+ ${Boost_FILESYSTEM_LIBRARY}
+ ${Boost_THREAD_LIBRARY}
+ ${CMAKE_THREAD_LIBS_INIT}
+ ${EXTRA_LIBRARIES})
+set_property(TARGET wallet_rpc_server
+ PROPERTY
+ OUTPUT_NAME "monero-wallet-rpc")
+install(TARGETS wallet_rpc_server DESTINATION bin)
# build and install libwallet_merged only if we building for GUI
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 2d3b25bd2..9d607211d 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -59,7 +59,6 @@ using namespace epee;
#include "rapidjson/stringbuffer.h"
#include "common/json_util.h"
#include "common/base58.h"
-#include "common/scoped_message_writer.h"
#include "ringct/rctSigs.h"
extern "C"
@@ -67,6 +66,8 @@ extern "C"
#include "crypto/keccak.h"
#include "crypto/crypto-ops.h"
}
+using namespace std;
+using namespace crypto;
using namespace cryptonote;
#undef MONERO_DEFAULT_LOG_CATEGORY
@@ -135,7 +136,7 @@ uint64_t calculate_fee(uint64_t fee_per_kb, const cryptonote::blobdata &blob, ui
return calculate_fee(fee_per_kb, blob.size(), fee_multiplier);
}
-std::unique_ptr<tools::wallet2> make_basic(const boost::program_options::variables_map& vm, const options& opts)
+std::unique_ptr<tools::wallet2> make_basic(const boost::program_options::variables_map& vm, const options& opts, const std::function<boost::optional<tools::password_container>(const char *, bool)> &password_prompter)
{
const bool testnet = command_line::get_arg(vm, opts.testnet);
const bool restricted = command_line::get_arg(vm, opts.restricted);
@@ -144,17 +145,16 @@ std::unique_ptr<tools::wallet2> make_basic(const boost::program_options::variabl
auto daemon_host = command_line::get_arg(vm, opts.daemon_host);
auto daemon_port = command_line::get_arg(vm, opts.daemon_port);
- if (!daemon_address.empty() && !daemon_host.empty() && 0 != daemon_port)
- {
- tools::fail_msg_writer() << tools::wallet2::tr("can't specify daemon host or port more than once");
- return nullptr;
- }
+ THROW_WALLET_EXCEPTION_IF(!daemon_address.empty() && !daemon_host.empty() && 0 != daemon_port,
+ tools::error::wallet_internal_error, tools::wallet2::tr("can't specify daemon host or port more than once"));
boost::optional<epee::net_utils::http::login> login{};
if (command_line::has_arg(vm, opts.daemon_login))
{
auto parsed = tools::login::parse(
- command_line::get_arg(vm, opts.daemon_login), false, "Daemon client password"
+ command_line::get_arg(vm, opts.daemon_login), false, [password_prompter](bool verify) {
+ return password_prompter("Daemon client password", verify);
+ }
);
if (!parsed)
return nullptr;
@@ -178,12 +178,11 @@ std::unique_ptr<tools::wallet2> make_basic(const boost::program_options::variabl
return wallet;
}
-boost::optional<tools::password_container> get_password(const boost::program_options::variables_map& vm, const options& opts, const bool verify)
+boost::optional<tools::password_container> get_password(const boost::program_options::variables_map& vm, const options& opts, const std::function<boost::optional<tools::password_container>(const char*, bool)> &password_prompter, const bool verify)
{
if (command_line::has_arg(vm, opts.password) && command_line::has_arg(vm, opts.password_file))
{
- tools::fail_msg_writer() << tools::wallet2::tr("can't specify more than one of --password and --password-file");
- return boost::none;
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("can't specify more than one of --password and --password-file"));
}
if (command_line::has_arg(vm, opts.password))
@@ -196,21 +195,17 @@ boost::optional<tools::password_container> get_password(const boost::program_opt
std::string password;
bool r = epee::file_io_utils::load_file_to_string(command_line::get_arg(vm, opts.password_file),
password);
- if (!r)
- {
- tools::fail_msg_writer() << tools::wallet2::tr("the password file specified could not be read");
- return boost::none;
- }
+ THROW_WALLET_EXCEPTION_IF(!r, tools::error::wallet_internal_error, tools::wallet2::tr("the password file specified could not be read"));
// Remove line breaks the user might have inserted
boost::trim_right_if(password, boost::is_any_of("\r\n"));
return {tools::password_container{std::move(password)}};
}
- return tools::wallet2::password_prompt(verify);
+ return password_prompter(verify ? tr("Enter new wallet password") : tr("Wallet password"), verify);
}
-std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file, const boost::program_options::variables_map& vm, const options& opts)
+std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file, const boost::program_options::variables_map& vm, const options& opts, const std::function<boost::optional<tools::password_container>(const char *, bool)> &password_prompter)
{
const bool testnet = command_line::get_arg(vm, opts.testnet);
@@ -221,22 +216,20 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
const auto do_generate = [&]() -> bool {
std::string buf;
if (!epee::file_io_utils::load_file_to_string(json_file, buf)) {
- tools::fail_msg_writer() << tools::wallet2::tr("Failed to load file ") << json_file;
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, std::string(tools::wallet2::tr("Failed to load file ")) + json_file);
return false;
}
rapidjson::Document json;
if (json.Parse(buf.c_str()).HasParseError()) {
- tools::fail_msg_writer() << tools::wallet2::tr("Failed to parse JSON");
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("Failed to parse JSON"));
return false;
}
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, version, unsigned, Uint, true, 0);
const int current_version = 1;
- if (field_version > current_version) {
- tools::fail_msg_writer() << boost::format(tools::wallet2::tr("Version %u too new, we can only grok up to %u")) % field_version % current_version;
- return false;
- }
+ THROW_WALLET_EXCEPTION_IF(field_version > current_version, tools::error::wallet_internal_error,
+ ((boost::format(tools::wallet2::tr("Version %u too new, we can only grok up to %u")) % field_version % current_version)).str());
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, filename, std::string, String, true, std::string());
@@ -252,14 +245,12 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
cryptonote::blobdata viewkey_data;
if(!epee::string_tools::parse_hexstr_to_binbuff(field_viewkey, viewkey_data) || viewkey_data.size() != sizeof(crypto::secret_key))
{
- tools::fail_msg_writer() << tools::wallet2::tr("failed to parse view key secret key");
- return false;
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("failed to parse view key secret key"));
}
viewkey = *reinterpret_cast<const crypto::secret_key*>(viewkey_data.data());
crypto::public_key pkey;
if (!crypto::secret_key_to_public_key(viewkey, pkey)) {
- tools::fail_msg_writer() << tools::wallet2::tr("failed to verify view key secret key");
- return false;
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("failed to verify view key secret key"));
}
}
@@ -270,14 +261,12 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
cryptonote::blobdata spendkey_data;
if(!epee::string_tools::parse_hexstr_to_binbuff(field_spendkey, spendkey_data) || spendkey_data.size() != sizeof(crypto::secret_key))
{
- tools::fail_msg_writer() << tools::wallet2::tr("failed to parse spend key secret key");
- return false;
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("failed to parse spend key secret key"));
}
spendkey = *reinterpret_cast<const crypto::secret_key*>(spendkey_data.data());
crypto::public_key pkey;
if (!crypto::secret_key_to_public_key(spendkey, pkey)) {
- tools::fail_msg_writer() << tools::wallet2::tr("failed to verify spend key secret key");
- return false;
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("failed to verify spend key secret key"));
}
}
@@ -289,8 +278,7 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
{
if (!crypto::ElectrumWords::words_to_bytes(field_seed, recovery_key, old_language))
{
- tools::fail_msg_writer() << tools::wallet2::tr("Electrum-style word list failed verification");
- return false;
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("Electrum-style word list failed verification"));
}
restore_deterministic_wallet = true;
@@ -307,13 +295,11 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
// compatibility checks
if (!field_seed_found && !field_viewkey_found && !field_spendkey_found)
{
- tools::fail_msg_writer() << tools::wallet2::tr("At least one of Electrum-style word list and private view key and private spend key must be specified");
- return false;
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("At least one of Electrum-style word list and private view key and private spend key must be specified"));
}
if (field_seed_found && (field_viewkey_found || field_spendkey_found))
{
- tools::fail_msg_writer() << tools::wallet2::tr("Both Electrum-style word list and private key(s) specified");
- return false;
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("Both Electrum-style word list and private key(s) specified"));
}
// if an address was given, we check keys against it, and deduce the spend
@@ -323,43 +309,36 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
cryptonote::address_parse_info info;
if(!get_account_address_from_str(info, testnet, field_address))
{
- tools::fail_msg_writer() << tools::wallet2::tr("invalid address");
- return false;
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("invalid address"));
}
if (field_viewkey_found)
{
crypto::public_key pkey;
if (!crypto::secret_key_to_public_key(viewkey, pkey)) {
- tools::fail_msg_writer() << tools::wallet2::tr("failed to verify view key secret key");
- return false;
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("failed to verify view key secret key"));
}
if (info.address.m_view_public_key != pkey) {
- tools::fail_msg_writer() << tools::wallet2::tr("view key does not match standard address");
- return false;
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("view key does not match standard address"));
}
}
if (field_spendkey_found)
{
crypto::public_key pkey;
if (!crypto::secret_key_to_public_key(spendkey, pkey)) {
- tools::fail_msg_writer() << tools::wallet2::tr("failed to verify spend key secret key");
- return false;
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("failed to verify spend key secret key"));
}
if (info.address.m_spend_public_key != pkey) {
- tools::fail_msg_writer() << tools::wallet2::tr("spend key does not match standard address");
- return false;
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("spend key does not match standard address"));
}
}
}
const bool deprecated_wallet = restore_deterministic_wallet && ((old_language == crypto::ElectrumWords::old_language_name) ||
crypto::ElectrumWords::get_is_old_style_seed(field_seed));
- if (deprecated_wallet) {
- tools::fail_msg_writer() << tools::wallet2::tr("Cannot create deprecated wallets from JSON");
- return false;
- }
+ THROW_WALLET_EXCEPTION_IF(deprecated_wallet, tools::error::wallet_internal_error,
+ tools::wallet2::tr("Cannot create deprecated wallets from JSON"));
- wallet.reset(make_basic(vm, opts).release());
+ wallet.reset(make_basic(vm, opts, password_prompter).release());
wallet->set_refresh_from_block_height(field_scan_from_height);
try
@@ -376,8 +355,7 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
{
cryptonote::account_public_address address;
if (!crypto::secret_key_to_public_key(viewkey, address.m_view_public_key)) {
- tools::fail_msg_writer() << tools::wallet2::tr("failed to verify view key secret key");
- return false;
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("failed to verify view key secret key"));
}
if (field_spendkey.empty())
@@ -389,23 +367,20 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
cryptonote::address_parse_info info;
if(!get_account_address_from_str(info, testnet, field_address))
{
- tools::fail_msg_writer() << tools::wallet2::tr("failed to parse address: ") << field_address;
- return false;
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, std::string(tools::wallet2::tr("failed to parse address: ")) + field_address);
}
address.m_spend_public_key = info.address.m_spend_public_key;
}
else
{
- tools::fail_msg_writer() << tools::wallet2::tr("Address must be specified in order to create watch-only wallet");
- return false;
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("Address must be specified in order to create watch-only wallet"));
}
wallet->generate(field_filename, field_password, address, viewkey);
}
else
{
if (!crypto::secret_key_to_public_key(spendkey, address.m_spend_public_key)) {
- tools::fail_msg_writer() << tools::wallet2::tr("failed to verify spend key secret key");
- return false;
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("failed to verify spend key secret key"));
}
wallet->generate(field_filename, field_password, address, spendkey, viewkey);
}
@@ -413,8 +388,7 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
}
catch (const std::exception& e)
{
- tools::fail_msg_writer() << tools::wallet2::tr("failed to generate new wallet: ") << e.what();
- return false;
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, std::string(tools::wallet2::tr("failed to generate new wallet: ")) + e.what());
}
return true;
};
@@ -468,6 +442,19 @@ static void emplace_or_replace(std::unordered_multimap<crypto::hash, tools::wall
container.emplace(key, pd);
}
+void drop_from_short_history(std::list<crypto::hash> &short_chain_history, size_t N)
+{
+ std::list<crypto::hash>::iterator right;
+ // drop early N off, skipping the genesis block
+ if (short_chain_history.size() > N) {
+ right = short_chain_history.end();
+ std::advance(right,-1);
+ std::list<crypto::hash>::iterator left = right;
+ std::advance(left, -N);
+ short_chain_history.erase(left, right);
+ }
+}
+
} //namespace
namespace tools
@@ -496,34 +483,22 @@ void wallet2::init_options(boost::program_options::options_description& desc_par
command_line::add_arg(desc_params, opts.restricted);
}
-boost::optional<password_container> wallet2::password_prompt(const bool new_password)
-{
- auto pwd_container = tools::password_container::prompt(
- new_password, (new_password ? tr("Enter new wallet password") : tr("Wallet password"))
- );
- if (!pwd_container)
- {
- tools::fail_msg_writer() << tr("failed to read wallet password");
- }
- return pwd_container;
-}
-
-std::unique_ptr<wallet2> wallet2::make_from_json(const boost::program_options::variables_map& vm, const std::string& json_file)
+std::unique_ptr<wallet2> wallet2::make_from_json(const boost::program_options::variables_map& vm, const std::string& json_file, const std::function<boost::optional<tools::password_container>(const char *, bool)> &password_prompter)
{
const options opts{};
- return generate_from_json(json_file, vm, opts);
+ return generate_from_json(json_file, vm, opts, password_prompter);
}
std::pair<std::unique_ptr<wallet2>, password_container> wallet2::make_from_file(
- const boost::program_options::variables_map& vm, const std::string& wallet_file)
+ const boost::program_options::variables_map& vm, const std::string& wallet_file, const std::function<boost::optional<tools::password_container>(const char *, bool)> &password_prompter)
{
const options opts{};
- auto pwd = get_password(vm, opts, false);
+ auto pwd = get_password(vm, opts, password_prompter, false);
if (!pwd)
{
return {nullptr, password_container{}};
}
- auto wallet = make_basic(vm, opts);
+ auto wallet = make_basic(vm, opts, password_prompter);
if (wallet)
{
wallet->load(wallet_file, pwd->password());
@@ -531,21 +506,21 @@ std::pair<std::unique_ptr<wallet2>, password_container> wallet2::make_from_file(
return {std::move(wallet), std::move(*pwd)};
}
-std::pair<std::unique_ptr<wallet2>, password_container> wallet2::make_new(const boost::program_options::variables_map& vm)
+std::pair<std::unique_ptr<wallet2>, password_container> wallet2::make_new(const boost::program_options::variables_map& vm, const std::function<boost::optional<password_container>(const char *, bool)> &password_prompter)
{
const options opts{};
- auto pwd = get_password(vm, opts, true);
+ auto pwd = get_password(vm, opts, password_prompter, true);
if (!pwd)
{
return {nullptr, password_container{}};
}
- return {make_basic(vm, opts), std::move(*pwd)};
+ return {make_basic(vm, opts, password_prompter), std::move(*pwd)};
}
-std::unique_ptr<wallet2> wallet2::make_dummy(const boost::program_options::variables_map& vm)
+std::unique_ptr<wallet2> wallet2::make_dummy(const boost::program_options::variables_map& vm, const std::function<boost::optional<tools::password_container>(const char *, bool)> &password_prompter)
{
const options opts{};
- return make_basic(vm, opts);
+ return make_basic(vm, opts, password_prompter);
}
//----------------------------------------------------------------------------------------------------
@@ -1498,6 +1473,8 @@ void wallet2::pull_next_blocks(uint64_t start_height, uint64_t &blocks_start_hei
try
{
+ drop_from_short_history(short_chain_history, 3);
+
// prepend the last 3 blocks, should be enough to guard against a block or two's reorg
cryptonote::block bl;
std::list<cryptonote::block_complete_entry>::const_reverse_iterator i = prev_blocks.rbegin();
@@ -1766,24 +1743,29 @@ void wallet2::update_pool_state(bool refreshed)
void wallet2::fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history)
{
std::list<crypto::hash> hashes;
- size_t current_index = m_blockchain.size();
+ const uint64_t checkpoint_height = m_checkpoints.get_max_height();
+ if (stop_height > checkpoint_height && m_blockchain.size()-1 < checkpoint_height)
+ {
+ // we will drop all these, so don't bother getting them
+ uint64_t missing_blocks = m_checkpoints.get_max_height() - m_blockchain.size();
+ while (missing_blocks-- > 0)
+ m_blockchain.push_back(crypto::null_hash); // maybe a bit suboptimal, but deque won't do huge reallocs like vector
+ m_blockchain.push_back(m_checkpoints.get_points().at(checkpoint_height));
+ m_local_bc_height = m_blockchain.size();
+ short_chain_history.clear();
+ get_short_chain_history(short_chain_history);
+ }
+
+ size_t current_index = m_blockchain.size();
while(m_run.load(std::memory_order_relaxed) && current_index < stop_height)
{
pull_hashes(0, blocks_start_height, short_chain_history, hashes);
if (hashes.size() <= 3)
return;
if (hashes.size() + current_index < stop_height) {
- std::list<crypto::hash>::iterator right;
- // drop early 3 off, skipping the genesis block
- if (short_chain_history.size() > 3) {
- right = short_chain_history.end();
- std::advance(right,-1);
- std::list<crypto::hash>::iterator left = right;
- std::advance(left, -3);
- short_chain_history.erase(left, right);
- }
- right = hashes.end();
+ drop_from_short_history(short_chain_history, 3);
+ std::list<crypto::hash>::iterator right = hashes.end();
// prepend 3 more
for (int i = 0; i<3; i++) {
right--;
@@ -3958,6 +3940,19 @@ int wallet2::get_fee_algorithm()
return 1;
return 0;
}
+//------------------------------------------------------------------------------------------------------------------------------
+uint64_t wallet2::adjust_mixin(uint64_t mixin)
+{
+ if (mixin < 4 && use_fork_rules(6, 10)) {
+ MWARNING("Requested ring size " << (mixin + 1) << " too low for hard fork 6, using 5");
+ mixin = 4;
+ }
+ else if (mixin < 2 && use_fork_rules(2, 10)) {
+ MWARNING("Requested ring size " << (mixin + 1) << " too low for hard fork 2, using 3");
+ mixin = 2;
+ }
+ return mixin;
+}
//----------------------------------------------------------------------------------------------------
// separated the call(s) to wallet2::transfer into their own function
//
@@ -6474,16 +6469,12 @@ uint64_t wallet2::import_key_images(const std::string &filename, uint64_t &spent
std::string data;
bool r = epee::file_io_utils::load_file_to_string(filename, data);
- if (!r)
- {
- fail_msg_writer() << tr("failed to read file ") << filename;
- return 0;
- }
+ THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, std::string(tr("failed to read file ")) + filename);
+
const size_t magiclen = strlen(KEY_IMAGE_EXPORT_FILE_MAGIC);
if (data.size() < magiclen || memcmp(data.data(), KEY_IMAGE_EXPORT_FILE_MAGIC, magiclen))
{
- fail_msg_writer() << "Bad key image export file magic in " << filename;
- return 0;
+ THROW_WALLET_EXCEPTION(error::wallet_internal_error, std::string("Bad key image export file magic in ") + filename);
}
try
@@ -6492,31 +6483,22 @@ uint64_t wallet2::import_key_images(const std::string &filename, uint64_t &spent
}
catch (const std::exception &e)
{
- fail_msg_writer() << "Failed to decrypt " << filename << ": " << e.what();
- return 0;
+ THROW_WALLET_EXCEPTION(error::wallet_internal_error, std::string("Failed to decrypt ") + filename + ": " + e.what());
}
const size_t headerlen = 2 * sizeof(crypto::public_key);
- if (data.size() < headerlen)
- {
- fail_msg_writer() << "Bad data size from file " << filename;
- return 0;
- }
+ THROW_WALLET_EXCEPTION_IF(data.size() < headerlen, error::wallet_internal_error, std::string("Bad data size from file ") + filename);
const crypto::public_key &public_spend_key = *(const crypto::public_key*)&data[0];
const crypto::public_key &public_view_key = *(const crypto::public_key*)&data[sizeof(crypto::public_key)];
const cryptonote::account_public_address &keys = get_account().get_keys().m_account_address;
if (public_spend_key != keys.m_spend_public_key || public_view_key != keys.m_view_public_key)
{
- fail_msg_writer() << "Key images from " << filename << " are for a different account";
- return 0;
+ THROW_WALLET_EXCEPTION(error::wallet_internal_error, std::string( "Key images from ") + filename + " are for a different account");
}
const size_t record_size = sizeof(crypto::key_image) + sizeof(crypto::signature);
- if ((data.size() - headerlen) % record_size)
- {
- fail_msg_writer() << "Bad data size from file " << filename;
- return 0;
- }
+ THROW_WALLET_EXCEPTION_IF((data.size() - headerlen) % record_size,
+ error::wallet_internal_error, std::string("Bad data size from file ") + filename);
size_t nki = (data.size() - headerlen) / record_size;
std::vector<std::pair<crypto::key_image, crypto::signature>> ski;
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 3603faaca..38898930d 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -147,7 +147,7 @@ namespace tools
};
private:
- wallet2(const wallet2&) : m_run(true), m_callback(0), m_testnet(false), m_always_confirm_transfers(true), m_print_ring_members(false), m_store_tx_info(true), m_default_mixin(0), m_default_priority(0), m_refresh_type(RefreshOptimizeCoinbase), m_auto_refresh(true), m_refresh_from_block_height(0), m_confirm_missing_payment_id(true), m_ask_password(true), m_min_output_count(0), m_min_output_value(0), m_merge_destinations(false), m_confirm_backlog(true), m_is_initialized(false),m_node_rpc_proxy(m_http_client, m_daemon_rpc_mutex) {}
+ wallet2(const wallet2&) : m_run(true), m_callback(0), m_testnet(false), m_always_confirm_transfers(true), m_print_ring_members(false), m_store_tx_info(true), m_default_mixin(0), m_default_priority(0), m_refresh_type(RefreshDefault), m_auto_refresh(true), m_refresh_from_block_height(0), m_confirm_missing_payment_id(true), m_ask_password(true), m_min_output_count(0), m_min_output_value(0), m_merge_destinations(false), m_confirm_backlog(true), m_is_initialized(false),m_node_rpc_proxy(m_http_client, m_daemon_rpc_mutex) {}
public:
static const char* tr(const char* str);
@@ -155,25 +155,22 @@ namespace tools
static bool has_testnet_option(const boost::program_options::variables_map& vm);
static void init_options(boost::program_options::options_description& desc_params);
- //! \return Password retrieved from prompt. Logs error on failure.
- static boost::optional<password_container> password_prompt(const bool new_password);
-
//! Uses stdin and stdout. Returns a wallet2 if no errors.
- static std::unique_ptr<wallet2> make_from_json(const boost::program_options::variables_map& vm, const std::string& json_file);
+ static std::unique_ptr<wallet2> make_from_json(const boost::program_options::variables_map& vm, const std::string& json_file, const std::function<boost::optional<password_container>(const char *, bool)> &password_prompter);
//! Uses stdin and stdout. Returns a wallet2 and password for `wallet_file` if no errors.
static std::pair<std::unique_ptr<wallet2>, password_container>
- make_from_file(const boost::program_options::variables_map& vm, const std::string& wallet_file);
+ make_from_file(const boost::program_options::variables_map& vm, const std::string& wallet_file, const std::function<boost::optional<password_container>(const char *, bool)> &password_prompter);
//! Uses stdin and stdout. Returns a wallet2 and password for wallet with no file if no errors.
- static std::pair<std::unique_ptr<wallet2>, password_container> make_new(const boost::program_options::variables_map& vm);
+ static std::pair<std::unique_ptr<wallet2>, password_container> make_new(const boost::program_options::variables_map& vm, const std::function<boost::optional<password_container>(const char *, bool)> &password_prompter);
//! Just parses variables.
- static std::unique_ptr<wallet2> make_dummy(const boost::program_options::variables_map& vm);
+ static std::unique_ptr<wallet2> make_dummy(const boost::program_options::variables_map& vm, const std::function<boost::optional<password_container>(const char *, bool)> &password_prompter);
static bool verify_password(const std::string& keys_file_name, const std::string& password, bool watch_only);
- wallet2(bool testnet = false, bool restricted = false) : m_run(true), m_callback(0), m_testnet(testnet), m_always_confirm_transfers(true), m_print_ring_members(false), m_store_tx_info(true), m_default_mixin(0), m_default_priority(0), m_refresh_type(RefreshOptimizeCoinbase), m_auto_refresh(true), m_refresh_from_block_height(0), m_confirm_missing_payment_id(true), m_ask_password(true), m_min_output_count(0), m_min_output_value(0), m_merge_destinations(false), m_confirm_backlog(true), m_is_initialized(false), m_restricted(restricted), is_old_file_format(false), m_node_rpc_proxy(m_http_client, m_daemon_rpc_mutex), m_light_wallet(false), m_light_wallet_scanned_block_height(0), m_light_wallet_blockchain_height(0), m_light_wallet_connected(false), m_light_wallet_balance(0), m_light_wallet_unlocked_balance(0) {}
+ wallet2(bool testnet = false, bool restricted = false) : m_run(true), m_callback(0), m_testnet(testnet), m_always_confirm_transfers(true), m_print_ring_members(false), m_store_tx_info(true), m_default_mixin(0), m_default_priority(0), m_refresh_type(RefreshDefault), m_auto_refresh(true), m_refresh_from_block_height(0), m_confirm_missing_payment_id(true), m_ask_password(true), m_min_output_count(0), m_min_output_value(0), m_merge_destinations(false), m_confirm_backlog(true), m_is_initialized(false), m_restricted(restricted), is_old_file_format(false), m_node_rpc_proxy(m_http_client, m_daemon_rpc_mutex), m_light_wallet(false), m_light_wallet_scanned_block_height(0), m_light_wallet_blockchain_height(0), m_light_wallet_connected(false), m_light_wallet_balance(0), m_light_wallet_unlocked_balance(0) {}
struct tx_scan_info_t
{
@@ -613,14 +610,13 @@ namespace tools
a & m_address_book;
if(ver < 17)
return;
- if (ver < 21)
+ if (ver < 22)
{
// we're loading an old version, where m_unconfirmed_payments payload was payment_details
- std::unordered_map<crypto::hash, payment_details> m;
+ std::unordered_multimap<crypto::hash, payment_details> m;
a & m;
for (const auto &i: m)
m_unconfirmed_payments.insert(std::make_pair(i.first, pool_payment_details{i.second, false}));
- return;
}
if(ver < 18)
return;
@@ -761,6 +757,7 @@ namespace tools
uint64_t get_fee_multiplier(uint32_t priority, int fee_algorithm = -1);
uint64_t get_per_kb_fee();
+ uint64_t adjust_mixin(uint64_t mixin);
// Light wallet specific functions
// fetch unspent outs from lw node and store in m_transfers
diff --git a/src/wallet/wallet_args.cpp b/src/wallet/wallet_args.cpp
index df01ec238..cc6bb1de2 100644
--- a/src/wallet/wallet_args.cpp
+++ b/src/wallet/wallet_args.cpp
@@ -30,7 +30,6 @@
#include <boost/filesystem/path.hpp>
#include <boost/format.hpp>
#include "common/i18n.h"
-#include "common/scoped_message_writer.h"
#include "common/util.h"
#include "misc_log_ex.h"
#include "string_tools.h"
@@ -50,6 +49,20 @@
#define DEFAULT_MAX_CONCURRENCY 0
#endif
+namespace
+{
+ class Print
+ {
+ public:
+ Print(const std::function<void(const std::string&, bool)> &p, bool em = false): print(p), emphasis(em) {}
+ ~Print() { print(ss.str(), emphasis); }
+ template<typename T> std::ostream &operator<<(const T &t) { ss << t; return ss; }
+ private:
+ const std::function<void(const std::string&, bool)> &print;
+ std::stringstream ss;
+ bool emphasis;
+ };
+}
namespace wallet_args
{
@@ -73,6 +86,7 @@ namespace wallet_args
const char* const usage,
boost::program_options::options_description desc_params,
const boost::program_options::positional_options_description& positional_options,
+ const std::function<void(const std::string&, bool)> &print,
const char *default_log_name,
bool log_to_console)
@@ -118,16 +132,16 @@ namespace wallet_args
if (command_line::get_arg(vm, command_line::arg_help))
{
- tools::msg_writer() << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")" << ENDL;
- tools::msg_writer() << wallet_args::tr("This is the command line monero wallet. It needs to connect to a monero\n"
+ Print(print) << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")" << ENDL;
+ Print(print) << wallet_args::tr("This is the command line monero wallet. It needs to connect to a monero\n"
"daemon to work correctly.") << ENDL;
- tools::msg_writer() << wallet_args::tr("Usage:") << ENDL << " " << usage;
- tools::msg_writer() << desc_all;
+ Print(print) << wallet_args::tr("Usage:") << ENDL << " " << usage;
+ Print(print) << desc_all;
return false;
}
else if (command_line::get_arg(vm, command_line::arg_version))
{
- tools::msg_writer() << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")";
+ Print(print) << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")";
return false;
}
@@ -142,7 +156,7 @@ namespace wallet_args
}
else
{
- tools::fail_msg_writer() << wallet_args::tr("Can't find config file ") << config;
+ MERROR(wallet_args::tr("Can't find config file ") << config);
return false;
}
}
@@ -167,14 +181,15 @@ namespace wallet_args
if(command_line::has_arg(vm, arg_max_concurrency))
tools::set_max_concurrency(command_line::get_arg(vm, arg_max_concurrency));
- tools::scoped_message_writer(epee::console_color_white, true) << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")";
+ Print(print) << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")";
if (!command_line::is_arg_defaulted(vm, arg_log_level))
MINFO("Setting log level = " << command_line::get_arg(vm, arg_log_level));
else
MINFO("Setting log levels = " << getenv("MONERO_LOGS"));
MINFO(wallet_args::tr("Logging to: ") << log_path);
- tools::scoped_message_writer(epee::console_color_white, true) << boost::format(wallet_args::tr("Logging to %s")) % log_path;
+
+ Print(print) << boost::format(wallet_args::tr("Logging to %s")) % log_path;
return {std::move(vm)};
}
diff --git a/src/wallet/wallet_args.h b/src/wallet/wallet_args.h
index cf23ffded..8974098ad 100644
--- a/src/wallet/wallet_args.h
+++ b/src/wallet/wallet_args.h
@@ -50,5 +50,6 @@ namespace wallet_args
const char* const usage,
boost::program_options::options_description desc_params,
const boost::program_options::positional_options_description& positional_options,
+ const std::function<void(const std::string&, bool)> &print,
const char *default_log_name, bool log_to_console = false);
}
diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h
index 9d66f125e..41eb77451 100644
--- a/src/wallet/wallet_errors.h
+++ b/src/wallet/wallet_errors.h
@@ -765,6 +765,12 @@ namespace tools
#define STRINGIZE_DETAIL(x) #x
#define STRINGIZE(x) STRINGIZE_DETAIL(x)
+#define THROW_WALLET_EXCEPTION(err_type, ...) \
+ do { \
+ LOG_ERROR("THROW EXCEPTION: " << #err_type); \
+ tools::error::throw_wallet_ex<err_type>(std::string(__FILE__ ":" STRINGIZE(__LINE__)), ## __VA_ARGS__); \
+ } while(0)
+
#define THROW_WALLET_EXCEPTION_IF(cond, err_type, ...) \
if (cond) \
{ \
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index 5dbf30419..90acb44d8 100755..100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -60,6 +60,16 @@ namespace
const command_line::arg_descriptor<std::string> arg_wallet_dir = {"wallet-dir", "Directory for newly created wallets"};
constexpr const char default_rpc_username[] = "monero";
+
+ boost::optional<tools::password_container> password_prompter(const char *prompt, bool verify)
+ {
+ auto pwd_container = tools::password_container::prompt(verify, prompt);
+ if (!pwd_container)
+ {
+ MERROR("failed to read wallet password");
+ }
+ return pwd_container;
+ }
}
namespace tools
@@ -131,7 +141,7 @@ namespace tools
walvars = m_wallet;
else
{
- tmpwal = tools::wallet2::make_dummy(*m_vm);
+ tmpwal = tools::wallet2::make_dummy(*m_vm, password_prompter);
walvars = tmpwal.get();
}
boost::optional<epee::net_utils::http::login> http_login{};
@@ -227,19 +237,6 @@ namespace tools
return false;
}
//------------------------------------------------------------------------------------------------------------------------------
- uint64_t wallet_rpc_server::adjust_mixin(uint64_t mixin)
- {
- if (mixin < 4 && m_wallet->use_fork_rules(6, 10)) {
- MWARNING("Requested ring size " << (mixin + 1) << " too low for hard fork 6, using 5");
- mixin = 4;
- }
- else if (mixin < 2 && m_wallet->use_fork_rules(2, 10)) {
- MWARNING("Requested ring size " << (mixin + 1) << " too low for hard fork 2, using 3");
- mixin = 2;
- }
- return mixin;
- }
- //------------------------------------------------------------------------------------------------------------------------------
void wallet_rpc_server::fill_transfer_entry(tools::wallet_rpc::transfer_entry &entry, const crypto::hash &txid, const crypto::hash &payment_id, const tools::wallet2::payment_details &pd)
{
entry.txid = string_tools::pod_to_hex(pd.m_tx_hash);
@@ -607,7 +604,7 @@ namespace tools
try
{
- uint64_t mixin = adjust_mixin(req.mixin);
+ uint64_t mixin = m_wallet->adjust_mixin(req.mixin);
std::vector<wallet2::pending_tx> ptx_vector = m_wallet->create_transactions_2(dsts, mixin, req.unlock_time, req.priority, extra, req.account_index, req.subaddr_indices, m_trusted_daemon);
// reject proposed transactions if there are more than one. see on_transfer_split below.
@@ -667,7 +664,7 @@ namespace tools
try
{
- uint64_t mixin = adjust_mixin(req.mixin);
+ uint64_t mixin = m_wallet->adjust_mixin(req.mixin);
uint64_t ptx_amount;
std::vector<wallet2::pending_tx> ptx_vector;
LOG_PRINT_L2("on_transfer_split calling create_transactions_2");
@@ -784,7 +781,7 @@ namespace tools
try
{
- uint64_t mixin = adjust_mixin(req.mixin);
+ uint64_t mixin = m_wallet->adjust_mixin(req.mixin);
std::vector<wallet2::pending_tx> ptx_vector = m_wallet->create_transactions_all(req.below_amount, dsts[0].addr, dsts[0].is_subaddress, mixin, req.unlock_time, req.priority, extra, req.account_index, req.subaddr_indices, m_trusted_daemon);
if (!req.do_not_relay)
@@ -1811,7 +1808,7 @@ namespace tools
command_line::add_arg(desc, arg_password);
po::store(po::parse_command_line(argc, argv, desc), vm2);
}
- std::unique_ptr<tools::wallet2> wal = tools::wallet2::make_new(vm2).first;
+ std::unique_ptr<tools::wallet2> wal = tools::wallet2::make_new(vm2, password_prompter).first;
if (!wal)
{
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
@@ -1885,7 +1882,7 @@ namespace tools
}
std::unique_ptr<tools::wallet2> wal = nullptr;
try {
- wal = tools::wallet2::make_from_file(vm2, wallet_file).first;
+ wal = tools::wallet2::make_from_file(vm2, wallet_file, password_prompter).first;
}
catch (const std::exception& e)
{
@@ -1984,6 +1981,7 @@ int main(int argc, char** argv) {
"monero-wallet-rpc [--wallet-file=<file>|--generate-from-json=<file>|--wallet-dir=<directory>] [--rpc-bind-port=<port>]",
desc_params,
po::positional_options_description(),
+ [](const std::string &s, bool emphasis){ epee::set_console_color(emphasis ? epee::console_color_white : epee::console_color_default, true); std::cout << s << std::endl; if (emphasis) epee::reset_console_color(); },
"monero-wallet-rpc.log",
true
);
@@ -2020,11 +2018,19 @@ int main(int argc, char** argv) {
LOG_PRINT_L0(tools::wallet_rpc_server::tr("Loading wallet..."));
if(!wallet_file.empty())
{
- wal = tools::wallet2::make_from_file(*vm, wallet_file).first;
+ wal = tools::wallet2::make_from_file(*vm, wallet_file, password_prompter).first;
}
else
{
- wal = tools::wallet2::make_from_json(*vm, from_json);
+ try
+ {
+ wal = tools::wallet2::make_from_json(*vm, from_json, password_prompter);
+ }
+ catch (const std::exception &e)
+ {
+ MERROR("Error creating wallet: " << e.what());
+ return 1;
+ }
}
if (!wal)
{
diff --git a/tests/core_proxy/core_proxy.cpp b/tests/core_proxy/core_proxy.cpp
index 0dc314b49..fd07a5d2e 100644
--- a/tests/core_proxy/core_proxy.cpp
+++ b/tests/core_proxy/core_proxy.cpp
@@ -34,12 +34,8 @@
#include "include_base_utils.h"
#include "version.h"
-
-using namespace epee;
-
#include <iostream>
#include <sstream>
-using namespace std;
#include <boost/program_options.hpp>
@@ -56,6 +52,8 @@ using namespace std;
#endif
namespace po = boost::program_options;
+using namespace std;
+using namespace epee;
using namespace cryptonote;
using namespace crypto;
@@ -81,7 +79,7 @@ int main(int argc, char* argv[])
po::options_description desc("Allowed options");
// tools::get_default_data_dir() can't be called during static initialization
- command_line::add_arg(desc, command_line::arg_data_dir, tools::get_default_data_dir());
+ command_line::add_arg(desc, cryptonote::arg_data_dir, tools::get_default_data_dir());
nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<tests::proxy_core> >::init_options(desc);
po::variables_map vm;
diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp
index 2b713cab9..4c5dc6c9a 100644
--- a/tests/core_tests/chaingen.cpp
+++ b/tests/core_tests/chaingen.cpp
@@ -47,6 +47,7 @@
using namespace std;
using namespace epee;
+using namespace crypto;
using namespace cryptonote;
diff --git a/tests/fuzz/block.cpp b/tests/fuzz/block.cpp
index 099e8e3bd..03751fc14 100644
--- a/tests/fuzz/block.cpp
+++ b/tests/fuzz/block.cpp
@@ -27,7 +27,6 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "include_base_utils.h"
-#include "common/command_line.h"
#include "file_io_utils.h"
#include "cryptonote_protocol/blobdatatype.h"
#include "cryptonote_basic/cryptonote_basic.h"
diff --git a/tests/fuzz/cold-transaction.cpp b/tests/fuzz/cold-transaction.cpp
index c35d604a8..25a80fc68 100644
--- a/tests/fuzz/cold-transaction.cpp
+++ b/tests/fuzz/cold-transaction.cpp
@@ -27,7 +27,6 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "include_base_utils.h"
-#include "common/command_line.h"
#include "file_io_utils.h"
#include "cryptonote_protocol/blobdatatype.h"
#include "cryptonote_basic/cryptonote_basic.h"
diff --git a/tests/fuzz/signature.cpp b/tests/fuzz/signature.cpp
index 071297ba8..42a8fa997 100644
--- a/tests/fuzz/signature.cpp
+++ b/tests/fuzz/signature.cpp
@@ -27,7 +27,6 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "include_base_utils.h"
-#include "common/command_line.h"
#include "file_io_utils.h"
#include "cryptonote_protocol/blobdatatype.h"
#include "cryptonote_basic/cryptonote_basic.h"
diff --git a/tests/fuzz/transaction.cpp b/tests/fuzz/transaction.cpp
index 21cd01bef..9e2b9f2cb 100644
--- a/tests/fuzz/transaction.cpp
+++ b/tests/fuzz/transaction.cpp
@@ -27,7 +27,6 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "include_base_utils.h"
-#include "common/command_line.h"
#include "file_io_utils.h"
#include "cryptonote_protocol/blobdatatype.h"
#include "cryptonote_basic/cryptonote_basic.h"
diff --git a/tests/performance_tests/performance_utils.h b/tests/performance_tests/performance_utils.h
index 061772cbd..6bf45ff83 100644
--- a/tests/performance_tests/performance_utils.h
+++ b/tests/performance_tests/performance_utils.h
@@ -40,7 +40,7 @@
void set_process_affinity(int core)
{
-#if defined (__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+#if defined (__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__sun)
return;
#elif defined(BOOST_WINDOWS)
DWORD_PTR mask = 1;
@@ -62,7 +62,7 @@ void set_process_affinity(int core)
void set_thread_high_priority()
{
-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__sun)
return;
#elif defined(BOOST_WINDOWS)
::SetPriorityClass(::GetCurrentProcess(), HIGH_PRIORITY_CLASS);
diff --git a/tests/unit_tests/main.cpp b/tests/unit_tests/main.cpp
index 76f2b2749..86e7bcef3 100644
--- a/tests/unit_tests/main.cpp
+++ b/tests/unit_tests/main.cpp
@@ -53,7 +53,7 @@ int main(int argc, char** argv)
po::options_description desc_options("Command line options");
const command_line::arg_descriptor<std::string> arg_data_dir = {"data-dir", "Data files directory", "", true};
- command_line::add_arg(desc_options, command_line::arg_data_dir, "");
+ command_line::add_arg(desc_options, arg_data_dir, "");
po::variables_map vm;
bool r = command_line::handle_error_helper(desc_options, [&]()
diff --git a/tests/unit_tests/output_selection.cpp b/tests/unit_tests/output_selection.cpp
index 6ff73b107..ccca0b799 100644
--- a/tests/unit_tests/output_selection.cpp
+++ b/tests/unit_tests/output_selection.cpp
@@ -76,7 +76,7 @@ TEST(select_outputs, one_out_of_N)
tools::wallet2::transfer_container transfers = make_transfers_container(10);
transfers[6].m_block_height = 700;
std::vector<size_t> unused_indices({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
- std::list<size_t> selected;
+ std::vector<size_t> selected;
SELECT(2);
PICK(6);
}
@@ -93,7 +93,7 @@ TEST(select_outputs, order)
transfers[3].m_block_height = 716;
transfers[4].m_block_height = 701;
std::vector<size_t> unused_indices({0, 1, 2, 3, 4});
- std::list<size_t> selected;
+ std::vector<size_t> selected;
SELECT(0);
PICK(3); // first the one that's far away
PICK(2); // then the one that's close
diff --git a/tests/unit_tests/ringct.cpp b/tests/unit_tests/ringct.cpp
index af6afa636..ef6151efb 100644
--- a/tests/unit_tests/ringct.cpp
+++ b/tests/unit_tests/ringct.cpp
@@ -38,6 +38,7 @@
#include "ringct/rctSigs.h"
#include "ringct/rctOps.h"
+using namespace std;
using namespace crypto;
using namespace rct;
diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp
index 011082d1c..0750ab7d1 100644
--- a/tests/unit_tests/serialization.cpp
+++ b/tests/unit_tests/serialization.cpp
@@ -49,6 +49,7 @@
#include "gtest/gtest.h"
#include "unit_tests_utils.h"
using namespace std;
+using namespace crypto;
struct Struct
{