aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt4
-rw-r--r--README4
-rw-r--r--ReleaseNotes.txt7
-rw-r--r--contrib/epee/demo/demo_http_server/demo_http_server.cpp10
-rw-r--r--contrib/epee/demo/demo_http_server/demo_http_server.h12
-rw-r--r--contrib/epee/demo/demo_levin_server/demo_levin_server.cpp2
-rw-r--r--contrib/epee/demo/iface/transport_defs.h10
-rw-r--r--contrib/epee/include/console_handler.h2
-rw-r--r--contrib/epee/include/net/http_protocol_handler.inl2
-rw-r--r--contrib/epee/include/net/http_server_handlers_map2.h86
-rw-r--r--contrib/epee/include/serialization/keyvalue_serialization_overloads.h16
-rw-r--r--contrib/epee/include/storages/portable_storage.h18
-rw-r--r--include/INode.h37
-rw-r--r--include/IWallet.h87
-rw-r--r--src/cryptonote_config.h2
-rw-r--r--src/cryptonote_core/blockchain_storage.h16
-rw-r--r--src/cryptonote_core/cryptonote_format_utils.h2
-rw-r--r--src/cryptonote_core/miner.cpp8
-rw-r--r--src/daemon/daemon.cpp2
-rw-r--r--src/simplewallet/simplewallet.cpp26
-rw-r--r--src/version.h.in4
-rw-r--r--src/wallet/wallet2.cpp54
-rw-r--r--src/wallet/wallet2.h33
-rw-r--r--src/wallet/wallet_errors.h2
24 files changed, 296 insertions, 150 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9c51b6461..c51e61f5d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -99,9 +99,11 @@ elseif(DEFINED COMMIT)
add_custom_target(version ALL)
else()
find_package(Git QUIET)
- if(Git_FOUND)
+ if(Git_FOUND OR GIT_FOUND)
+ message(STATUS "Found Git: ${GIT_EXECUTABLE}")
add_custom_target(version ALL "${CMAKE_COMMAND}" "-D" "VERSION=${VERSION}" "-D" "GIT=${GIT_EXECUTABLE}" "-D" "TO=${CMAKE_BINARY_DIR}/version/version.h" "-P" "src/version.cmake" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
else()
+ message(STATUS "WARNING: Git was not found!")
set(VERSION "${VERSION}-unknown")
configure_file("src/version.h.in" "version/version.h")
add_custom_target(version ALL)
diff --git a/README b/README
index 2908133e8..f63a4cc4f 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
--= Building Cybernote =-
+-= Building CryptoNote =-
On *nix:
@@ -29,4 +29,4 @@ cd build
cmake -G "Visual Studio 11 Win64" ..
And then do Build.
-Good luck! \ No newline at end of file
+Good luck!
diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt
index 6adb22758..8940acd9b 100644
--- a/ReleaseNotes.txt
+++ b/ReleaseNotes.txt
@@ -1,3 +1,8 @@
+Release notes 0.8.4
+
+- Formalization of high level API
+- Improvements for wallet JSON RPC API
+
Release notes 0.8.3
- JSON RPC for wallet
@@ -14,4 +19,4 @@ Release notes 0.8.2
Release notes 0.8.1
-Bytecoin project is moved to GitHub \ No newline at end of file
+Bytecoin project is moved to GitHub
diff --git a/contrib/epee/demo/demo_http_server/demo_http_server.cpp b/contrib/epee/demo/demo_http_server/demo_http_server.cpp
index fda53b9ad..85547e4c9 100644
--- a/contrib/epee/demo/demo_http_server/demo_http_server.cpp
+++ b/contrib/epee/demo/demo_http_server/demo_http_server.cpp
@@ -43,7 +43,7 @@ bool communicate(const std::string url, t_request& req, t_response& rsp, const s
{
epee::json_rpc::request<t_request> req_t = AUTO_VAL_INIT(req_t);
req_t.jsonrpc = "2.0";
- req_t.id = "10";
+ req_t.id = epee::serialization::storage_entry(10);
req_t.method = "command_example_1";
req_t.params = req;
epee::json_rpc::response<t_response, std::string> resp_t = AUTO_VAL_INIT(resp_t);
@@ -80,7 +80,7 @@ int main(int argc, char* argv[])
demo::demo_http_server srv;
- start_default_console(&srv);
+ start_default_console(&srv, "#");
std::string bind_param = "0.0.0.0";
std::string port = "83";
@@ -195,7 +195,7 @@ namespace demo
return true;
}
- bool demo_http_server::on_request_api_1(const COMMAND_EXAMPLE_1::request& req, COMMAND_EXAMPLE_1::response& res)
+ bool demo_http_server::on_request_api_1(const COMMAND_EXAMPLE_1::request& req, COMMAND_EXAMPLE_1::response& res, connection_context& ctxt)
{
CHECK_AND_ASSERT_MES(req.sub == demo::get_test_data(), false, "wrong request");
res.m_success = true;
@@ -203,14 +203,14 @@ namespace demo
return true;
}
- bool demo_http_server::on_request_api_1_with_error(const COMMAND_EXAMPLE_1::request& req, COMMAND_EXAMPLE_1::response& res, epee::json_rpc::error& error_resp)
+ bool demo_http_server::on_request_api_1_with_error(const COMMAND_EXAMPLE_1::request& req, COMMAND_EXAMPLE_1::response& res, epee::json_rpc::error& error_resp, connection_context& ctxt)
{
error_resp.code = 232432;
error_resp.message = "bla bla bla";
return false;
}
- bool demo_http_server::on_request_api_2(const COMMAND_EXAMPLE_2::request& req, COMMAND_EXAMPLE_2::response& res)
+ bool demo_http_server::on_request_api_2(const COMMAND_EXAMPLE_2::request& req, COMMAND_EXAMPLE_2::response& res, connection_context& ctxt)
{
return true;
}
diff --git a/contrib/epee/demo/demo_http_server/demo_http_server.h b/contrib/epee/demo/demo_http_server/demo_http_server.h
index bb8f9bffa..088ead548 100644
--- a/contrib/epee/demo/demo_http_server/demo_http_server.h
+++ b/contrib/epee/demo/demo_http_server/demo_http_server.h
@@ -39,9 +39,11 @@ using namespace epee;
namespace demo
{
- class demo_http_server: public net_utils::http::i_http_server_handler
+ class demo_http_server: public net_utils::http::i_http_server_handler<epee::net_utils::connection_context_base>
{
public:
+ typedef epee::net_utils::connection_context_base connection_context;
+
demo_http_server():m_stop(false){}
bool run();
bool init(const std::string& bind_port = "11112", const std::string& bind_ip = "0.0.0.0");
@@ -52,7 +54,7 @@ namespace demo
private:
- CHAIN_HTTP_TO_MAP2(); //forward http requests to uri map
+ CHAIN_HTTP_TO_MAP2(connection_context); //forward http requests to uri map
BEGIN_URI_MAP2()
MAP_URI2("/requestr_uri_1", on_requestr_uri_1)
@@ -89,10 +91,10 @@ namespace demo
net_utils::http::http_response_info& response,
const net_utils::connection_context_base& m_conn_context);
- bool on_request_api_1(const COMMAND_EXAMPLE_1::request& req, COMMAND_EXAMPLE_1::response& res);
- bool on_request_api_2(const COMMAND_EXAMPLE_2::request& req, COMMAND_EXAMPLE_2::response& res);
+ bool on_request_api_1(const COMMAND_EXAMPLE_1::request& req, COMMAND_EXAMPLE_1::response& res, connection_context& ctxt);
+ bool on_request_api_2(const COMMAND_EXAMPLE_2::request& req, COMMAND_EXAMPLE_2::response& res, connection_context& ctxt);
- bool on_request_api_1_with_error(const COMMAND_EXAMPLE_1::request& req, COMMAND_EXAMPLE_1::response& res, epee::json_rpc::error& error_resp);
+ bool on_request_api_1_with_error(const COMMAND_EXAMPLE_1::request& req, COMMAND_EXAMPLE_1::response& res, epee::json_rpc::error& error_resp, connection_context& ctxt);
net_utils::boosted_http_server_custum_handling m_net_server;
std::atomic<bool> m_stop;
diff --git a/contrib/epee/demo/demo_levin_server/demo_levin_server.cpp b/contrib/epee/demo/demo_levin_server/demo_levin_server.cpp
index 215b1dd48..a99a1f564 100644
--- a/contrib/epee/demo/demo_levin_server/demo_levin_server.cpp
+++ b/contrib/epee/demo/demo_levin_server/demo_levin_server.cpp
@@ -101,7 +101,7 @@ int main(int argc, char* argv[])
demo::demo_levin_server srv;
- start_default_console(&srv);
+ start_default_console(&srv, "#");
std::string bind_param = "0.0.0.0";
std::string port = "12345";
diff --git a/contrib/epee/demo/iface/transport_defs.h b/contrib/epee/demo/iface/transport_defs.h
index 97f6caadd..8463eb903 100644
--- a/contrib/epee/demo/iface/transport_defs.h
+++ b/contrib/epee/demo/iface/transport_defs.h
@@ -1,7 +1,7 @@
#pragma once
#include "serialization/keyvalue_serialization.h"
-
+#include "storages/portable_storage_base.h"
namespace demo
{
@@ -41,6 +41,8 @@ namespace demo
std::list<bool> m_list_of_bool;
some_test_subdata m_subobj;
std::list<some_test_data> m_list_of_self;
+ epee::serialization::storage_entry m_storage_entry_int;
+ epee::serialization::storage_entry m_storage_entry_string;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(m_str)
@@ -67,6 +69,8 @@ namespace demo
KV_SERIALIZE(m_list_of_double)
KV_SERIALIZE(m_list_of_bool)
KV_SERIALIZE(m_list_of_self)
+ KV_SERIALIZE(m_storage_entry_int)
+ KV_SERIALIZE(m_storage_entry_string)
END_KV_SERIALIZE_MAP()
};
@@ -162,6 +166,8 @@ namespace demo
|| b.m_list_of_bool != a.m_list_of_bool
|| b.m_subobj != a.m_subobj
|| b.m_list_of_self != a.m_list_of_self
+ || b.m_storage_entry_int.which() != a.m_storage_entry_int.which()
+ || b.m_storage_entry_string.which() != a.m_storage_entry_string.which()
)
return false;
return true;
@@ -208,6 +214,8 @@ namespace demo
s.m_subobj.m_str = "subszzzzzzzz";
s.m_list_of_self.push_back(s);
+ s.m_storage_entry_int = epee::serialization::storage_entry(uint64_t(22222));;
+ s.m_storage_entry_string = epee::serialization::storage_entry(std::string("sdsvsdvs"));
return s;
}
} \ No newline at end of file
diff --git a/contrib/epee/include/console_handler.h b/contrib/epee/include/console_handler.h
index 65414a265..5798d2def 100644
--- a/contrib/epee/include/console_handler.h
+++ b/contrib/epee/include/console_handler.h
@@ -311,7 +311,7 @@ namespace epee
bool start_default_console(t_server* ptsrv, t_handler handlr, const std::string& prompt, const std::string& usage = "")
{
std::shared_ptr<async_console_handler> console_handler = std::make_shared<async_console_handler>();
- boost::thread(boost::bind(&async_console_handler::run<t_server, t_handler>, console_handler, ptsrv, handlr, prompt, usage)).detach();
+ boost::thread([=](){console_handler->run<t_server, t_handler>(ptsrv, handlr, prompt, usage);}).detach();
return true;
}
diff --git a/contrib/epee/include/net/http_protocol_handler.inl b/contrib/epee/include/net/http_protocol_handler.inl
index b8eeb5993..78b46427e 100644
--- a/contrib/epee/include/net/http_protocol_handler.inl
+++ b/contrib/epee/include/net/http_protocol_handler.inl
@@ -587,7 +587,7 @@ namespace net_utils
{
std::string buf = "HTTP/1.1 ";
buf += boost::lexical_cast<std::string>(response.m_response_code) + " " + response.m_response_comment + "\r\n" +
- "Server: Siski v0.1\r\n"
+ "Server: Epee-based\r\n"
"Content-Length: ";
buf += boost::lexical_cast<std::string>(response.m_body.size()) + "\r\n";
buf += "Content-Type: ";
diff --git a/contrib/epee/include/net/http_server_handlers_map2.h b/contrib/epee/include/net/http_server_handlers_map2.h
index 0b6ffa095..af4e035f8 100644
--- a/contrib/epee/include/net/http_server_handlers_map2.h
+++ b/contrib/epee/include/net/http_server_handlers_map2.h
@@ -120,7 +120,7 @@ namespace epee
{
std::string jsonrpc;
std::string method;
- std::string id;
+ epee::serialization::storage_entry id;
t_param params;
BEGIN_KV_SERIALIZE_MAP()
@@ -158,7 +158,7 @@ namespace epee
{
std::string jsonrpc;
t_param result;
- std::string id;
+ epee::serialization::storage_entry id;
t_error error;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(jsonrpc)
@@ -173,7 +173,7 @@ namespace epee
{
std::string jsonrpc;
t_param result;
- std::string id;
+ epee::serialization::storage_entry id;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(jsonrpc)
KV_SERIALIZE(id)
@@ -186,7 +186,7 @@ namespace epee
{
std::string jsonrpc;
t_error error;
- std::string id;
+ epee::serialization::storage_entry id;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(jsonrpc)
KV_SERIALIZE(id)
@@ -213,6 +213,9 @@ namespace epee
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(rsp), response_info.m_body); \
return true; \
} \
+ epee::serialization::storage_entry id_; \
+ id_ = epee::serialization::storage_entry(std::string()); \
+ ps.get_value("id", id_, nullptr); \
std::string callback_name; \
if(!ps.get_value("method", callback_name, nullptr)) \
{ \
@@ -225,18 +228,39 @@ namespace epee
} \
if(false) return true; //just a stub to have "else if"
-#define MAP_JON_RPC_WE(method_name, callback_f, command_type) \
- else if(callback_name == method_name) \
-{ \
+
+#define PREPARE_OBJECTS_FROM_JSON(command_type) \
handled = true; \
boost::value_initialized<epee::json_rpc::request<command_type::request> > req_; \
epee::json_rpc::request<command_type::request>& req = static_cast<epee::json_rpc::request<command_type::request>&>(req_);\
- req.load(ps); \
+ if(!req.load(ps)) \
+ { \
+ epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
+ fail_resp.jsonrpc = "2.0"; \
+ fail_resp.id = req.id; \
+ fail_resp.error.code = -32602; \
+ fail_resp.error.message = "Invalid params"; \
+ epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
+ return true; \
+ } \
uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
boost::value_initialized<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> > resp_; \
epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error>& resp = static_cast<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> &>(resp_); \
resp.jsonrpc = "2.0"; \
- resp.id = req.id; \
+ resp.id = req.id;
+
+#define FINALIZE_OBJECTS_TO_JSON(method_name) \
+ uint64_t ticks2 = epee::misc_utils::get_tick_count(); \
+ epee::serialization::store_t_to_json(resp, response_info.m_body); \
+ uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
+ response_info.m_mime_tipe = "application/json"; \
+ response_info.m_header_info.m_content_type = " application/json"; \
+ LOG_PRINT( query_info.m_URI << "[" << method_name << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2);
+
+#define MAP_JON_RPC_WE(method_name, callback_f, command_type) \
+ else if(callback_name == method_name) \
+{ \
+ PREPARE_OBJECTS_FROM_JSON(command_type) \
epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
fail_resp.jsonrpc = "2.0"; \
fail_resp.id = req.id; \
@@ -245,27 +269,14 @@ namespace epee
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
return true; \
} \
- uint64_t ticks2 = epee::misc_utils::get_tick_count(); \
- epee::serialization::store_t_to_json(resp, response_info.m_body); \
- uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
- response_info.m_mime_tipe = "application/json"; \
- response_info.m_header_info.m_content_type = " application/json"; \
- LOG_PRINT( query_info.m_URI << "[" << method_name << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2); \
+ FINALIZE_OBJECTS_TO_JSON(method_name) \
return true;\
}
#define MAP_JON_RPC_WERI(method_name, callback_f, command_type) \
else if(callback_name == method_name) \
{ \
- handled = true; \
- boost::value_initialized<epee::json_rpc::request<command_type::request> > req_; \
- epee::json_rpc::request<command_type::request>& req = static_cast<epee::json_rpc::request<command_type::request>&>(req_);\
- req.load(ps); \
- uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
- boost::value_initialized<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> > resp_; \
- epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error>& resp = static_cast<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> &>(resp_); \
- resp.jsonrpc = "2.0"; \
- resp.id = req.id; \
+ PREPARE_OBJECTS_FROM_JSON(command_type) \
epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
fail_resp.jsonrpc = "2.0"; \
fail_resp.id = req.id; \
@@ -274,28 +285,14 @@ namespace epee
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
return true; \
} \
- uint64_t ticks2 = epee::misc_utils::get_tick_count(); \
- epee::serialization::store_t_to_json(resp, response_info.m_body); \
- uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
- response_info.m_mime_tipe = "application/json"; \
- response_info.m_header_info.m_content_type = " application/json"; \
- LOG_PRINT( query_info.m_URI << "[" << method_name << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2); \
+ FINALIZE_OBJECTS_TO_JSON(method_name) \
return true;\
}
-
#define MAP_JON_RPC(method_name, callback_f, command_type) \
else if(callback_name == method_name) \
{ \
- handled = true; \
- boost::value_initialized<epee::json_rpc::request<command_type::request> > req_; \
- epee::json_rpc::request<command_type::request>& req = static_cast<epee::json_rpc::request<command_type::request>&>(req_);\
- req.load(ps); \
- uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
- boost::value_initialized<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> > resp_; \
- epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error>& resp = static_cast<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> &>(resp_); \
- resp.jsonrpc = "2.0"; \
- resp.id = req.id; \
+ PREPARE_OBJECTS_FROM_JSON(command_type) \
if(!callback_f(req.params, resp.result, m_conn_context)) \
{ \
epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
@@ -306,18 +303,13 @@ namespace epee
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
return true; \
} \
- uint64_t ticks2 = epee::misc_utils::get_tick_count(); \
- epee::serialization::store_t_to_json(resp, response_info.m_body); \
- uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
- response_info.m_mime_tipe = "application/json"; \
- response_info.m_header_info.m_content_type = " application/json"; \
- LOG_PRINT( query_info.m_URI << "[" << method_name << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2); \
+ FINALIZE_OBJECTS_TO_JSON(method_name) \
return true;\
}
-
#define END_JSON_RPC_MAP() \
epee::json_rpc::error_response rsp; \
+ rsp.id = id_; \
rsp.jsonrpc = "2.0"; \
rsp.error.code = -32601; \
rsp.error.message = "Method not found"; \
diff --git a/contrib/epee/include/serialization/keyvalue_serialization_overloads.h b/contrib/epee/include/serialization/keyvalue_serialization_overloads.h
index 2ad9a82a4..54535a404 100644
--- a/contrib/epee/include/serialization/keyvalue_serialization_overloads.h
+++ b/contrib/epee/include/serialization/keyvalue_serialization_overloads.h
@@ -280,7 +280,9 @@ namespace epee
return unserialize_stl_container_t_obj(d, stg, hparent_section, pname);
}
};
- typedef boost::mpl::vector<uint64_t, uint32_t, uint16_t, uint8_t, int64_t, int32_t, int16_t, int8_t, double, bool, std::string>::type base_serializable_types;
+ template<class t_storage>
+ struct base_serializable_types: public boost::mpl::vector<uint64_t, uint32_t, uint16_t, uint8_t, int64_t, int32_t, int16_t, int8_t, double, bool, std::string, typename t_storage::meta_entry>::type
+ {};
//-------------------------------------------------------------------------------------------------------------------
template<bool> struct selector;
template<>
@@ -330,37 +332,37 @@ namespace epee
template<class t_type, class t_storage>
bool kv_serialize(const t_type& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
{
- return kv_serialization_overloads_impl_is_base_serializable_types<boost::mpl::contains<base_serializable_types, typename std::remove_const<t_type>::type>::value>::kv_serialize(d, stg, hparent_section, pname);
+ return kv_serialization_overloads_impl_is_base_serializable_types<boost::mpl::contains<base_serializable_types<t_storage>, typename std::remove_const<t_type>::type>::value>::kv_serialize(d, stg, hparent_section, pname);
}
//-------------------------------------------------------------------------------------------------------------------
template<class t_type, class t_storage>
bool kv_unserialize(t_type& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
{
- return kv_serialization_overloads_impl_is_base_serializable_types<boost::mpl::contains<base_serializable_types, typename std::remove_const<t_type>::type>::value>::kv_unserialize(d, stg, hparent_section, pname);
+ return kv_serialization_overloads_impl_is_base_serializable_types<boost::mpl::contains<base_serializable_types<t_storage>, typename std::remove_const<t_type>::type>::value>::kv_unserialize(d, stg, hparent_section, pname);
}
//-------------------------------------------------------------------------------------------------------------------
template<class t_type, class t_storage>
bool kv_serialize(const std::vector<t_type>& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
{
- return kv_serialization_overloads_impl_is_base_serializable_types<boost::mpl::contains<base_serializable_types, typename std::remove_const<t_type>::type>::value>::kv_serialize(d, stg, hparent_section, pname);
+ return kv_serialization_overloads_impl_is_base_serializable_types<boost::mpl::contains<base_serializable_types<t_storage>, typename std::remove_const<t_type>::type>::value>::kv_serialize(d, stg, hparent_section, pname);
}
//-------------------------------------------------------------------------------------------------------------------
template<class t_type, class t_storage>
bool kv_unserialize(std::vector<t_type>& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
{
- return kv_serialization_overloads_impl_is_base_serializable_types<boost::mpl::contains<base_serializable_types, typename std::remove_const<t_type>::type>::value>::kv_unserialize(d, stg, hparent_section, pname);
+ return kv_serialization_overloads_impl_is_base_serializable_types<boost::mpl::contains<base_serializable_types<t_storage>, typename std::remove_const<t_type>::type>::value>::kv_unserialize(d, stg, hparent_section, pname);
}
//-------------------------------------------------------------------------------------------------------------------
template<class t_type, class t_storage>
bool kv_serialize(const std::list<t_type>& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
{
- return kv_serialization_overloads_impl_is_base_serializable_types<boost::mpl::contains<base_serializable_types, typename std::remove_const<t_type>::type>::value>::kv_serialize(d, stg, hparent_section, pname);
+ return kv_serialization_overloads_impl_is_base_serializable_types<boost::mpl::contains<base_serializable_types<t_storage>, typename std::remove_const<t_type>::type>::value>::kv_serialize(d, stg, hparent_section, pname);
}
//-------------------------------------------------------------------------------------------------------------------
template<class t_type, class t_storage>
bool kv_unserialize(std::list<t_type>& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
{
- return kv_serialization_overloads_impl_is_base_serializable_types<boost::mpl::contains<base_serializable_types, typename std::remove_const<t_type>::type>::value>::kv_unserialize(d, stg, hparent_section, pname);
+ return kv_serialization_overloads_impl_is_base_serializable_types<boost::mpl::contains<base_serializable_types<t_storage>, typename std::remove_const<t_type>::type>::value>::kv_unserialize(d, stg, hparent_section, pname);
}
}
} \ No newline at end of file
diff --git a/contrib/epee/include/storages/portable_storage.h b/contrib/epee/include/storages/portable_storage.h
index 8f4ebc6ae..c244dac19 100644
--- a/contrib/epee/include/storages/portable_storage.h
+++ b/contrib/epee/include/storages/portable_storage.h
@@ -48,12 +48,14 @@ namespace epee
public:
typedef epee::serialization::hsection hsection;
typedef epee::serialization::harray harray;
+ typedef storage_entry meta_entry;
portable_storage(){}
virtual ~portable_storage(){}
hsection open_section(const std::string& section_name, hsection hparent_section, bool create_if_notexist = false);
template<class t_value>
bool get_value(const std::string& value_name, t_value& val, hsection hparent_section);
+ bool get_value(const std::string& value_name, storage_entry& val, hsection hparent_section);
template<class t_value>
bool set_value(const std::string& value_name, const t_value& target, hsection hparent_section);
@@ -221,10 +223,24 @@ namespace epee
//CATCH_ENTRY("portable_storage::template<>get_value", false);
}
//---------------------------------------------------------------------------------------------------------------
+ inline
+ bool portable_storage::get_value(const std::string& value_name, storage_entry& val, hsection hparent_section)
+ {
+ //TRY_ENTRY();
+ if(!hparent_section) hparent_section = &m_root;
+ storage_entry* pentry = find_storage_entry(value_name, hparent_section);
+ if(!pentry)
+ return false;
+
+ val = *pentry;
+ return true;
+ //CATCH_ENTRY("portable_storage::template<>get_value", false);
+ }
+ //---------------------------------------------------------------------------------------------------------------
template<class t_value>
bool portable_storage::set_value(const std::string& value_name, const t_value& v, hsection hparent_section)
{
- BOOST_MPL_ASSERT(( boost::mpl::contains<storage_entry::types, t_value> ));
+ BOOST_MPL_ASSERT(( boost::mpl::contains<boost::mpl::push_front<storage_entry::types, storage_entry>::type, t_value> ));
TRY_ENTRY();
if(!hparent_section)
hparent_section = &m_root;
diff --git a/include/INode.h b/include/INode.h
new file mode 100644
index 000000000..bd35dccc5
--- /dev/null
+++ b/include/INode.h
@@ -0,0 +1,37 @@
+// Copyright (c) 2012-2013 The Cryptonote developers
+// Distributed under the MIT/X11 software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#pragma once
+
+#include <cstdint>
+#include <system_error>
+
+namespace cryptonote {
+
+class INodeObserver {
+public:
+ virtual void initCompleted(std::error_code result) {}
+
+ virtual void peerCountUpdated(size_t count) {}
+ virtual void lastLocalBlockHeightUpdated(uint64_t height) {}
+ virtual void lastKnownBlockHeightUpdated(uint64_t height) {}
+
+ virtual void blockchainReorganized(uint64_t height) {}
+};
+
+class INode {
+public:
+ virtual ~INode() = 0;
+ virtual void init() = 0;
+ virtual void shutdown() = 0;
+
+ virtual void addObserver(INodeObserver* observer) = 0;
+ virtual void removeObserver(INodeObserver* observer) = 0;
+
+ virtual size_t getPeerCount() = 0;
+ virtual uint64_t getLastLocalBlockHeight() = 0;
+ virtual uint64_t getLastKnownBlockHeight() = 0;
+};
+
+}
diff --git a/include/IWallet.h b/include/IWallet.h
new file mode 100644
index 000000000..d48f69d5f
--- /dev/null
+++ b/include/IWallet.h
@@ -0,0 +1,87 @@
+// Copyright (c) 2012-2013 The Cryptonote developers
+// Distributed under the MIT/X11 software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#pragma once
+
+#include <array>
+#include <cstdint>
+#include <istream>
+#include <limits>
+#include <ostream>
+#include <string>
+#include <system_error>
+#include <vector>
+
+namespace cryptonote {
+
+typedef size_t TransactionId;
+typedef size_t TransferId;
+typedef std::array<uint8_t, 32> TransacitonHash;
+
+struct Transfer {
+ std::string address;
+ int64_t amount;
+};
+
+const TransactionId INVALID_TRANSACTION_ID = std::numeric_limits<TransactionId>::max();
+const TransferId INVALID_TRANSFER_ID = std::numeric_limits<TransferId>::max();
+const uint64_t UNCONFIRMED_TRANSACTION_HEIGHT = std::numeric_limits<uint64_t>::max();
+
+struct Transaction {
+ TransferId firstTransferId;
+ size_t transferCount;
+ int64_t totalAmount;
+ uint64_t fee;
+ TransacitonHash hash;
+ bool isCoinbase;
+ uint64_t blockHeight;
+ uint64_t timestamp;
+ std::string extra;
+};
+
+class IWalletObserver {
+public:
+ virtual void initCompleted(std::error_code result) {}
+ virtual void saveCompleted(std::error_code result) {}
+ virtual void synchronizationProgressUpdated(uint64_t current, uint64_t total) {}
+ virtual void actualBalanceUpdated(uint64_t actualBalance) {}
+ virtual void pendingBalanceUpdated(uint64_t pendingBalance) {}
+ virtual void externalTransactionCreated(TransactionId transactionId) {}
+ virtual void sendTransactionCompleted(TransactionId transactionId, std::error_code result) {}
+ virtual void transactionUpdated(TransactionId transactionId) {}
+};
+
+class IWallet {
+public:
+ virtual ~IWallet() = 0;
+ virtual void addObserver(IWalletObserver* observer) = 0;
+ virtual void removeObserver(IWalletObserver* observer) = 0;
+
+ virtual void initAndGenerate(const std::string& password) = 0;
+ virtual void initAndLoad(std::istream& source, const std::string& password) = 0;
+ virtual void shutdown() = 0;
+
+ virtual void save(std::ostream& destination, bool saveDetailed = true, bool saveCache = true) = 0;
+
+ virtual std::error_code changePassword(const std::string& oldPassword, const std::string& newPassword) = 0;
+
+ virtual std::string getAddress() = 0;
+
+ virtual uint64_t actualBalance() = 0;
+ virtual uint64_t pendingBalance() = 0;
+
+ virtual size_t getTransactionCount() = 0;
+ virtual size_t getTransferCount() = 0;
+
+ virtual TransactionId findTransactionByTransferId(TransferId transferId) = 0;
+
+ virtual bool getTransaction(TransactionId transactionId, Transaction& transaction) = 0;
+ virtual bool getTransfer(TransferId transferId, Transfer& transfer) = 0;
+
+ virtual TransactionId sendTransaction(const Transfer& transfer, uint64_t fee, const std::string& extra = "", uint64_t mixIn = 0, uint64_t unlockTimestamp = 0) = 0;
+ virtual TransactionId sendTransaction(const std::vector<Transfer>& transfers, uint64_t fee, const std::string& extra = "", uint64_t mixIn = 0, uint64_t unlockTimestamp = 0) = 0;
+ virtual std::error_code cancelTransaction(size_t transferId) = 0;
+};
+
+}
diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h
index 35dfcb3bb..9f0b5bd9b 100644
--- a/src/cryptonote_config.h
+++ b/src/cryptonote_config.h
@@ -64,7 +64,7 @@
#define P2P_DEFAULT_PEERS_IN_HANDSHAKE 250
#define P2P_DEFAULT_CONNECTION_TIMEOUT 5000 //5 seconds
#define P2P_DEFAULT_PING_CONNECTION_TIMEOUT 2000 //2 seconds
-#define P2P_DEFAULT_INVOKE_TIMEOUT 20*1000 //2 minutes
+#define P2P_DEFAULT_INVOKE_TIMEOUT 60*2*1000 //2 minutes
#define P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT 5000 //5 seconds
#define P2P_STAT_TRUSTED_PUB_KEY "8f80f9a5a434a9f1510d13336228debfee9c918ce505efe225d8c94d045fa115"
#define P2P_DEFAULT_WHITELIST_CONNECTIONS_PERCENT 70
diff --git a/src/cryptonote_core/blockchain_storage.h b/src/cryptonote_core/blockchain_storage.h
index 5a3ff3d84..1ea5e29ea 100644
--- a/src/cryptonote_core/blockchain_storage.h
+++ b/src/cryptonote_core/blockchain_storage.h
@@ -63,9 +63,6 @@ namespace cryptonote
bool get_blocks(uint64_t start_offset, size_t count, std::list<block>& blocks, std::list<transaction>& txs);
bool get_blocks(uint64_t start_offset, size_t count, std::list<block>& blocks);
bool get_alternative_blocks(std::list<block>& blocks);
- //bool get_orphaned_blocks(std::list<block>& orphaned_by_prev_id, std::list<block>& orphaned_by_tx);
- //size_t get_orphaned_by_prev_blocks_count();
- //size_t get_orphaned_by_tx_blocks_count();
size_t get_alternative_blocks_count();
crypto::hash get_block_id_by_height(uint64_t height);
bool get_block_by_hash(const crypto::hash &h, block &blk);
@@ -87,7 +84,6 @@ namespace cryptonote
crypto::hash get_tail_id(uint64_t& height);
difficulty_type get_difficulty_for_next_block();
bool add_new_block(const block& bl_, block_verification_context& bvc);
-
bool reset_and_set_genesis_block(const block& b);
bool create_block_template(block& b, const account_public_address& miner_address, difficulty_type& di, uint64_t& height, const blobdata& ex_nonce);
bool have_block(const crypto::hash& id);
@@ -97,11 +93,9 @@ namespace cryptonote
bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp);
bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, uint64_t& starter_offset);
bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count);
- //bool get_chain_entry(const NOTIFY_REQUEST_CHAIN_ENTRY::request& req, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp);
bool handle_get_objects(NOTIFY_REQUEST_GET_OBJECTS::request& arg, NOTIFY_RESPONSE_GET_OBJECTS::request& rsp);
bool handle_get_objects(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res);
bool get_random_outs_for_amounts(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res);
- //bool get_outs_for_amounts(uint64_t amount, std::vector<std::pair<crypto::hash, size_t> >& keys, std::map<crypto::hash, transaction>& txs);
bool get_backward_blocks_sizes(size_t from_height, std::vector<size_t>& sz, size_t count);
bool get_tx_outputs_gindexs(const crypto::hash& tx_id, std::vector<uint64_t>& indexs);
bool store_blockchain();
@@ -111,6 +105,7 @@ namespace cryptonote
bool check_tx_inputs(const transaction& tx, uint64_t& pmax_used_block_height, crypto::hash& max_used_block_id);
uint64_t get_current_comulative_blocksize_limit();
bool is_storing_blockchain(){return m_is_blockchain_storing;}
+ uint64_t block_difficulty(size_t i);
template<class t_ids_container, class t_blocks_container, class t_missed_container>
bool get_blocks(const t_ids_container& block_ids, t_blocks_container& blocks, t_missed_container& missed_bs)
@@ -191,9 +186,6 @@ namespace cryptonote
std::atomic<bool> m_is_in_checkpoint_zone;
std::atomic<bool> m_is_blockchain_storing;
-
-
-
bool switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::iterator>& alt_chain);
bool pop_block_from_blockchain();
bool purge_block_data_from_blockchain(const block& b, size_t processed_tx_count);
@@ -203,26 +195,20 @@ namespace cryptonote
bool handle_block_to_main_chain(const block& bl, block_verification_context& bvc);
bool handle_block_to_main_chain(const block& bl, const crypto::hash& id, block_verification_context& bvc);
bool handle_alternative_block(const block& b, const crypto::hash& id, block_verification_context& bvc);
- //bool handle_block_as_orphaned(const block& b, const crypto::hash& id, block_verification_context& bvc);
difficulty_type get_next_difficulty_for_alternative_chain(const std::list<blocks_ext_by_hash::iterator>& alt_chain, block_extended_info& bei);
bool prevalidate_miner_transaction(const block& b, uint64_t height);
bool validate_miner_transaction(const block& b, size_t cumulative_block_size, uint64_t fee, uint64_t& base_reward, uint64_t already_generated_coins);
bool validate_transaction(const block& b, uint64_t height, const transaction& tx);
- //bool add_block_to_orphaned_by_tx(const block& bl, const crypto::hash& h);
- //bool finish_forward_orphaned_chain(std::list< orphans_indexed_container::index<by_id>::type::iterator >& orph_chain);
bool rollback_blockchain_switching(std::list<block>& original_chain, size_t rollback_height);
bool add_transaction_from_block(const transaction& tx, const crypto::hash& tx_id, const crypto::hash& bl_id, uint64_t bl_height);
bool push_transaction_to_global_outs_index(const transaction& tx, const crypto::hash& tx_id, std::vector<uint64_t>& global_indexes);
bool pop_transaction_from_global_index(const transaction& tx, const crypto::hash& tx_id);
- //bool review_orphaned_blocks_with_new_block_id(const crypto::hash& id, bool main_chain);
- //void review_orphaned_blocks_finisher();
bool get_last_n_blocks_sizes(std::vector<size_t>& sz, size_t count);
bool add_out_to_get_random_outs(std::vector<std::pair<crypto::hash, size_t> >& amount_outs, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& result_outs, uint64_t amount, size_t i);
bool is_tx_spendtime_unlocked(uint64_t unlock_time);
bool add_block_as_invalid(const block& bl, const crypto::hash& h);
bool add_block_as_invalid(const block_extended_info& bei, const crypto::hash& h);
size_t find_end_of_allowed_index(const std::vector<std::pair<crypto::hash, size_t> >& amount_outs);
- uint64_t block_difficulty(size_t i);
bool check_block_timestamp_main(const block& b);
bool check_block_timestamp(std::vector<uint64_t> timestamps, const block& b);
uint64_t get_adjusted_time();
diff --git a/src/cryptonote_core/cryptonote_format_utils.h b/src/cryptonote_core/cryptonote_format_utils.h
index 8f42b807a..554e466cc 100644
--- a/src/cryptonote_core/cryptonote_format_utils.h
+++ b/src/cryptonote_core/cryptonote_format_utils.h
@@ -36,7 +36,7 @@ namespace cryptonote
uint64_t amount; //money
account_public_address addr; //destination address
- tx_destination_entry() { }
+ tx_destination_entry() : amount(0), addr(AUTO_VAL_INIT(addr)) { }
tx_destination_entry(uint64_t a, const account_public_address &ad) : amount(a), addr(ad) { }
};
diff --git a/src/cryptonote_core/miner.cpp b/src/cryptonote_core/miner.cpp
index a882e1899..142c81f68 100644
--- a/src/cryptonote_core/miner.cpp
+++ b/src/cryptonote_core/miner.cpp
@@ -48,7 +48,8 @@ namespace cryptonote
m_last_hr_merge_time(0),
m_hashes(0),
m_do_print_hashrate(false),
- m_do_mining(false)
+ m_do_mining(false),
+ m_current_hash_rate(0)
{
}
@@ -225,7 +226,10 @@ namespace cryptonote
//-----------------------------------------------------------------------------------------------------
uint64_t miner::get_speed()
{
- return m_current_hash_rate;
+ if(is_mining())
+ return m_current_hash_rate;
+ else
+ return 0;
}
//-----------------------------------------------------------------------------------------------------
void miner::send_stop_signal()
diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp
index b537f91ca..329f44e7f 100644
--- a/src/daemon/daemon.cpp
+++ b/src/daemon/daemon.cpp
@@ -48,7 +48,7 @@ int main(int argc, char* argv[])
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
log_space::get_set_log_detalisation_level(true, LOG_LEVEL_0);
- log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, 0);
+ log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL);
LOG_PRINT_L0("Starting...");
TRY_ENTRY();
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index a8aa7dc00..a4cae0480 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -92,10 +92,10 @@ namespace
}
template<typename T>
- message_writer& operator<<(const T& val)
+ std::ostream& operator<<(const T& val)
{
m_oss << val;
- return *this;
+ return m_oss;
}
~message_writer()
@@ -166,7 +166,7 @@ simple_wallet::simple_wallet()
: m_daemon_port(0)
, m_refresh_progress_reporter(*this)
{
- m_cmd_binder.set_handler("start_mining", boost::bind(&simple_wallet::start_mining, this, _1), "start_mining <threads_count> - Start mining in daemon");
+ m_cmd_binder.set_handler("start_mining", boost::bind(&simple_wallet::start_mining, this, _1), "start_mining [<number_of_threads>] - Start mining in daemon");
m_cmd_binder.set_handler("stop_mining", boost::bind(&simple_wallet::stop_mining, this, _1), "Stop mining in daemon");
m_cmd_binder.set_handler("refresh", boost::bind(&simple_wallet::refresh, this, _1), "Resynchronize transactions and balance");
m_cmd_binder.set_handler("balance", boost::bind(&simple_wallet::show_balance, this, _1), "Show current wallet balance");
@@ -295,7 +295,7 @@ bool simple_wallet::new_wallet(const string &wallet_file, const std::string& pas
try
{
m_wallet->generate(wallet_file, password);
- message_writer(epee::log_space::console_color_white, true) << "Generated new wallet: " << m_wallet->get_account().get_public_address_str();
+ message_writer(epee::log_space::console_color_white, true) << "Generated new wallet: " << m_wallet->get_account().get_public_address_str() << std::endl << "view key: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key);
}
catch (const std::exception& e)
{
@@ -389,6 +389,8 @@ bool simple_wallet::start_mining(const std::vector<std::string>& args)
COMMAND_RPC_START_MINING::request req;
req.miner_address = m_wallet->get_account().get_public_address_str();
+ bool ok = true;
+ size_t max_mining_threads_count = (std::max)(std::thread::hardware_concurrency(), static_cast<unsigned>(2));
if (0 == args.size())
{
req.threads_count = 1;
@@ -396,17 +398,19 @@ bool simple_wallet::start_mining(const std::vector<std::string>& args)
else if (1 == args.size())
{
uint16_t num;
- bool ok = string_tools::get_xtype_from_string(num, args[0]);
- if(!ok || 0 == num)
- {
- fail_msg_writer() << "wrong number of mining threads: \"" << args[0] << "\"";
- return true;
- }
+ ok = string_tools::get_xtype_from_string(num, args[0]);
+ ok &= (1 <= num && num <= max_mining_threads_count);
req.threads_count = num;
}
else
{
- fail_msg_writer() << "wrong number of arguments, expected the number of mining threads";
+ ok = false;
+ }
+
+ if (!ok)
+ {
+ fail_msg_writer() << "invalid arguments. Please use start_mining [<number_of_threads>], " <<
+ "<number_of_threads> should be from 1 to " << max_mining_threads_count;
return true;
}
diff --git a/src/version.h.in b/src/version.h.in
index b4e144387..2fc114a34 100644
--- a/src/version.h.in
+++ b/src/version.h.in
@@ -1,4 +1,4 @@
#define BUILD_COMMIT_ID "@VERSION@"
-#define PROJECT_VERSION "0.8.3"
-#define PROJECT_VERSION_BUILD_NO "288"
+#define PROJECT_VERSION "0.8.4"
+#define PROJECT_VERSION_BUILD_NO "289"
#define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO "(" BUILD_COMMIT_ID ")"
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 572affb2f..e8b6c22fd 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -38,10 +38,10 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
uint64_t tx_money_got_in_outs = 0;
crypto::public_key tx_pub_key = null_pkey;
bool r = parse_and_validate_tx_extra(tx, tx_pub_key);
- CHECK_AND_THROW_WALLET_EX(!r, error::tx_extra_parse_error, tx);
+ THROW_WALLET_EXCEPTION_IF(!r, error::tx_extra_parse_error, tx);
r = lookup_acc_outs(m_account.get_keys(), tx, tx_pub_key, outs, tx_money_got_in_outs);
- CHECK_AND_THROW_WALLET_EX(!r, error::acc_outs_lookup_error, tx, tx_pub_key, m_account.get_keys());
+ THROW_WALLET_EXCEPTION_IF(!r, error::acc_outs_lookup_error, tx, tx_pub_key, m_account.get_keys());
if(!outs.empty() && tx_money_got_in_outs)
{
@@ -51,16 +51,16 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
cryptonote::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response res = AUTO_VAL_INIT(res);
req.txid = get_transaction_hash(tx);
bool r = net_utils::invoke_http_bin_remote_command2(m_daemon_address + "/get_o_indexes.bin", req, res, m_http_client, WALLET_RCP_CONNECTION_TIMEOUT);
- CHECK_AND_THROW_WALLET_EX(!r, error::no_connection_to_daemon, "get_o_indexes.bin");
- CHECK_AND_THROW_WALLET_EX(res.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "get_o_indexes.bin");
- CHECK_AND_THROW_WALLET_EX(res.status != CORE_RPC_STATUS_OK, error::get_out_indices_error, res.status);
- CHECK_AND_THROW_WALLET_EX(res.o_indexes.size() != tx.vout.size(), error::wallet_internal_error,
+ THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "get_o_indexes.bin");
+ THROW_WALLET_EXCEPTION_IF(res.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "get_o_indexes.bin");
+ THROW_WALLET_EXCEPTION_IF(res.status != CORE_RPC_STATUS_OK, error::get_out_indices_error, res.status);
+ THROW_WALLET_EXCEPTION_IF(res.o_indexes.size() != tx.vout.size(), error::wallet_internal_error,
"transactions outputs size=" + std::to_string(tx.vout.size()) +
" not match with COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES response size=" + std::to_string(res.o_indexes.size()));
BOOST_FOREACH(size_t o, outs)
{
- CHECK_AND_THROW_WALLET_EX(tx.vout.size() <= o, error::wallet_internal_error, "wrong out in transaction: internal index=" +
+ THROW_WALLET_EXCEPTION_IF(tx.vout.size() <= o, error::wallet_internal_error, "wrong out in transaction: internal index=" +
std::to_string(o) + ", total_outs=" + std::to_string(tx.vout.size()));
m_transfers.push_back(boost::value_initialized<transfer_details>());
@@ -72,7 +72,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
td.m_spent = false;
cryptonote::keypair in_ephemeral;
cryptonote::generate_key_image_helper(m_account.get_keys(), tx_pub_key, o, in_ephemeral, td.m_key_image);
- CHECK_AND_THROW_WALLET_EX(in_ephemeral.pub != boost::get<cryptonote::txout_to_key>(tx.vout[o].target).key,
+ THROW_WALLET_EXCEPTION_IF(in_ephemeral.pub != boost::get<cryptonote::txout_to_key>(tx.vout[o].target).key,
error::wallet_internal_error, "key_image generated ephemeral public key not matched with output_key");
m_key_images[td.m_key_image] = m_transfers.size()-1;
@@ -108,7 +108,7 @@ void wallet2::process_unconfirmed(const cryptonote::transaction& tx)
void wallet2::process_new_blockchain_entry(const cryptonote::block& b, cryptonote::block_complete_entry& bche, crypto::hash& bl_id, uint64_t height)
{
//handle transactions from new block
- CHECK_AND_THROW_WALLET_EX(height != m_blockchain.size(), error::wallet_internal_error,
+ THROW_WALLET_EXCEPTION_IF(height != m_blockchain.size(), error::wallet_internal_error,
"current_index=" + std::to_string(height) + ", m_blockchain.size()=" + std::to_string(m_blockchain.size()));
//optimization: seeking only for blocks that are not older then the wallet creation time plus 1 day. 1 day is for possible user incorrect time setup
@@ -123,7 +123,7 @@ void wallet2::process_new_blockchain_entry(const cryptonote::block& b, cryptonot
{
cryptonote::transaction tx;
bool r = parse_and_validate_tx_from_blob(txblob, tx);
- CHECK_AND_THROW_WALLET_EX(!r, error::tx_parse_error, txblob);
+ THROW_WALLET_EXCEPTION_IF(!r, error::tx_parse_error, txblob);
process_new_transaction(tx, height);
}
TIME_MEASURE_FINISH(txs_handle_time);
@@ -173,10 +173,10 @@ void wallet2::pull_blocks(size_t& blocks_added)
cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::response res = AUTO_VAL_INIT(res);
get_short_chain_history(req.block_ids);
bool r = net_utils::invoke_http_bin_remote_command2(m_daemon_address + "/getblocks.bin", req, res, m_http_client, WALLET_RCP_CONNECTION_TIMEOUT);
- CHECK_AND_THROW_WALLET_EX(!r, error::no_connection_to_daemon, "getblocks.bin");
- CHECK_AND_THROW_WALLET_EX(res.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "getblocks.bin");
- CHECK_AND_THROW_WALLET_EX(res.status != CORE_RPC_STATUS_OK, error::get_blocks_error, res.status);
- CHECK_AND_THROW_WALLET_EX(m_blockchain.size() <= res.start_height, error::wallet_internal_error,
+ THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "getblocks.bin");
+ THROW_WALLET_EXCEPTION_IF(res.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "getblocks.bin");
+ THROW_WALLET_EXCEPTION_IF(res.status != CORE_RPC_STATUS_OK, error::get_blocks_error, res.status);
+ THROW_WALLET_EXCEPTION_IF(m_blockchain.size() <= res.start_height, error::wallet_internal_error,
"wrong daemon response: m_start_height=" + std::to_string(res.start_height) +
" not less than local blockchain size=" + std::to_string(m_blockchain.size()));
@@ -185,7 +185,7 @@ void wallet2::pull_blocks(size_t& blocks_added)
{
cryptonote::block bl;
r = cryptonote::parse_and_validate_block_from_blob(bl_entry.block, bl);
- CHECK_AND_THROW_WALLET_EX(!r, error::block_parse_error, bl_entry.block);
+ THROW_WALLET_EXCEPTION_IF(!r, error::block_parse_error, bl_entry.block);
crypto::hash bl_id = get_block_hash(bl);
if(current_index >= m_blockchain.size())
@@ -196,7 +196,7 @@ void wallet2::pull_blocks(size_t& blocks_added)
else if(bl_id != m_blockchain[current_index])
{
//split detected here !!!
- CHECK_AND_THROW_WALLET_EX(current_index == res.start_height, error::wallet_internal_error,
+ THROW_WALLET_EXCEPTION_IF(current_index == res.start_height, error::wallet_internal_error,
"wrong daemon response: split starts from the first block in response " + string_tools::pod_to_hex(bl_id) +
" (height " + std::to_string(res.start_height) + "), local block id at this height: " +
string_tools::pod_to_hex(m_blockchain[current_index]));
@@ -288,7 +288,7 @@ void wallet2::detach_blockchain(uint64_t height)
for(size_t i = i_start; i!= m_transfers.size();i++)
{
auto it_ki = m_key_images.find(m_transfers[i].m_key_image);
- CHECK_AND_THROW_WALLET_EX(it_ki == m_key_images.end(), error::wallet_internal_error, "key image not found");
+ THROW_WALLET_EXCEPTION_IF(it_ki == m_key_images.end(), error::wallet_internal_error, "key image not found");
m_key_images.erase(it_ki);
++transfers_detached;
}
@@ -355,9 +355,9 @@ void wallet2::load_keys(const std::string& keys_file_name, const std::string& pa
wallet2::keys_file_data keys_file_data;
std::string buf;
bool r = epee::file_io_utils::load_file_to_string(keys_file_name, buf);
- CHECK_AND_THROW_WALLET_EX(!r, error::file_read_error, keys_file_name);
+ THROW_WALLET_EXCEPTION_IF(!r, error::file_read_error, keys_file_name);
r = ::serialization::parse_binary(buf, keys_file_data);
- CHECK_AND_THROW_WALLET_EX(!r, error::wallet_internal_error, "internal error: failed to deserialize \"" + keys_file_name + '\"');
+ THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, "internal error: failed to deserialize \"" + keys_file_name + '\"');
crypto::chacha8_key key;
crypto::generate_chacha8_key(password, key);
@@ -369,7 +369,7 @@ void wallet2::load_keys(const std::string& keys_file_name, const std::string& pa
r = epee::serialization::load_t_from_binary(m_account, account_data);
r = r && verify_keys(keys.m_view_secret_key, keys.m_account_address.m_view_public_key);
r = r && verify_keys(keys.m_spend_secret_key, keys.m_account_address.m_spend_public_key);
- CHECK_AND_THROW_WALLET_EX(!r, error::invalid_password);
+ THROW_WALLET_EXCEPTION_IF(!r, error::invalid_password);
}
//----------------------------------------------------------------------------------------------------
void wallet2::generate(const std::string& wallet_, const std::string& password)
@@ -378,14 +378,14 @@ void wallet2::generate(const std::string& wallet_, const std::string& password)
prepare_file_names(wallet_);
boost::system::error_code ignored_ec;
- CHECK_AND_THROW_WALLET_EX(boost::filesystem::exists(m_wallet_file, ignored_ec), error::file_exists, m_wallet_file);
- CHECK_AND_THROW_WALLET_EX(boost::filesystem::exists(m_keys_file, ignored_ec), error::file_exists, m_keys_file);
+ THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_wallet_file, ignored_ec), error::file_exists, m_wallet_file);
+ THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_keys_file, ignored_ec), error::file_exists, m_keys_file);
m_account.generate();
m_account_public_address = m_account.get_keys().m_account_address;
bool r = store_keys(m_keys_file, password);
- CHECK_AND_THROW_WALLET_EX(!r, error::file_save_error, m_keys_file);
+ THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str());
if(!r) LOG_PRINT_RED_L0("String with address text not saved");
@@ -427,7 +427,7 @@ void wallet2::load(const std::string& wallet_, const std::string& password)
boost::system::error_code e;
bool exists = boost::filesystem::exists(m_keys_file, e);
- CHECK_AND_THROW_WALLET_EX(e || !exists, error::file_not_found, m_keys_file);
+ THROW_WALLET_EXCEPTION_IF(e || !exists, error::file_not_found, m_keys_file);
load_keys(m_keys_file, password);
LOG_PRINT_L0("Loaded wallet keys file, with public address: " << m_account.get_public_address_str());
@@ -441,8 +441,8 @@ void wallet2::load(const std::string& wallet_, const std::string& password)
return;
}
bool r = tools::unserialize_obj_from_file(*this, m_wallet_file);
- CHECK_AND_THROW_WALLET_EX(!r, error::file_read_error, m_wallet_file);
- CHECK_AND_THROW_WALLET_EX(
+ THROW_WALLET_EXCEPTION_IF(!r, error::file_read_error, m_wallet_file);
+ THROW_WALLET_EXCEPTION_IF(
m_account_public_address.m_spend_public_key != m_account.get_keys().m_account_address.m_spend_public_key ||
m_account_public_address.m_view_public_key != m_account.get_keys().m_account_address.m_view_public_key,
error::wallet_files_doesnt_correspond, m_keys_file, m_wallet_file);
@@ -459,7 +459,7 @@ void wallet2::load(const std::string& wallet_, const std::string& password)
void wallet2::store()
{
bool r = tools::serialize_obj_to_file(*this, m_wallet_file);
- CHECK_AND_THROW_WALLET_EX(!r, error::file_save_error, m_wallet_file);
+ THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_wallet_file);
}
//----------------------------------------------------------------------------------------------------
uint64_t wallet2::unlocked_balance()
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 74de1b6d9..221f3d25c 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -272,18 +272,19 @@ namespace tools
uint64_t unlock_time, uint64_t fee, T destination_split_strategy, const tx_dust_policy& dust_policy, cryptonote::transaction &tx)
{
using namespace cryptonote;
+ THROW_WALLET_EXCEPTION_IF(dsts.empty(), error::zero_destination);
uint64_t needed_money = fee;
BOOST_FOREACH(auto& dt, dsts)
{
- CHECK_AND_THROW_WALLET_EX(0 == dt.amount, error::zero_destination);
+ THROW_WALLET_EXCEPTION_IF(0 == dt.amount, error::zero_destination);
needed_money += dt.amount;
- CHECK_AND_THROW_WALLET_EX(needed_money < dt.amount, error::tx_sum_overflow, dsts, fee);
+ THROW_WALLET_EXCEPTION_IF(needed_money < dt.amount, error::tx_sum_overflow, dsts, fee);
}
std::list<transfer_container::iterator> selected_transfers;
uint64_t found_money = select_transfers(needed_money, 0 == fake_outputs_count, dust_policy.dust_threshold, selected_transfers);
- CHECK_AND_THROW_WALLET_EX(found_money < needed_money, error::not_enough_money, found_money, needed_money - fee, fee);
+ THROW_WALLET_EXCEPTION_IF(found_money < needed_money, error::not_enough_money, found_money, needed_money - fee, fee);
typedef COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::out_entry out_entry;
typedef cryptonote::tx_source_entry::output_entry tx_output_entry;
@@ -295,17 +296,17 @@ namespace tools
req.outs_count = fake_outputs_count + 1;// add one to make possible (if need) to skip real output key
BOOST_FOREACH(transfer_container::iterator it, selected_transfers)
{
- CHECK_AND_THROW_WALLET_EX(it->m_tx.vout.size() <= it->m_internal_output_index, error::wallet_internal_error,
+ THROW_WALLET_EXCEPTION_IF(it->m_tx.vout.size() <= it->m_internal_output_index, error::wallet_internal_error,
"m_internal_output_index = " + std::to_string(it->m_internal_output_index) +
" is greater or equal to outputs count = " + std::to_string(it->m_tx.vout.size()));
req.amounts.push_back(it->amount());
}
bool r = net_utils::invoke_http_bin_remote_command2(m_daemon_address + "/getrandom_outs.bin", req, daemon_resp, m_http_client, 200000);
- CHECK_AND_THROW_WALLET_EX(!r, error::no_connection_to_daemon, "getrandom_outs.bin");
- CHECK_AND_THROW_WALLET_EX(daemon_resp.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "getrandom_outs.bin");
- CHECK_AND_THROW_WALLET_EX(daemon_resp.status != CORE_RPC_STATUS_OK, error::get_random_outs_error, daemon_resp.status);
- CHECK_AND_THROW_WALLET_EX(daemon_resp.outs.size() != selected_transfers.size(), error::wallet_internal_error,
+ THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "getrandom_outs.bin");
+ THROW_WALLET_EXCEPTION_IF(daemon_resp.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "getrandom_outs.bin");
+ THROW_WALLET_EXCEPTION_IF(daemon_resp.status != CORE_RPC_STATUS_OK, error::get_random_outs_error, daemon_resp.status);
+ THROW_WALLET_EXCEPTION_IF(daemon_resp.outs.size() != selected_transfers.size(), error::wallet_internal_error,
"daemon returned wrong response for getrandom_outs.bin, wrong amounts count = " +
std::to_string(daemon_resp.outs.size()) + ", expected " + std::to_string(selected_transfers.size()));
@@ -317,7 +318,7 @@ namespace tools
scanty_outs.push_back(amount_outs);
}
}
- CHECK_AND_THROW_WALLET_EX(!scanty_outs.empty(), error::not_enough_outs_to_mix, scanty_outs, fake_outputs_count);
+ THROW_WALLET_EXCEPTION_IF(!scanty_outs.empty(), error::not_enough_outs_to_mix, scanty_outs, fake_outputs_count);
}
//prepare inputs
@@ -373,7 +374,7 @@ namespace tools
uint64_t dust = 0;
std::vector<cryptonote::tx_destination_entry> splitted_dsts;
destination_split_strategy(dsts, change_dts, dust_policy.dust_threshold, splitted_dsts, dust);
- CHECK_AND_THROW_WALLET_EX(dust_policy.dust_threshold < dust, error::wallet_internal_error, "invalid dust value: dust = " +
+ THROW_WALLET_EXCEPTION_IF(dust_policy.dust_threshold < dust, error::wallet_internal_error, "invalid dust value: dust = " +
std::to_string(dust) + ", dust_threshold = " + std::to_string(dust_policy.dust_threshold));
if (0 != dust && !dust_policy.add_to_fee)
{
@@ -381,8 +382,8 @@ namespace tools
}
bool r = cryptonote::construct_tx(m_account.get_keys(), sources, splitted_dsts, tx, unlock_time);
- CHECK_AND_THROW_WALLET_EX(!r, error::tx_not_constructed, sources, splitted_dsts, unlock_time);
- CHECK_AND_THROW_WALLET_EX(m_upper_transaction_size_limit <= get_object_blobsize(tx), error::tx_too_big, tx, m_upper_transaction_size_limit);
+ THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sources, splitted_dsts, unlock_time);
+ THROW_WALLET_EXCEPTION_IF(m_upper_transaction_size_limit <= get_object_blobsize(tx), error::tx_too_big, tx, m_upper_transaction_size_limit);
std::string key_images;
bool all_are_txin_to_key = std::all_of(tx.vin.begin(), tx.vin.end(), [&](const txin_v& s_e) -> bool
@@ -391,15 +392,15 @@ namespace tools
key_images += boost::to_string(in.k_image) + " ";
return true;
});
- CHECK_AND_THROW_WALLET_EX(!all_are_txin_to_key, error::unexpected_txin_type, tx);
+ THROW_WALLET_EXCEPTION_IF(!all_are_txin_to_key, error::unexpected_txin_type, tx);
COMMAND_RPC_SEND_RAW_TX::request req;
req.tx_as_hex = epee::string_tools::buff_to_hex_nodelimer(tx_to_blob(tx));
COMMAND_RPC_SEND_RAW_TX::response daemon_send_resp;
r = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/sendrawtransaction", req, daemon_send_resp, m_http_client, 200000);
- CHECK_AND_THROW_WALLET_EX(!r, error::no_connection_to_daemon, "sendrawtransaction");
- CHECK_AND_THROW_WALLET_EX(daemon_send_resp.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "sendrawtransaction");
- CHECK_AND_THROW_WALLET_EX(daemon_send_resp.status != CORE_RPC_STATUS_OK, error::tx_rejected, tx, daemon_send_resp.status);
+ THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "sendrawtransaction");
+ THROW_WALLET_EXCEPTION_IF(daemon_send_resp.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "sendrawtransaction");
+ THROW_WALLET_EXCEPTION_IF(daemon_send_resp.status != CORE_RPC_STATUS_OK, error::tx_rejected, tx, daemon_send_resp.status);
add_unconfirmed_tx(tx, change_dts.amount);
diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h
index b517d64f9..b2a863436 100644
--- a/src/wallet/wallet_errors.h
+++ b/src/wallet/wallet_errors.h
@@ -603,7 +603,7 @@ namespace tools
#define STRINGIZE_DETAIL(x) #x
#define STRINGIZE(x) STRINGIZE_DETAIL(x)
-#define CHECK_AND_THROW_WALLET_EX(cond, err_type, ...) \
+#define THROW_WALLET_EXCEPTION_IF(cond, err_type, ...) \
if (cond) \
{ \
LOG_ERROR(#cond << ". THROW EXCEPTION: " << #err_type); \