Skip to content

Commit

Permalink
json rpc for wallet and bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Juarez committed Apr 2, 2014
1 parent 8efa131 commit 29c2859
Show file tree
Hide file tree
Showing 43 changed files with 2,288 additions and 834 deletions.
17 changes: 17 additions & 0 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Release notes 0.8.3

- JSON RPC for wallet
- fixed bug with blockchain storing
- fixed bug with correct display of transfer's change
- bug fix in simple wallet

Release notes 0.8.2

- now wallet is still working when daemon stores blockchain and can't serve clients;
- no-console option for a daemon;
- fixed problem with network synchronization;
- major bug fix in simple wallet.

Release notes 0.8.1

Bytecoin project is moved to GitHub
4 changes: 2 additions & 2 deletions contrib/epee/demo/demo_http_server/demo_http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ bool communicate(const std::string url, t_request& req, t_response& rsp, const s
if(use_jrpc)
{
epee::json_rpc::request<t_request> req_t = AUTO_VAL_INIT(req_t);
req_t.params = req;
req_t.jsonrpc = "2.0";
req_t.id = "10";
req_t.method = "command_example_1";
req_t.version = "1.1";
req_t.params = req;
epee::json_rpc::response<t_response, std::string> resp_t = AUTO_VAL_INIT(resp_t);
if(!epee::net_utils::invoke_http_json_remote_command2("/request_json_rpc", req_t, resp_t, http_client))
{
Expand Down
4 changes: 3 additions & 1 deletion contrib/epee/include/console_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ namespace epee
continue_handle = false;
break;
}
string_tools::trim(command);

LOG_PRINT_L2("Read command: " << command);
if(0 == command.compare("exit") || 0 == command.compare("q"))
Expand All @@ -281,7 +282,8 @@ namespace epee
continue;
}
log_space::get_set_log_detalisation_level(true, n);
LOG_PRINT_L0("New log level set " << n);
std::cout << "New log level set " << n;
LOG_PRINT_L2("New log level set " << n);
}else if (command.empty())
{
continue;
Expand Down
3 changes: 3 additions & 0 deletions contrib/epee/include/misc_log_ex.h
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,9 @@ POP_WARNINGS
#define LOG_PRINT_RED(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_red)
#define LOG_PRINT_GREEN(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_green)
#define LOG_PRINT_BLUE(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_blue)
#define LOG_PRINT_YELLOW(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_yellow)
#define LOG_PRINT_CYAN(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_cyan)
#define LOG_PRINT_MAGENTA(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_magenta)

#define LOG_PRINT_RED_L0(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_red)

Expand Down
2 changes: 1 addition & 1 deletion contrib/epee/include/net/http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ using namespace std;
}else
{ //Apparently there are no signs of the form of transfer, will receive data until the connection is closed
m_state = reciev_machine_state_error;
LOG_PRINT("Undefinded transfer type, consider http_body_transfer_connection_close method.", LOG_LEVEL_2);
LOG_PRINT("Undefinded transfer type, consider http_body_transfer_connection_close method. header: " << m_header_cache, LOG_LEVEL_2);
return false;
}
return false;
Expand Down
102 changes: 85 additions & 17 deletions contrib/epee/include/net/http_server_handlers_map2.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ namespace epee
template<typename t_param>
struct request
{
std::string version;
std::string jsonrpc;
std::string method;
std::string id;
t_param params;

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(version)
KV_SERIALIZE(method)
KV_SERIALIZE(jsonrpc)
KV_SERIALIZE(id)
KV_SERIALIZE(method)
KV_SERIALIZE(params)
END_KV_SERIALIZE_MAP()
};
Expand All @@ -147,21 +147,54 @@ namespace epee
END_KV_SERIALIZE_MAP()
};

struct dummy_result
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};

template<typename t_param, typename t_error>
struct response
{
std::string jsonrpc;
t_param result;
t_error error;
std::string id;

t_error error;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(jsonrpc)
KV_SERIALIZE(id)
KV_SERIALIZE(result)
KV_SERIALIZE(error)
END_KV_SERIALIZE_MAP()
};

template<typename t_param>
struct response<t_param, dummy_error>
{
std::string jsonrpc;
t_param result;
std::string id;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(jsonrpc)
KV_SERIALIZE(id)
KV_SERIALIZE(result)
END_KV_SERIALIZE_MAP()
};

