Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
net_api_plugin.cpp
Go to the documentation of this file.
4
5#include <fc/variant.hpp>
6#include <fc/io/json.hpp>
7
8#include <chrono>
9
10namespace sysio { namespace detail {
12}}
13
15
16namespace sysio {
17
18static appbase::abstract_plugin& _net_api_plugin = app().register_plugin<net_api_plugin>();
19
20using namespace sysio;
21
22#define CALL_WITH_400(api_name, api_handle, call_name, INVOKE, http_response_code) \
23{std::string("/v1/" #api_name "/" #call_name), \
24 [&api_handle](string, string body, url_response_callback cb) mutable { \
25 try { \
26 INVOKE \
27 cb(http_response_code, fc::variant(result)); \
28 } catch (...) { \
29 http_plugin::handle_exception(#api_name, #call_name, body, cb); \
30 } \
31 }}
32
33#define INVOKE_R_R(api_handle, call_name, in_param) \
34 auto params = parse_params<in_param, http_params_types::params_required>(body);\
35 fc::variant result( api_handle.call_name( std::move(params) ) );
36
37#define INVOKE_R_V(api_handle, call_name) \
38 body = parse_params<std::string, http_params_types::no_params>(body); \
39 auto result = api_handle.call_name();
40
41#define INVOKE_V_R(api_handle, call_name, in_param) \
42 auto params = parse_params<in_param, http_params_types::params_required>(body);\
43 api_handle.call_name( std::move(params) ); \
44 sysio::detail::net_api_plugin_empty result;
45
46#define INVOKE_V_V(api_handle, call_name) \
47 body = parse_params<std::string, http_params_types::no_params_required>(body); \
48 api_handle.call_name(); \
49 sysio::detail::net_api_plugin_empty result;
50
51
53 ilog("starting net_api_plugin");
54 // lifetime of plugin is lifetime of application
55 auto& net_mgr = app().get_plugin<net_plugin>();
56 app().get_plugin<http_plugin>().add_api({
57 // CALL(net, net_mgr, set_timeout,
58 // INVOKE_V_R(net_mgr, set_timeout, int64_t), 200),
59 // CALL(net, net_mgr, sign_transaction,
60 // INVOKE_R_R_R_R(net_mgr, sign_transaction, chain::signed_transaction, flat_set<public_key_type>, chain::chain_id_type), 201),
61 CALL_WITH_400(net, net_mgr, connect,
62 INVOKE_R_R(net_mgr, connect, std::string), 201),
63 CALL_WITH_400(net, net_mgr, disconnect,
64 INVOKE_R_R(net_mgr, disconnect, std::string), 201),
65 CALL_WITH_400(net, net_mgr, status,
66 INVOKE_R_R(net_mgr, status, std::string), 201),
67 CALL_WITH_400(net, net_mgr, connections,
68 INVOKE_R_V(net_mgr, connections), 201),
69 // CALL(net, net_mgr, open,
70 // INVOKE_V_R(net_mgr, open, std::string), 200),
72}
73
74void net_api_plugin::plugin_initialize(const variables_map& options) {
75 try {
76 const auto& _http_plugin = app().get_plugin<http_plugin>();
77 if( !_http_plugin.is_on_loopback()) {
78 wlog( "\n"
79 "**********SECURITY WARNING**********\n"
80 "* *\n"
81 "* -- Net API -- *\n"
82 "* - EXPOSED to the LOCAL NETWORK - *\n"
83 "* - USE ONLY ON SECURE NETWORKS! - *\n"
84 "* *\n"
85 "************************************\n" );
86 }
88}
89
90
91#undef INVOKE_R_R
92#undef INVOKE_R_V
93#undef INVOKE_V_R
94#undef INVOKE_V_V
95#undef CALL
96
97}
#define CALL_WITH_400(api_name, api_handle, api_namespace, call_name, http_response_code, params_type)
abstract_plugin & get_plugin(const string &name) const
void plugin_initialize(const variables_map &vm)
#define INVOKE_R_V(api_handle, call_name)
#define FC_LOG_AND_RETHROW()
#define wlog(FORMAT,...)
Definition logger.hpp:124
#define ilog(FORMAT,...)
Definition logger.hpp:118
application & app()
#define INVOKE_R_R(api_handle, call_name, in_param)
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition reflect.hpp:311
static constexpr int medium_high