Wire Sysio
Wire Sysion 1.0.0
Loading...
Searching...
No Matches
net_api_plugin.cpp
Go to the documentation of this file.
1
#include <
sysio/net_api_plugin/net_api_plugin.hpp
>
2
#include <
sysio/chain/exceptions.hpp
>
3
#include <
sysio/chain/transaction.hpp
>
4
5
#include <
fc/variant.hpp
>
6
#include <
fc/io/json.hpp
>
7
8
#include <chrono>
9
10
namespace
sysio
{
namespace
detail
{
11
struct
net_api_plugin_empty
{};
12
}}
13
14
FC_REFLECT
(
sysio::detail::net_api_plugin_empty
, );
15
16
namespace
sysio
{
17
18
static
appbase::abstract_plugin
& _net_api_plugin =
app
().
register_plugin
<net_api_plugin>();
19
20
using 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
52
void
net_api_plugin::plugin_startup
() {
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),
71
},
appbase::priority::medium_high
);
72
}
73
74
void
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
}
87
}
FC_LOG_AND_RETHROW
()
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
}
exceptions.hpp
CALL_WITH_400
#define CALL_WITH_400(api_name, api_handle, api_namespace, call_name, http_response_code, params_type)
Definition
chain_api_plugin.cpp:51
appbase::abstract_plugin
Definition
plugin.hpp:28
appbase::application::get_plugin
abstract_plugin & get_plugin(const string &name) const
Definition
application.cpp:520
appbase::application::register_plugin
auto & register_plugin()
Definition
application.hpp:136
sysio::http_plugin
Definition
http_plugin.hpp:65
sysio::net_api_plugin::plugin_initialize
void plugin_initialize(const variables_map &vm)
Definition
net_api_plugin.cpp:74
sysio::net_api_plugin::plugin_startup
void plugin_startup()
Definition
net_api_plugin.cpp:52
sysio::net_plugin
Definition
net_plugin.hpp:17
INVOKE_R_V
#define INVOKE_R_V(api_handle, call_name)
Definition
db_size_api_plugin.cpp:24
FC_LOG_AND_RETHROW
#define FC_LOG_AND_RETHROW()
Definition
exception.hpp:411
variant.hpp
json.hpp
wlog
#define wlog(FORMAT,...)
Definition
logger.hpp:124
ilog
#define ilog(FORMAT,...)
Definition
logger.hpp:118
appbase::app
application & app()
Definition
application.cpp:210
detail
Definition
main.cpp:23
sysio
Definition
abi_serializer.cpp:8
INVOKE_R_R
#define INVOKE_R_R(api_handle, call_name, in_param)
Definition
net_api_plugin.cpp:33
net_api_plugin.hpp
FC_REFLECT
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition
reflect.hpp:311
appbase::priority::medium_high
static constexpr int medium_high
Definition
execution_priority_queue.hpp:14
sysio::detail::net_api_plugin_empty
Definition
net_api_plugin.cpp:11
transaction.hpp
plugins
net_api_plugin
net_api_plugin.cpp
Generated by
1.12.0