template<typename t_error>
struct response<dummy_result, t_error>
{
std::string jsonrpc;
t_error error;
std::string id;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(jsonrpc)
KV_SERIALIZE(id)
KV_SERIALIZE(error)
END_KV_SERIALIZE_MAP()
};

typedef response<std::string, error> error_response;
typedef response<dummy_result, error> error_response;
}
}

Expand All @@ -184,6 +217,7 @@ namespace epee
if(!ps.get_value("method", callback_name, nullptr)) \
{ \
epee::json_rpc::error_response rsp; \
rsp.jsonrpc = "2.0"; \
rsp.error.code = -32600; \
rsp.error.message = "Invalid Request"; \
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(rsp), response_info.m_body); \
Expand All @@ -201,14 +235,45 @@ namespace epee
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; \
epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
fail_resp.jsonrpc = "2.0"; \
fail_resp.id = req.id; \
if(!callback_f(req.params, resp.result, fail_resp.error, m_conn_context)) \
{ \
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); \
return true;\
}

#define MAP_JON_RPC_WERI(method_name, callback_f, command_type) \
else if(callback_name == method_name) \
{ \
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
return true; \
} \
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; \
epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
fail_resp.jsonrpc = "2.0"; \
fail_resp.id = req.id; \
if(!callback_f(req.params, resp.result, fail_resp.error, m_conn_context, response_info)) \
{ \
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(); \
Expand All @@ -229,16 +294,18 @@ namespace epee
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; \
if(!callback_f(req.params, resp.result, m_conn_context)) \
{ \
epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
fail_resp.id = req.id; \
fail_resp.error.code = -32603; \
fail_resp.error.message = "Internal error"; \
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
return true; \
} \
{ \
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 = -32603; \
fail_resp.error.message = "Internal error"; \
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(); \
Expand All @@ -251,6 +318,7 @@ namespace epee

#define END_JSON_RPC_MAP() \
epee::json_rpc::error_response rsp; \
rsp.jsonrpc = "2.0"; \
rsp.error.code = -32601; \
rsp.error.message = "Method not found"; \
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(rsp), response_info.m_body); \
Expand Down
6 changes: 6 additions & 0 deletions contrib/epee/include/net/net_utils_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ namespace net_utils
#define LOG_PRINT_CC_GREEN(ct, message, log_level) LOG_PRINT_GREEN("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, log_level)
#define LOG_PRINT_CC_RED(ct, message, log_level) LOG_PRINT_RED("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, log_level)
#define LOG_PRINT_CC_BLUE(ct, message, log_level) LOG_PRINT_BLUE("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, log_level)
#define LOG_PRINT_CC_YELLOW(ct, message, log_level) LOG_PRINT_YELLOW("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, log_level)
#define LOG_PRINT_CC_CYAN(ct, message, log_level) LOG_PRINT_CYAN("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, log_level)
#define LOG_PRINT_CC_MAGENTA(ct, message, log_level) LOG_PRINT_MAGENTA("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, log_level)
#define LOG_ERROR_CC(ct, message) LOG_ERROR("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message)

#define LOG_PRINT_CC_L0(ct, message) LOG_PRINT_L0("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message)
Expand All @@ -154,6 +157,9 @@ namespace net_utils
#define LOG_PRINT_CCONTEXT_GREEN(message, log_level) LOG_PRINT_CC_GREEN(context, message, log_level)
#define LOG_PRINT_CCONTEXT_RED(message, log_level) LOG_PRINT_CC_RED(context, message, log_level)
#define LOG_PRINT_CCONTEXT_BLUE(message, log_level) LOG_PRINT_CC_BLUE(context, message, log_level)
#define LOG_PRINT_CCONTEXT_YELLOW(message, log_level) LOG_PRINT_CC_YELLOW(context, message, log_level)
#define LOG_PRINT_CCONTEXT_CYAN(message, log_level) LOG_PRINT_CC_CYAN(context, message, log_level)
#define LOG_PRINT_CCONTEXT_MAGENTA(message, log_level) LOG_PRINT_CC_MAGENTA(context, message, log_level)

#define CHECK_AND_ASSERT_MES_CC(condition, return_val, err_message) CHECK_AND_ASSERT_MES(condition, return_val, "[" << epee::net_utils::print_connection_context_short(context) << "]" << err_message)

Expand Down
4 changes: 2 additions & 2 deletions contrib/epee/include/storages/http_abstract_invoke.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ namespace epee
bool invoke_http_json_rpc(const std::string& url, const std::string& method_name, t_request& out_struct, t_response& result_struct, t_transport& transport, unsigned int timeout = 5000, const std::string& http_method = "GET", const std::string& req_id = "0")
{
epee::json_rpc::request<t_request> req_t = AUTO_VAL_INIT(req_t);
req_t.params = out_struct;
req_t.jsonrpc = "2.0";
req_t.id = req_id;
req_t.method = method_name;
req_t.version = "2.0";
req_t.params = out_struct;
epee::json_rpc::response<t_response, epee::json_rpc::error> resp_t = AUTO_VAL_INIT(resp_t);
if(!epee::net_utils::invoke_http_json_remote_command2(url, req_t, resp_t, transport, timeout, http_method))
{
Expand Down
2 changes: 2 additions & 0 deletions src/common/unordered_containers_boost_serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace boost
template <class Archive, class h_key, class hval>
inline void load(Archive &a, std::unordered_map<h_key, hval> &x, const boost::serialization::version_type ver)
{
x.clear();
size_t s = 0;
a >> s;
for(size_t i = 0; i != s; i++)
Expand Down Expand Up @@ -54,6 +55,7 @@ namespace boost
template <class Archive, class hval>
inline void load(Archive &a, std::unordered_set<hval> &x, const boost::serialization::version_type ver)
{
x.clear();
size_t s = 0;
a >> s;
for(size_t i = 0; i != s; i++)
Expand Down
32 changes: 16 additions & 16 deletions src/cryptonote_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@

#pragma once

#define CRYPTONOTE_MAX_BLOCK_NUMBER 500000000
#define CRYPTONOTE_MAX_BLOCK_SIZE 500000000 // block header blob limit, never used!
#define CRYPTONOTE_MAX_TX_SIZE 1000000000
#define CRYPTONOTE_PUBLIC_ADDRESS_TEXTBLOB_VER 0
#define CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX 6 // addresses start with "2"
#define CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW 10
#define CRYPTONOTE_MAX_BLOCK_NUMBER 500000000
#define CRYPTONOTE_MAX_BLOCK_SIZE 500000000 // block header blob limit, never used!
#define CRYPTONOTE_MAX_TX_SIZE 1000000000
#define CRYPTONOTE_PUBLIC_ADDRESS_TEXTBLOB_VER 0
#define CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX 6 // addresses start with "2"
#define CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW 10
#define CURRENT_TRANSACTION_VERSION 1
#define CURRENT_BLOCK_MAJOR_VERSION 1
#define CURRENT_BLOCK_MINOR_VERSION 0
#define CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT 60*60*2
#define CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT 60*60*2

#define BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW 60

// MONEY_SUPPLY - total number coins to be generated
#define MONEY_SUPPLY ((uint64_t)(-1))

#define CRYPTONOTE_REWARD_BLOCKS_WINDOW 100
#define CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE 10000 //size of block (bytes) after which reward for block calculated using block size
#define CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE 600
#define CRYPTONOTE_DISPLAY_DECIMAL_POINT 8
// COIN - number of smallest units in one coin
#define COIN ((uint64_t)1000000000000) // pow(10, 12)
#define COIN ((uint64_t)100000000) // pow(10, 8)
#define DEFAULT_FEE ((uint64_t)1000000) // pow(10, 6)

#define CRYPTONOTE_REWARD_BLOCKS_WINDOW 100
#define CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE 10000 //size of block (bytes) after which reward for block calculated using block size
#define CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE 600
#define CRYPTONOTE_DISPLAY_DECIMAL_POINT 8


#define ORPHANED_BLOCKS_MAX_COUNT 100

Expand All @@ -39,16 +39,16 @@
#define DIFFICULTY_BLOCKS_COUNT DIFFICULTY_WINDOW + DIFFICULTY_LAG


#define CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS DIFFICULTY_TARGET * CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS
#define CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS 1
#define CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS DIFFICULTY_TARGET * CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS
#define CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS 1


#define DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN DIFFICULTY_TARGET //just alias


#define BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT 10000 //by default, blocks ids count in synchronizing
#define BLOCKS_SYNCHRONIZING_DEFAULT_COUNT 200 //by default, blocks count in blocks downloading
#define CRYPTONOTE_PROTOCOL_HOP_RELAX_COUNT 3 //value of hop, after which we use only announce of new block
#define CRYPTONOTE_PROTOCOL_HOP_RELAX_COUNT 3 //value of hop, after which we use only announce of new block


#define P2P_DEFAULT_PORT 8080
Expand Down
Loading

0 comments on commit 29c2859

Please sign in to comment.