forked from lthn/blockchain
added wallet API complete documentation
This commit is contained in:
parent
42fda5eaf7
commit
3a792e9a8e
14 changed files with 632 additions and 459 deletions
|
|
@ -34,148 +34,7 @@
|
|||
|
||||
|
||||
|
||||
template<typename typename_t>
|
||||
typename_t get_documentation_json_struct()
|
||||
{
|
||||
return AUTO_VAL_INIT_T(typename_t);
|
||||
}
|
||||
|
||||
|
||||
template<typename request_t, typename response_t>
|
||||
bool auto_doc_t(const std::string& prefix_name, std::string& generate_reference)
|
||||
{
|
||||
if (!generate_reference.size()) return true;
|
||||
request_t req = get_documentation_json_struct<request_t>();
|
||||
response_t res = get_documentation_json_struct<response_t>();
|
||||
|
||||
std::string req_str;
|
||||
std::string req_str_descr;
|
||||
epee::serialization::portable_storage_extended_doc ps;
|
||||
req.store(ps, nullptr);
|
||||
ps.dump_as_json(req_str);
|
||||
ps.dump_as_decriptions(req_str_descr);
|
||||
|
||||
|
||||
std::string res_str;
|
||||
std::string res_str_descr;
|
||||
epee::serialization::portable_storage_extended_doc ps_res;
|
||||
res.store(ps_res, nullptr);
|
||||
ps_res.dump_as_json(res_str);
|
||||
ps_res.dump_as_decriptions(res_str_descr);
|
||||
|
||||
|
||||
std::stringstream ss;
|
||||
ss << prefix_name << ENDL
|
||||
<< "REQUEST: " << ENDL << req_str << ENDL << req_str_descr << "--------------------------------" << ENDL
|
||||
<< "RESPONSE: " << ENDL << res_str << ENDL << res_str_descr << "################################" << ENDL;
|
||||
generate_reference += ss.str();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<typename command_type_t>
|
||||
bool auto_doc(const std::string& prefix_name, std::string& generate_reference)
|
||||
{
|
||||
return auto_doc_t<typename command_type_t::request, typename command_type_t::response>(prefix_name, generate_reference);
|
||||
}
|
||||
|
||||
namespace epee {
|
||||
namespace net_utils {
|
||||
namespace http {
|
||||
struct i_chain_handler
|
||||
{
|
||||
virtual bool handle_http_request_map(const epee::net_utils::http::http_request_info& query_info, epee::net_utils::http::http_response_info& response_info,
|
||||
epee::net_utils::connection_context_base& m_conn_context, bool& call_found, std::string& generate_reference) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#define CHAIN_HTTP_TO_MAP2(context_type) bool handle_http_request(const epee::net_utils::http::http_request_info& query_info, \
|
||||
epee::net_utils::http::http_response_info& response, \
|
||||
context_type& m_conn_context) \
|
||||
{\
|
||||
response.m_response_code = 200; \
|
||||
response.m_response_comment = "Ok"; \
|
||||
std::string reference_stub; \
|
||||
bool call_found = false; \
|
||||
if(!handle_http_request_map(query_info, response, m_conn_context, call_found, reference_stub) && response.m_response_code == 200) \
|
||||
{ response.m_response_code = 500; response.m_response_comment = "Internal Server Error"; return true; } \
|
||||
if (!call_found) \
|
||||
{ response.m_response_code = 404; response.m_response_comment = "Not Found"; return true; } \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define BEGIN_URI_MAP2() template<class t_context> bool handle_http_request_map(const epee::net_utils::http::http_request_info& query_info, \
|
||||
epee::net_utils::http::http_response_info& response_info, \
|
||||
t_context& m_conn_context, bool& call_found, std::string& generate_reference) { \
|
||||
call_found = false; \
|
||||
if(false) return true; //just a stub to have "else if"
|
||||
|
||||
#define BEGIN_URI_MAP2_VIRTUAL() virtual bool handle_http_request_map(const epee::net_utils::http::http_request_info& query_info, \
|
||||
epee::net_utils::http::http_response_info& response_info, \
|
||||
epee::net_utils::connection_context_base& m_conn_context, bool& call_found, std::string& generate_reference) { \
|
||||
call_found = false; \
|
||||
if(false) return true; //just a stub to have "else if"
|
||||
|
||||
|
||||
#define MAP_URI2(pattern, callback) else if(std::string::npos != query_info.m_URI.find(pattern)) return callback(query_info, response_info, m_conn_context);
|
||||
|
||||
#define MAP_URI_AUTO_XML2(s_pattern, callback_f, command_type) //TODO: don't think i ever again will use xml - ambiguous and "overtagged" format
|
||||
|
||||
#define MAP_URI_AUTO_JON2(s_pattern, callback_f, command_type) \
|
||||
else if(auto_doc<command_type>(s_pattern "[JSON]", generate_reference) && query_info.m_URI == s_pattern) \
|
||||
{ \
|
||||
call_found = true; \
|
||||
uint64_t ticks = misc_utils::get_tick_count(); \
|
||||
boost::value_initialized<command_type::request> req; \
|
||||
bool res = epee::serialization::load_t_from_json(static_cast<command_type::request&>(req), query_info.m_body); \
|
||||
CHECK_AND_ASSERT_MES(res, false, "Failed to parse json: \r\n" << query_info.m_body); \
|
||||
uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
|
||||
boost::value_initialized<command_type::response> resp;\
|
||||
res = callback_f(static_cast<command_type::request&>(req), static_cast<command_type::response&>(resp), m_conn_context); \
|
||||
CHECK_AND_ASSERT_MES(res, false, "Failed to call " << #callback_f << "() while handling " << s_pattern); \
|
||||
uint64_t ticks2 = epee::misc_utils::get_tick_count(); \
|
||||
epee::serialization::store_t_to_json(static_cast<command_type::response&>(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("[HTTP/JSON][" << epee::string_tools::get_ip_string_from_int32(m_conn_context.m_remote_ip ) << "][" << query_info.m_URI << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2); \
|
||||
}
|
||||
|
||||
#define MAP_URI_AUTO_BIN2(s_pattern, callback_f, command_type) \
|
||||
else if(auto_doc<command_type>(s_pattern "[BIN]", generate_reference) && query_info.m_URI == s_pattern) \
|
||||
{ \
|
||||
call_found = true; \
|
||||
uint64_t ticks = misc_utils::get_tick_count(); \
|
||||
boost::value_initialized<command_type::request> req; \
|
||||
bool res = epee::serialization::load_t_from_binary(static_cast<command_type::request&>(req), query_info.m_body); \
|
||||
CHECK_AND_ASSERT_MES(res, false, "Failed to parse bin body data, body size=" << query_info.m_body.size()); \
|
||||
uint64_t ticks1 = misc_utils::get_tick_count(); \
|
||||
boost::value_initialized<command_type::response> resp;\
|
||||
res = callback_f(static_cast<command_type::request&>(req), static_cast<command_type::response&>(resp), m_conn_context); \
|
||||
CHECK_AND_ASSERT_MES(res, false, "Failed to call " << #callback_f << "() while handling " << s_pattern); \
|
||||
uint64_t ticks2 = misc_utils::get_tick_count(); \
|
||||
epee::serialization::store_t_to_binary(static_cast<command_type::response&>(resp), response_info.m_body); \
|
||||
uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
|
||||
response_info.m_mime_tipe = " application/octet-stream"; \
|
||||
response_info.m_header_info.m_content_type = " application/octet-stream"; \
|
||||
LOG_PRINT( "[HTTP/BIN][" << epee::string_tools::get_ip_string_from_int32(m_conn_context.m_remote_ip ) << "][" << query_info.m_URI << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2); \
|
||||
}
|
||||
|
||||
#define CHAIN_TO_PHANDLER(pi_chain_handler) else if (pi_chain_handler && pi_chain_handler->handle_http_request_map(query_info, response_info, m_conn_context, call_found, generate_reference) && call_found) { return true;}
|
||||
|
||||
#define CHAIN_URI_MAP2(callback) else {callback(query_info, response_info, m_conn_context);call_found = true;}
|
||||
|
||||
#define END_URI_MAP2() return true;}
|
||||
|
||||
|
||||
|
||||
|
||||
namespace epee
|
||||
namespace epee
|
||||
{
|
||||
namespace json_rpc
|
||||
{
|
||||
|
|
@ -204,7 +63,7 @@ namespace epee
|
|||
KV_SERIALIZE(message)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
||||
struct dummy_error
|
||||
{
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
|
|
@ -264,20 +123,241 @@ namespace epee
|
|||
}
|
||||
}
|
||||
|
||||
template<typename command_type_t>
|
||||
struct json_command_type_t
|
||||
|
||||
template<typename typename_t>
|
||||
typename_t get_documentation_json_struct()
|
||||
{
|
||||
typedef typename epee::json_rpc::request<typename command_type_t::request> request;
|
||||
typedef typename epee::json_rpc::request<typename command_type_t::response> response;
|
||||
return AUTO_VAL_INIT_T(typename_t);
|
||||
}
|
||||
|
||||
struct documentation_entry
|
||||
{
|
||||
std::string uri;
|
||||
bool is_binary = false; //if not - then it's JSON
|
||||
std::string json_method_name;
|
||||
std::string request_json_example;
|
||||
std::string request_json_descriptions;
|
||||
|
||||
std::string response_json_example;
|
||||
std::string response_json_descriptions;
|
||||
|
||||
std::string method_general_decription;
|
||||
};
|
||||
|
||||
#define JSON_RPC_REFERENCE_MARKER "JSON_RPC"
|
||||
struct documentation
|
||||
{
|
||||
bool do_generate_documentation = false;
|
||||
std::list<documentation_entry> entries;
|
||||
};
|
||||
|
||||
|
||||
// Primary template
|
||||
template<typename T>
|
||||
struct has_static_member_description {
|
||||
private:
|
||||
// SFINAE test function
|
||||
template<typename U>
|
||||
static auto test(int) -> decltype(U::description, std::true_type{});
|
||||
|
||||
// Fallback function
|
||||
template<typename>
|
||||
static auto test(...) -> std::false_type;
|
||||
|
||||
public:
|
||||
// Member constant indicating whether T has a static member
|
||||
static constexpr bool value = decltype(test<T>(0))::value;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define BEGIN_JSON_RPC_MAP(uri) else if(query_info.m_URI == JSON_RPC_REFERENCE_MARKER || query_info.m_URI == uri) \
|
||||
|
||||
template <typename T>
|
||||
const char* get_command_description()
|
||||
{
|
||||
if constexpr (has_static_member_description<T>::value)
|
||||
{
|
||||
return T::description;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "NO DESCRIPTION";
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void f(T) {} // Definition #2
|
||||
|
||||
|
||||
template<typename command_type_t, bool is_json_rpc_method>
|
||||
bool auto_doc(const std::string& uri, const std::string& method, bool is_json, documentation& docs)
|
||||
{
|
||||
if (!docs.do_generate_documentation) return true;
|
||||
|
||||
docs.entries.resize(docs.entries.size()+1);
|
||||
docs.entries.back().is_binary = !is_json;
|
||||
docs.entries.back().json_method_name = method;
|
||||
docs.entries.back().method_general_decription = get_command_description<command_type_t>();
|
||||
|
||||
if constexpr (is_json_rpc_method)
|
||||
{
|
||||
//json rpc-like call
|
||||
typedef typename epee::json_rpc::request<typename command_type_t::request> request_t;
|
||||
typedef typename epee::json_rpc::request<typename command_type_t::response> response_t;
|
||||
request_t req = AUTO_VAL_INIT(req); //get_documentation_json_struct<request_t>();
|
||||
response_t res = AUTO_VAL_INIT(res); //get_documentation_json_struct<response_t>();
|
||||
|
||||
|
||||
epee::serialization::portable_storage_extended_doc ps;
|
||||
req.store(ps, nullptr);
|
||||
ps.dump_as_json(docs.entries.back().request_json_example);
|
||||
ps.dump_as_decriptions(docs.entries.back().request_json_descriptions);
|
||||
|
||||
epee::serialization::portable_storage_extended_doc ps_res;
|
||||
res.store(ps_res, nullptr);
|
||||
ps_res.dump_as_json(docs.entries.back().response_json_example);
|
||||
ps_res.dump_as_decriptions(docs.entries.back().response_json_descriptions);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//json/bin uri/based
|
||||
typedef command_type_t::request request_t;
|
||||
typedef command_type_t::response response_t;
|
||||
|
||||
request_t req = AUTO_VAL_INIT(req); //get_documentation_json_struct<request_t>();
|
||||
response_t res = AUTO_VAL_INIT(res); //get_documentation_json_struct<response_t>();
|
||||
|
||||
|
||||
epee::serialization::portable_storage_extended_doc ps;
|
||||
req.store(ps, nullptr);
|
||||
ps.dump_as_json(docs.entries.back().request_json_example);
|
||||
ps.dump_as_decriptions(docs.entries.back().request_json_descriptions);
|
||||
|
||||
epee::serialization::portable_storage_extended_doc ps_res;
|
||||
res.store(ps_res, nullptr);
|
||||
ps_res.dump_as_json(docs.entries.back().response_json_example);
|
||||
ps_res.dump_as_decriptions(docs.entries.back().response_json_descriptions);
|
||||
}
|
||||
|
||||
|
||||
// std::stringstream ss;
|
||||
// ss << prefix_name << ENDL
|
||||
// << "REQUEST: " << ENDL << req_str << ENDL << req_str_descr << "--------------------------------" << ENDL
|
||||
// << "RESPONSE: " << ENDL << res_str << ENDL << res_str_descr << "################################" << ENDL;
|
||||
// generate_reference += ss.str();
|
||||
return true;
|
||||
|
||||
//return auto_doc_t<typename command_type_t::request, typename command_type_t::response>(prefix_name, generate_reference);
|
||||
}
|
||||
|
||||
namespace epee {
|
||||
namespace net_utils {
|
||||
namespace http {
|
||||
struct i_chain_handler
|
||||
{
|
||||
virtual bool handle_http_request_map(const epee::net_utils::http::http_request_info& query_info, epee::net_utils::http::http_response_info& response_info,
|
||||
epee::net_utils::connection_context_base& m_conn_context, bool& call_found, documentation& docs = documentation()) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#define CHAIN_HTTP_TO_MAP2(context_type) bool handle_http_request(const epee::net_utils::http::http_request_info& query_info, \
|
||||
epee::net_utils::http::http_response_info& response, \
|
||||
context_type& m_conn_context) \
|
||||
{\
|
||||
response.m_response_code = 200; \
|
||||
response.m_response_comment = "Ok"; \
|
||||
bool call_found = false; \
|
||||
if(!handle_http_request_map(query_info, response, m_conn_context, call_found) && response.m_response_code == 200) \
|
||||
{ response.m_response_code = 500; response.m_response_comment = "Internal Server Error"; return true; } \
|
||||
if (!call_found) \
|
||||
{ response.m_response_code = 404; response.m_response_comment = "Not Found"; return true; } \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define BEGIN_URI_MAP2() template<class t_context> bool handle_http_request_map(const epee::net_utils::http::http_request_info& query_info, \
|
||||
epee::net_utils::http::http_response_info& response_info, \
|
||||
t_context& m_conn_context, bool& call_found, documentation& docs = documentation()) { \
|
||||
call_found = false; \
|
||||
if(false) return true; //just a stub to have "else if"
|
||||
|
||||
#define BEGIN_URI_MAP2_VIRTUAL() virtual bool handle_http_request_map(const epee::net_utils::http::http_request_info& query_info, \
|
||||
epee::net_utils::http::http_response_info& response_info, \
|
||||
epee::net_utils::connection_context_base& m_conn_context, bool& call_found, documentation& docs = documentation()) { \
|
||||
call_found = false; \
|
||||
if(false) return true; //just a stub to have "else if"
|
||||
|
||||
|
||||
#define MAP_URI2(pattern, callback) else if(std::string::npos != query_info.m_URI.find(pattern)) return callback(query_info, response_info, m_conn_context);
|
||||
|
||||
#define MAP_URI_AUTO_XML2(s_pattern, callback_f, command_type) //TODO: don't think i ever again will use xml - ambiguous and "overtagged" format
|
||||
|
||||
#define MAP_URI_AUTO_JON2(s_pattern, callback_f, command_type) \
|
||||
else if(auto_doc<command_type, false>(s_pattern, "", true, docs) && query_info.m_URI == s_pattern) \
|
||||
{ \
|
||||
if(query_info.m_URI == JSON_RPC_REFERENCE_MARKER) {generate_reference = "JSON RPC URL: " uri "\n";} \
|
||||
call_found = true; \
|
||||
uint64_t ticks = misc_utils::get_tick_count(); \
|
||||
boost::value_initialized<command_type::request> req; \
|
||||
bool res = epee::serialization::load_t_from_json(static_cast<command_type::request&>(req), query_info.m_body); \
|
||||
CHECK_AND_ASSERT_MES(res, false, "Failed to parse json: \r\n" << query_info.m_body); \
|
||||
uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
|
||||
boost::value_initialized<command_type::response> resp;\
|
||||
res = callback_f(static_cast<command_type::request&>(req), static_cast<command_type::response&>(resp), m_conn_context); \
|
||||
CHECK_AND_ASSERT_MES(res, false, "Failed to call " << #callback_f << "() while handling " << s_pattern); \
|
||||
uint64_t ticks2 = epee::misc_utils::get_tick_count(); \
|
||||
epee::serialization::store_t_to_json(static_cast<command_type::response&>(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("[HTTP/JSON][" << epee::string_tools::get_ip_string_from_int32(m_conn_context.m_remote_ip ) << "][" << query_info.m_URI << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2); \
|
||||
}
|
||||
|
||||
#define MAP_URI_AUTO_BIN2(s_pattern, callback_f, command_type) \
|
||||
else if(auto_doc<command_type, false>(s_pattern, "", false, docs) && query_info.m_URI == s_pattern) \
|
||||
{ \
|
||||
call_found = true; \
|
||||
uint64_t ticks = misc_utils::get_tick_count(); \
|
||||
boost::value_initialized<command_type::request> req; \
|
||||
bool res = epee::serialization::load_t_from_binary(static_cast<command_type::request&>(req), query_info.m_body); \
|
||||
CHECK_AND_ASSERT_MES(res, false, "Failed to parse bin body data, body size=" << query_info.m_body.size()); \
|
||||
uint64_t ticks1 = misc_utils::get_tick_count(); \
|
||||
boost::value_initialized<command_type::response> resp;\
|
||||
res = callback_f(static_cast<command_type::request&>(req), static_cast<command_type::response&>(resp), m_conn_context); \
|
||||
CHECK_AND_ASSERT_MES(res, false, "Failed to call " << #callback_f << "() while handling " << s_pattern); \
|
||||
uint64_t ticks2 = misc_utils::get_tick_count(); \
|
||||
epee::serialization::store_t_to_binary(static_cast<command_type::response&>(resp), response_info.m_body); \
|
||||
uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
|
||||
response_info.m_mime_tipe = " application/octet-stream"; \
|
||||
response_info.m_header_info.m_content_type = " application/octet-stream"; \
|
||||
LOG_PRINT( "[HTTP/BIN][" << epee::string_tools::get_ip_string_from_int32(m_conn_context.m_remote_ip ) << "][" << query_info.m_URI << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2); \
|
||||
}
|
||||
|
||||
#define CHAIN_TO_PHANDLER(pi_chain_handler) else if (pi_chain_handler && pi_chain_handler->handle_http_request_map(query_info, response_info, m_conn_context, call_found, docs) && call_found) { return true;}
|
||||
|
||||
#define CHAIN_URI_MAP2(callback) else {callback(query_info, response_info, m_conn_context);call_found = true;}
|
||||
|
||||
#define END_URI_MAP2() return true;}
|
||||
|
||||
|
||||
|
||||
//template<typename command_type_t>
|
||||
//struct json_command_type_t
|
||||
//{
|
||||
// typedef typename epee::json_rpc::request<typename command_type_t::request> request;
|
||||
// typedef typename epee::json_rpc::request<typename command_type_t::response> response;
|
||||
//};
|
||||
|
||||
//#define JSON_RPC_REFERENCE_MARKER "JSON_RPC"
|
||||
|
||||
// if(query_info.m_URI == JSON_RPC_REFERENCE_MARKER) {generate_reference = "JSON RPC URL: " uri "\n";} \
|
||||
|
||||
#define BEGIN_JSON_RPC_MAP(uri) else if(docs.do_generate_documentation || query_info.m_URI == uri) \
|
||||
{ \
|
||||
const char* current_zone_json_uri = uri;\
|
||||
LOG_PRINT_L4("[JSON_REQUEST_BODY]: " << ENDL << query_info.m_body); \
|
||||
uint64_t ticks = epee::misc_utils::get_tick_count(); \
|
||||
epee::serialization::portable_storage ps; \
|
||||
|
|
@ -336,7 +416,7 @@ struct json_command_type_t
|
|||
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(auto_doc<json_command_type_t<command_type>>("[" method_name "]", generate_reference) && callback_name == method_name) \
|
||||
else if(auto_doc<command_type, true>(current_zone_json_uri, method_name, true, docs) && callback_name == method_name) \
|
||||
{ \
|
||||
call_found = true; \
|
||||
PREPARE_OBJECTS_FROM_JSON(command_type) \
|
||||
|
|
@ -354,7 +434,7 @@ struct json_command_type_t
|
|||
}
|
||||
|
||||
#define MAP_JON_RPC_WERI(method_name, callback_f, command_type) \
|
||||
else if(auto_doc<json_command_type_t<command_type>>("[" method_name "]", generate_reference) && callback_name == method_name) \
|
||||
else if(auto_doc<command_type, true>(current_zone_json_uri, method_name, true, docs) && callback_name == method_name) \
|
||||
{ \
|
||||
call_found = true; \
|
||||
PREPARE_OBJECTS_FROM_JSON(command_type) \
|
||||
|
|
@ -372,7 +452,7 @@ struct json_command_type_t
|
|||
}
|
||||
|
||||
#define MAP_JON_RPC(method_name, callback_f, command_type) \
|
||||
else if(auto_doc<json_command_type_t<command_type>>(std::string("[") + method_name + "]", generate_reference) && callback_name == method_name) \
|
||||
else if(auto_doc<command_type, true>(current_zone_json_uri, method_name, true, docs) && callback_name == method_name) \
|
||||
{ \
|
||||
call_found = true; \
|
||||
PREPARE_OBJECTS_FROM_JSON(command_type) \
|
||||
|
|
|
|||
|
|
@ -103,12 +103,9 @@ public: \
|
|||
|
||||
//#define DOC_DSCR(description) , description
|
||||
#define DOC_EXMP(substitute) , substitute
|
||||
#define DOC_EXMP_AUTO_1(arg_1) , KV_MAKE_ALIAS_NAME() (arg_1)
|
||||
#define DOC_EXMP_AUTO_2(arg_1, arg_2) , KV_MAKE_ALIAS_NAME() (arg_1, arg_2)
|
||||
//#define DOC_EXMP_AUTO_1(arg_1) , KV_MAKE_ALIAS_NAME() (arg_1)
|
||||
//#define DOC_EXMP_AUTO_2(arg_1, arg_2) , KV_MAKE_ALIAS_NAME() (arg_1, arg_2)
|
||||
#define DOC_END ); }
|
||||
|
||||
|
||||
|
||||
#define DOC_EXMP_AUTO(...) , epee::create_t_object<KV_MAKE_ALIAS_NAME() >(__VA_ARGS__)
|
||||
|
||||
|
||||
|
|
@ -164,7 +161,7 @@ public: \
|
|||
#define KV_SERIALIZE(varialble) KV_SERIALIZE_N(varialble, #varialble)
|
||||
#define KV_SERIALIZE_DOC(varialble) KV_SERIALIZE_N_DOC( varialble, #varialble)
|
||||
|
||||
#define DOC_COMMAND(desciption_text) inline static const char* description;
|
||||
#define DOC_COMMAND(desciption_text) inline static const char* description = desciption_text;
|
||||
|
||||
|
||||
#define KV_SERIALIZE_VAL_POD_AS_BLOB(varialble) KV_SERIALIZE_VAL_POD_AS_BLOB_N(varialble, #varialble)
|
||||
|
|
|
|||
|
|
@ -51,13 +51,13 @@ namespace epee
|
|||
template<class t_stream>
|
||||
static void handle_array_start(t_stream& strm, size_t indent)
|
||||
{
|
||||
strm << "[";
|
||||
//strm << "[";
|
||||
}
|
||||
|
||||
template<class t_stream>
|
||||
static void handle_array_end(t_stream& strm, size_t indent)
|
||||
{
|
||||
strm << "]";
|
||||
//strm << "]";
|
||||
}
|
||||
|
||||
template<class t_stream>
|
||||
|
|
@ -71,8 +71,11 @@ namespace epee
|
|||
template<class t_stream>
|
||||
static void handle_print_key(t_stream& strm, const std::string& key, const std::string& description, size_t indent)
|
||||
{
|
||||
const std::string indent_str = make_indent(indent);
|
||||
strm << indent_str << "\"" << key << "\"" << ": " << description;
|
||||
if (description.size())
|
||||
{
|
||||
const std::string indent_str = make_indent(indent);
|
||||
strm << indent_str << "\"" << key << "\"" << ": " << description << eol;
|
||||
}
|
||||
}
|
||||
|
||||
template<class t_stream>
|
||||
|
|
@ -84,19 +87,19 @@ namespace epee
|
|||
template<class t_stream>
|
||||
static void handle_section_entry_separator(t_stream& strm, size_t indent)
|
||||
{
|
||||
strm << ",";
|
||||
//strm << ",";
|
||||
}
|
||||
|
||||
template<class t_stream>
|
||||
static void handle_array_entry_separator(t_stream& strm, size_t indent)
|
||||
{
|
||||
strm << ",";
|
||||
//strm << ",";
|
||||
}
|
||||
|
||||
template<class t_stream>
|
||||
static void handle_line_break(t_stream& strm, size_t indent)
|
||||
{
|
||||
strm << eol;
|
||||
//strm << eol;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace command_line
|
|||
|
||||
const arg_descriptor<bool> arg_console ( "no-console", "Disable daemon console commands" );
|
||||
const arg_descriptor<bool> arg_show_details ( "currency-details", "Display currency details" );
|
||||
const arg_descriptor<bool> arg_show_rpc_autodoc ( "show_rpc_autodoc", "Display rpc auto-generated documentation template" );
|
||||
const arg_descriptor<std::string> arg_generate_rpc_autodoc ( "generate_rpc_autodoc", "Make auto-generated RPC API documentation documents at the given path" );
|
||||
|
||||
const arg_descriptor<bool> arg_disable_upnp ( "disable-upnp", "Disable UPnP (enhances local network privacy)");
|
||||
const arg_descriptor<bool> arg_disable_ntp ( "disable-ntp", "Disable NTP, could enhance to time synchronization issue but increase network privacy, consider using disable-stop-if-time-out-of-sync with it");
|
||||
|
|
|
|||
|
|
@ -220,7 +220,7 @@ namespace command_line
|
|||
extern const arg_descriptor<int> arg_log_level;
|
||||
extern const arg_descriptor<bool> arg_console;
|
||||
extern const arg_descriptor<bool> arg_show_details;
|
||||
extern const arg_descriptor<bool> arg_show_rpc_autodoc;
|
||||
//extern const arg_descriptor<bool> arg_show_rpc_autodoc;
|
||||
extern const arg_descriptor<bool> arg_disable_upnp;
|
||||
extern const arg_descriptor<bool> arg_disable_ntp;
|
||||
extern const arg_descriptor<bool> arg_disable_stop_if_time_out_of_sync;
|
||||
|
|
@ -233,4 +233,6 @@ namespace command_line
|
|||
extern const arg_descriptor<bool> arg_validate_predownload;
|
||||
extern const arg_descriptor<std::string> arg_predownload_link;
|
||||
extern const arg_descriptor<std::string> arg_deeplink;
|
||||
extern const arg_descriptor<std::string> arg_generate_rpc_autodoc;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -589,11 +589,11 @@ namespace currency
|
|||
END_SERIALIZE()
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(service_id)
|
||||
KV_SERIALIZE(instruction)
|
||||
KV_SERIALIZE_BLOB_AS_HEX_STRING(body)
|
||||
KV_SERIALIZE_CONTAINER_POD_AS_HEX(security)
|
||||
KV_SERIALIZE(flags)
|
||||
KV_SERIALIZE(service_id) DOC_DSCR("Service ID, identificator that diferent one service from another") DOC_EXMP("C") DOC_END
|
||||
KV_SERIALIZE(instruction) DOC_DSCR("Instruction that make sence for this particular service") DOC_EXMP("K") DOC_END
|
||||
KV_SERIALIZE_BLOB_AS_HEX_STRING(body) DOC_DSCR("Hex-encoded body of the attachment") DOC_EXMP("dcfd7e055a6a3043ea3541a571a57a63e25dcc64e4a270f14fa9a58ac5dbec85dcfd7e055a6a3043ea3541a571a57a63e25dcc64e4a270f14fa9a58ac5dbec85") DOC_END
|
||||
KV_SERIALIZE_CONTAINER_POD_AS_HEX(security) DOC_DSCR("Hex-encoded public key of the owner, optional") DOC_EXMP("d8f6e37f28a632c06b0b3466db1b9d2d1b36a580ee35edfd971dc1423bc412a5") DOC_END
|
||||
KV_SERIALIZE(flags) DOC_DSCR("Flags that help wallet to automatically process some properties of the attachment(combination of TX_SERVICE_ATTACHMENT_ENCRYPT_BODY=1, TX_SERVICE_ATTACHMENT_DEFLATE_BODY=2, TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE=4,TX_SERVICE_ATTACHMENT_ENCRYPT_ADD_PROOF=8 )") DOC_END
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -37,21 +37,21 @@ namespace bc_services
|
|||
//-----------------
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE_N(offer_type, "ot")
|
||||
KV_SERIALIZE_CUSTOM_N(amount_primary, std::string, bc_services::transform_amount_to_string, bc_services::transform_string_to_amount, "ap")
|
||||
KV_SERIALIZE_CUSTOM_N(amount_target, std::string, bc_services::transform_amount_to_string, bc_services::transform_string_to_amount, "at")
|
||||
KV_SERIALIZE_N(bonus, "b")
|
||||
KV_SERIALIZE_N(target, "t")
|
||||
KV_SERIALIZE_N(primary, "p")
|
||||
KV_SERIALIZE_N(location_country, "lco")
|
||||
KV_SERIALIZE_N(location_city, "lci")
|
||||
KV_SERIALIZE_N(contacts, "cnt")
|
||||
KV_SERIALIZE_N(comment, "com")
|
||||
KV_SERIALIZE_N(payment_types, "pt")
|
||||
KV_SERIALIZE_N(deal_option, "do")
|
||||
KV_SERIALIZE_N(category, "cat")
|
||||
KV_SERIALIZE_N(expiration_time, "et")
|
||||
KV_SERIALIZE_N(preview_url, "url")
|
||||
KV_SERIALIZE_N(offer_type, "ot") DOC_DSCR("Type of the offer: OFFER_TYPE_PRIMARY_TO_TARGET(SELL ORDER) - 0, OFFER_TYPE_TARGET_TO_PRIMARY(BUY ORDER) - 1 etc.") DOC_EXMP(0) DOC_END
|
||||
KV_SERIALIZE_CUSTOM_N(amount_primary, std::string, bc_services::transform_amount_to_string, bc_services::transform_string_to_amount, "ap") DOC_DSCR("Amount of the currency") DOC_EXMP("100000") DOC_END
|
||||
KV_SERIALIZE_CUSTOM_N(amount_target, std::string, bc_services::transform_amount_to_string, bc_services::transform_string_to_amount, "at") DOC_DSCR("Smount of other currency or goods") DOC_EXMP("10000000") DOC_END
|
||||
KV_SERIALIZE_N(bonus, "b") DOC_DSCR("Bonus associated with the offer") DOC_EXMP(false) DOC_END
|
||||
KV_SERIALIZE_N(target, "t") DOC_DSCR("Target: currency / goods") DOC_EXMP("USDT") DOC_END
|
||||
KV_SERIALIZE_N(primary, "p") DOC_DSCR("Currency for goods") DOC_EXMP("ZANO") DOC_END
|
||||
KV_SERIALIZE_N(location_country, "lco") DOC_DSCR("Country of the offer location") DOC_EXMP("Montenegro") DOC_END
|
||||
KV_SERIALIZE_N(location_city, "lci") DOC_DSCR("City of the offer location") DOC_EXMP("Kolasin") DOC_END
|
||||
KV_SERIALIZE_N(contacts, "cnt") DOC_DSCR("Contacts related to the offer") DOC_EXMP("Ranko +38211111111") DOC_END
|
||||
KV_SERIALIZE_N(comment, "com") DOC_DSCR("Comment associated with the offer") DOC_EXMP("Dobr dan") DOC_END
|
||||
KV_SERIALIZE_N(payment_types, "pt") DOC_DSCR("Types of payment accepted for the offer") DOC_EXMP("zano") DOC_END
|
||||
KV_SERIALIZE_N(deal_option, "do") DOC_DSCR("Deal option for the offer") DOC_EXMP("full amount, by parts") DOC_END
|
||||
KV_SERIALIZE_N(category, "cat") DOC_DSCR("Category of the offer") DOC_EXMP("") DOC_END
|
||||
KV_SERIALIZE_N(expiration_time, "et") DOC_DSCR("Expiration time of the offer") DOC_EXMP(0) DOC_END
|
||||
KV_SERIALIZE_N(preview_url, "url") DOC_DSCR("URL for previewing the offer") DOC_EXMP("") DOC_END
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
|
@ -69,12 +69,12 @@ namespace bc_services
|
|||
mutable bool stopped;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE_POD_AS_HEX_STRING(tx_hash)
|
||||
KV_SERIALIZE_POD_AS_HEX_STRING(tx_original_hash)
|
||||
KV_SERIALIZE(index_in_tx)
|
||||
KV_SERIALIZE(timestamp)
|
||||
KV_SERIALIZE(fee)
|
||||
KV_SERIALIZE_POD_AS_HEX_STRING(security)
|
||||
KV_SERIALIZE_POD_AS_HEX_STRING(tx_hash) DOC_DSCR("Transaction hash represented as a hexadecimal string") DOC_EXMP("cc608f59f8080e2fbfe3c8c80eb6e6a953d47cf2d6aebd345bada3a1cab99852") DOC_END
|
||||
KV_SERIALIZE_POD_AS_HEX_STRING(tx_original_hash) DOC_DSCR("Origin transaction hash represented as a hexadecimal string(if offer updated)") DOC_EXMP("cc608f59f8080e2fbfe3c8c80eb6e6a953d47cf2d6aebd345bada3a1cab99852") DOC_END
|
||||
KV_SERIALIZE(index_in_tx) DOC_DSCR("Index of the tx_service_attachment entrie in transaction") DOC_EXMP(0) DOC_END
|
||||
KV_SERIALIZE(timestamp) DOC_DSCR("Timestamp of the transaction") DOC_EXMP(1712683857) DOC_END
|
||||
KV_SERIALIZE(fee) DOC_DSCR("Fee associated with the transaction") DOC_EXMP(10000000000) DOC_END
|
||||
KV_SERIALIZE_POD_AS_HEX_STRING(security) DOC_DSCR("Onwer's public key for access control") DOC_EXMP("40fa6db923728b38962718c61b4dc3af1acaa1967479c73703e260dc3609c58d") DOC_END
|
||||
KV_CHAIN_BASE(offer_details)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
|
@ -163,32 +163,33 @@ namespace bc_services
|
|||
bool bonus;
|
||||
std::string category;
|
||||
std::string keyword;
|
||||
bool fake;
|
||||
//bool fake;
|
||||
uint64_t current_time;
|
||||
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(order_by)
|
||||
KV_SERIALIZE(reverse)
|
||||
KV_SERIALIZE(offset)
|
||||
KV_SERIALIZE(limit)
|
||||
KV_SERIALIZE(timestamp_start)
|
||||
KV_SERIALIZE(timestamp_stop)
|
||||
KV_SERIALIZE(offer_type_mask)
|
||||
KV_SERIALIZE(amount_low_limit)
|
||||
KV_SERIALIZE(amount_up_limit)
|
||||
KV_SERIALIZE_CUSTOM(rate_low_limit, std::string, bc_services::transform_double_to_string, bc_services::transform_string_to_double)
|
||||
KV_SERIALIZE_CUSTOM(rate_up_limit, std::string, bc_services::transform_double_to_string, bc_services::transform_string_to_double)
|
||||
KV_SERIALIZE(payment_types)
|
||||
KV_SERIALIZE(location_country)
|
||||
KV_SERIALIZE(location_city)
|
||||
KV_SERIALIZE(target)
|
||||
KV_SERIALIZE(primary)
|
||||
KV_SERIALIZE(bonus)
|
||||
KV_SERIALIZE(category)
|
||||
KV_SERIALIZE(keyword)
|
||||
KV_SERIALIZE(fake)
|
||||
KV_SERIALIZE(order_by) DOC_DSCR("Field to order the results by one on this: ORDER_BY_TIMESTAMP=0,ORDER_BY_AMOUNT_PRIMARY=1,ORDER_BY_AMOUNT_TARGET=2,ORDER_BY_AMOUNT_RATE=3,ORDER_BY_PAYMENT_TYPES=4,ORDER_BY_CONTACTS=5,ORDER_BY_LOCATION=6,ORDER_BY_NAME=7") DOC_EXMP(0) DOC_END
|
||||
KV_SERIALIZE(reverse) DOC_DSCR("Flag to indicate whether the results should be sorted in reverse order") DOC_EXMP(false) DOC_END
|
||||
KV_SERIALIZE(offset) DOC_DSCR("Offset for pagination") DOC_EXMP(0) DOC_END
|
||||
KV_SERIALIZE(limit) DOC_DSCR("Maximum number of results to return") DOC_EXMP(100) DOC_END
|
||||
KV_SERIALIZE(timestamp_start) DOC_DSCR("Start timestamp for filtering results") DOC_EXMP(0) DOC_END
|
||||
KV_SERIALIZE(timestamp_stop) DOC_DSCR("Stop timestamp for filtering results") DOC_EXMP(0) DOC_END
|
||||
KV_SERIALIZE(offer_type_mask) DOC_DSCR("Mask representing the types of offers to include in the results, conbination of this: OFFER_TYPE_MASK_PRIMARY_TO_TARGET 0x00000001, OFFER_TYPE_MASK_TARGET_TO_PRIMARY 0x00000002, OFFER_TYPE_MASK_GOODS_TO_PRIMARY 0x00000004, OFFER_TYPE_MASK_PRIMARY_TO_GOODS 0x00000008") DOC_EXMP(0) DOC_END
|
||||
KV_SERIALIZE(amount_low_limit) DOC_DSCR("Lower limit for the amount of offers") DOC_EXMP(0) DOC_END
|
||||
KV_SERIALIZE(amount_up_limit) DOC_DSCR("Upper limit for the amount of offers") DOC_EXMP(0) DOC_END
|
||||
KV_SERIALIZE_CUSTOM(rate_low_limit, std::string, bc_services::transform_double_to_string, bc_services::transform_string_to_double) DOC_DSCR("Lower limit for the rate") DOC_EXMP("0.1") DOC_END
|
||||
KV_SERIALIZE_CUSTOM(rate_up_limit, std::string, bc_services::transform_double_to_string, bc_services::transform_string_to_double) DOC_DSCR("Upper limit for the rate") DOC_EXMP("0.1") DOC_END
|
||||
KV_SERIALIZE(payment_types) DOC_DSCR("Types of payment accepted for the offers(in a free form as it is in contract)") DOC_END
|
||||
KV_SERIALIZE(location_country) DOC_DSCR("Country of the location for the offers") DOC_END
|
||||
KV_SERIALIZE(location_city) DOC_DSCR("City of the location for the offers") DOC_END
|
||||
KV_SERIALIZE(target) DOC_DSCR("Target entity of the offers") DOC_END
|
||||
KV_SERIALIZE(primary) DOC_DSCR("Primary field for the offers") DOC_END
|
||||
KV_SERIALIZE(bonus) DOC_DSCR("Bonus associated with the offers") DOC_EXMP(false) DOC_END
|
||||
KV_SERIALIZE(category) DOC_DSCR("Category of the offers") DOC_END
|
||||
KV_SERIALIZE(keyword) DOC_DSCR("Keyword for searching offers") DOC_EXMP("tubes") DOC_END
|
||||
//KV_SERIALIZE(fake) DOC_DSCR("Flag indicating whether the offer is fake") DOC_EXMP() DOC_END
|
||||
END_KV_SERIALIZE_MAP()
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ int main(int argc, char* argv[])
|
|||
command_line::add_arg(desc_cmd_sett, command_line::arg_log_level);
|
||||
command_line::add_arg(desc_cmd_sett, command_line::arg_console);
|
||||
command_line::add_arg(desc_cmd_only, command_line::arg_show_details);
|
||||
command_line::add_arg(desc_cmd_only, command_line::arg_show_rpc_autodoc);
|
||||
command_line::add_arg(desc_cmd_only, command_line::arg_generate_rpc_autodoc);
|
||||
command_line::add_arg(desc_cmd_sett, command_line::arg_disable_stop_if_time_out_of_sync);
|
||||
command_line::add_arg(desc_cmd_sett, command_line::arg_disable_stop_on_low_free_space);
|
||||
command_line::add_arg(desc_cmd_sett, command_line::arg_enable_offers_service);
|
||||
|
|
@ -272,15 +272,17 @@ int main(int argc, char* argv[])
|
|||
if (stratum_enabled)
|
||||
stratum_server_ptr = std::make_shared<currency::stratum_server>(&ccore);
|
||||
|
||||
if (command_line::get_arg(vm, command_line::arg_show_rpc_autodoc))
|
||||
if (command_line::has_arg(vm, command_line::arg_generate_rpc_autodoc))
|
||||
{
|
||||
LOG_PRINT_L0("Dumping RPC auto-generated documents!");
|
||||
epee::net_utils::http::http_request_info query_info;
|
||||
epee::net_utils::http::http_response_info response_info;
|
||||
epee::net_utils::connection_context_base conn_context;
|
||||
std::string generate_reference = std::string("RPC_COMMANDS_LIST:\n");
|
||||
//std::string generate_reference = std::string("RPC_COMMANDS_LIST:\n");
|
||||
documentation doc;
|
||||
doc.do_generate_documentation = true;
|
||||
bool call_found = false;
|
||||
rpc_server.handle_http_request_map(query_info, response_info, conn_context, call_found, generate_reference);
|
||||
rpc_server.handle_http_request_map(query_info, response_info, conn_context, call_found, doc);
|
||||
//std::string json_rpc_reference;
|
||||
//query_info.m_URI = JSON_RPC_REFERENCE_MARKER;
|
||||
//query_info.m_body = "{\"jsonrpc\": \"2.0\", \"method\": \"nonexisting_method\", \"params\": {}},";
|
||||
|
|
|
|||
|
|
@ -1687,11 +1687,13 @@ namespace currency
|
|||
|
||||
struct COMMAND_RPC_GET_OFFERS_EX
|
||||
{
|
||||
DOC_COMMAND("Fetch from daemon offers listed in the marketplace with given filters");
|
||||
|
||||
struct request
|
||||
{
|
||||
bc_services::core_offers_filter filter;
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(filter)
|
||||
KV_SERIALIZE(filter) DOC_DSCR("Filter options.") DOC_END
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
|
@ -1702,9 +1704,9 @@ namespace currency
|
|||
uint64_t total_offers;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(status)
|
||||
KV_SERIALIZE(offers)
|
||||
KV_SERIALIZE(total_offers)
|
||||
KV_SERIALIZE(status) DOC_DSCR("Status of the operation") DOC_EXMP("OK") DOC_END
|
||||
KV_SERIALIZE(offers) DOC_DSCR("List of offers related to the operation") DOC_EXMP_AUTO(1) DOC_END
|
||||
KV_SERIALIZE(total_offers) DOC_DSCR("Total number of offers") DOC_EXMP(1) DOC_END
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2807,7 +2807,7 @@ int main(int argc, char* argv[])
|
|||
command_line::add_arg(desc_params, arg_set_timeout);
|
||||
command_line::add_arg(desc_params, arg_voting_config_file);
|
||||
command_line::add_arg(desc_params, arg_no_password_confirmations);
|
||||
command_line::add_arg(desc_params, command_line::arg_show_rpc_autodoc);
|
||||
command_line::add_arg(desc_params, command_line::arg_generate_rpc_autodoc);
|
||||
|
||||
tools::wallet_rpc_server::init_options(desc_params);
|
||||
|
||||
|
|
@ -2863,24 +2863,50 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
|
||||
if (command_line::get_arg(vm, command_line::arg_show_rpc_autodoc))
|
||||
if (command_line::has_arg(vm, command_line::arg_generate_rpc_autodoc))
|
||||
{
|
||||
LOG_PRINT_L0("Dumping RPC auto-generated documents!");
|
||||
epee::net_utils::http::http_request_info query_info;
|
||||
epee::net_utils::http::http_response_info response_info;
|
||||
epee::net_utils::connection_context_base conn_context;
|
||||
std::string generate_reference = std::string("WALLET_RPC_COMMANDS_LIST:\n");
|
||||
//std::string generate_reference = std::string("WALLET_RPC_COMMANDS_LIST:\n");
|
||||
bool call_found = false;
|
||||
tools::wallet_rpc_server wallet_rpc_server(std::shared_ptr<tools::wallet2>(new tools::wallet2()));
|
||||
//wallet_rpc_server.handle_http_request_map(query_info, response_info, conn_context, call_found, generate_reference);
|
||||
|
||||
std::string json_rpc_reference = generate_reference;
|
||||
query_info.m_URI = JSON_RPC_REFERENCE_MARKER;
|
||||
//::string json_rpc_reference = generate_reference;
|
||||
documentation docs;
|
||||
docs.do_generate_documentation = true;
|
||||
// query_info.m_URI = JSON_RPC_REFERENCE_MARKER;
|
||||
query_info.m_body = "{\"jsonrpc\": \"2.0\", \"method\": \"nonexisting_method\", \"params\": {}},";
|
||||
wallet_rpc_server.handle_http_request_map(query_info, response_info, conn_context, call_found, json_rpc_reference);
|
||||
wallet_rpc_server.handle_http_request_map(query_info, response_info, conn_context, call_found, docs);
|
||||
|
||||
std::string path_to_generate = command_line::get_arg(vm, command_line::arg_generate_rpc_autodoc);
|
||||
for (const auto& de : docs.entries)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << de.method_general_decription << ENDL;
|
||||
|
||||
ss << "URL: ```http:://127.0.0.1:11211" << de.uri << "```" << ENDL;
|
||||
|
||||
LOG_PRINT_L0(json_rpc_reference);
|
||||
ss << "### Request: " << ENDL << "```json" << ENDL << de.request_json_example << ENDL << "```" << ENDL;
|
||||
ss << "### Request description: " << ENDL << "```" << ENDL << de.request_json_descriptions << ENDL << "```" << ENDL;
|
||||
ss << "### Response: " << ENDL << "```json" << ENDL << de.response_json_example << ENDL << "```" << ENDL;
|
||||
ss << "### Response description: " << ENDL << "```" << ENDL << de.response_json_descriptions << ENDL << "```" << ENDL;
|
||||
|
||||
std::string filename = de.json_method_name;
|
||||
if (!filename.size())
|
||||
{
|
||||
filename = de.uri;
|
||||
}
|
||||
filename += ".md";
|
||||
bool r = epee::file_io_utils::save_string_to_file(path_to_generate + "/" + filename, ss.str());
|
||||
if (!r)
|
||||
{
|
||||
LOG_ERROR("Failed to save file " << filename);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -284,7 +284,7 @@ namespace tools
|
|||
response.m_response_comment = "Internal Server Error";
|
||||
return true;
|
||||
}
|
||||
if (!handle_http_request_map(query_info, response, m_conn_context, call_found, reference_stub) && response.m_response_code == 200)
|
||||
if (!handle_http_request_map(query_info, response, m_conn_context, call_found) && response.m_response_code == 200)
|
||||
{
|
||||
response.m_response_code = 500;
|
||||
response.m_response_comment = "Internal Server Error";
|
||||
|
|
|
|||
|
|
@ -117,22 +117,22 @@ namespace tools
|
|||
MAP_JON_RPC_WE("get_mining_history", on_get_mining_history, wallet_public::COMMAND_RPC_GET_MINING_HISTORY)
|
||||
MAP_JON_RPC_WE("register_alias", on_register_alias, wallet_public::COMMAND_RPC_REGISTER_ALIAS)
|
||||
//contracts API
|
||||
MAP_JON_RPC_WE("contracts_send_proposal", on_contracts_send_proposal, wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL)
|
||||
MAP_JON_RPC_WE("contracts_accept_proposal", on_contracts_accept_proposal, wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL)
|
||||
MAP_JON_RPC_WE("contracts_get_all", on_contracts_get_all, wallet_public::COMMAND_CONTRACTS_GET_ALL)
|
||||
MAP_JON_RPC_WE("contracts_release", on_contracts_release, wallet_public::COMMAND_CONTRACTS_RELEASE)
|
||||
MAP_JON_RPC_WE("contracts_request_cancel", on_contracts_request_cancel, wallet_public::COMMAND_CONTRACTS_REQUEST_CANCEL)
|
||||
MAP_JON_RPC_WE("contracts_accept_cancel", on_contracts_accept_cancel, wallet_public::COMMAND_CONTRACTS_ACCEPT_CANCEL)
|
||||
//MAP_JON_RPC_WE("contracts_send_proposal", on_contracts_send_proposal, wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL)
|
||||
//MAP_JON_RPC_WE("contracts_accept_proposal", on_contracts_accept_proposal, wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL)
|
||||
//MAP_JON_RPC_WE("contracts_get_all", on_contracts_get_all, wallet_public::COMMAND_CONTRACTS_GET_ALL)
|
||||
//MAP_JON_RPC_WE("contracts_release", on_contracts_release, wallet_public::COMMAND_CONTRACTS_RELEASE)
|
||||
//MAP_JON_RPC_WE("contracts_request_cancel", on_contracts_request_cancel, wallet_public::COMMAND_CONTRACTS_REQUEST_CANCEL)
|
||||
//MAP_JON_RPC_WE("contracts_accept_cancel", on_contracts_accept_cancel, wallet_public::COMMAND_CONTRACTS_ACCEPT_CANCEL)
|
||||
//marketplace API
|
||||
MAP_JON_RPC_WE("marketplace_get_offers_ex", on_marketplace_get_my_offers, wallet_public::COMMAND_MARKETPLACE_GET_MY_OFFERS)
|
||||
MAP_JON_RPC_WE("marketplace_push_offer", on_marketplace_push_offer, wallet_public::COMMAND_MARKETPLACE_PUSH_OFFER)
|
||||
MAP_JON_RPC_WE("marketplace_push_update_offer", on_marketplace_push_update_offer, wallet_public::COMMAND_MARKETPLACE_PUSH_UPDATE_OFFER)
|
||||
MAP_JON_RPC_WE("marketplace_cancel_offer", on_marketplace_cancel_offer, wallet_public::COMMAND_MARKETPLACE_CANCEL_OFFER)
|
||||
//HTLC API
|
||||
MAP_JON_RPC_WE("atomics_create_htlc_proposal", on_create_htlc_proposal, wallet_public::COMMAND_CREATE_HTLC_PROPOSAL)
|
||||
MAP_JON_RPC_WE("atomics_get_list_of_active_htlc", on_get_list_of_active_htlc, wallet_public::COMMAND_GET_LIST_OF_ACTIVE_HTLC)
|
||||
MAP_JON_RPC_WE("atomics_redeem_htlc", on_redeem_htlc, wallet_public::COMMAND_REDEEM_HTLC)
|
||||
MAP_JON_RPC_WE("atomics_check_htlc_redeemed", on_check_htlc_redeemed, wallet_public::COMMAND_CHECK_HTLC_REDEEMED)
|
||||
//MAP_JON_RPC_WE("atomics_create_htlc_proposal", on_create_htlc_proposal, wallet_public::COMMAND_CREATE_HTLC_PROPOSAL)
|
||||
//MAP_JON_RPC_WE("atomics_get_list_of_active_htlc", on_get_list_of_active_htlc, wallet_public::COMMAND_GET_LIST_OF_ACTIVE_HTLC)
|
||||
//MAP_JON_RPC_WE("atomics_redeem_htlc", on_redeem_htlc, wallet_public::COMMAND_REDEEM_HTLC)
|
||||
//MAP_JON_RPC_WE("atomics_check_htlc_redeemed", on_check_htlc_redeemed, wallet_public::COMMAND_CHECK_HTLC_REDEEMED)
|
||||
|
||||
//IONIC_SWAPS API
|
||||
MAP_JON_RPC_WE("ionic_swap_generate_proposal", on_ionic_swap_generate_proposal, wallet_public::COMMAND_IONIC_SWAP_GENERATE_PROPOSAL)
|
||||
|
|
@ -145,16 +145,16 @@ namespace tools
|
|||
MAP_JON_RPC_WE("assets_whitelist_remove", on_assets_whitelist_remove, wallet_public::COMMAND_ASSETS_WHITELIST_REMOVE)
|
||||
|
||||
//MULTIWALLET APIs
|
||||
MAP_JON_RPC_WE("mw_get_wallets", on_mw_get_wallets, wallet_public::COMMAND_MW_GET_WALLETS)
|
||||
MAP_JON_RPC_WE("mw_select_wallet", on_mw_select_wallet, wallet_public::COMMAND_MW_SELECT_WALLET)
|
||||
MAP_JON_RPC_WE("mw_get_wallets", on_mw_get_wallets, wallet_public::COMMAND_MW_GET_WALLETS)
|
||||
MAP_JON_RPC_WE("mw_select_wallet", on_mw_select_wallet, wallet_public::COMMAND_MW_SELECT_WALLET)
|
||||
|
||||
//basic crypto operations
|
||||
MAP_JON_RPC_WE("sign_message", on_sign_message, wallet_public::COMMAND_SIGN_MESSAGE)
|
||||
MAP_JON_RPC_WE("encrypt_data", on_encrypt_data, wallet_public::COMMAND_ENCRYPT_DATA)
|
||||
MAP_JON_RPC_WE("decrypt_data", on_decrypt_data, wallet_public::COMMAND_DECRYPT_DATA)
|
||||
MAP_JON_RPC_WE("sign_message", on_sign_message, wallet_public::COMMAND_SIGN_MESSAGE)
|
||||
MAP_JON_RPC_WE("encrypt_data", on_encrypt_data, wallet_public::COMMAND_ENCRYPT_DATA)
|
||||
MAP_JON_RPC_WE("decrypt_data", on_decrypt_data, wallet_public::COMMAND_DECRYPT_DATA)
|
||||
|
||||
//utility call
|
||||
MAP_JON_RPC_WE("proxy_to_daemon", on_proxy_to_daemon, wallet_public::COMMAND_PROXY_TO_DAEMON)
|
||||
MAP_JON_RPC_WE("proxy_to_daemon", on_proxy_to_daemon, wallet_public::COMMAND_PROXY_TO_DAEMON)
|
||||
END_JSON_RPC_MAP()
|
||||
END_URI_MAP2()
|
||||
|
||||
|
|
|
|||
|
|
@ -1663,11 +1663,10 @@ std::string wallets_manager::invoke(uint64_t wallet_id, std::string params)
|
|||
epee::net_utils::http::http_request_info query_info = AUTO_VAL_INIT(query_info);
|
||||
epee::net_utils::http::http_response_info response_info = AUTO_VAL_INIT(response_info);
|
||||
epee::net_utils::connection_context_base stub_conn_context = AUTO_VAL_INIT(stub_conn_context);
|
||||
std::string reference_stub;
|
||||
bool call_found = false;
|
||||
query_info.m_URI = "/json_rpc";
|
||||
query_info.m_body = params;
|
||||
wo.rpc_wrapper->handle_http_request_map(query_info, response_info, stub_conn_context, call_found, reference_stub);
|
||||
wo.rpc_wrapper->handle_http_request_map(query_info, response_info, stub_conn_context, call_found);
|
||||
return response_info.m_body;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue