21chain_api_plugin::chain_api_plugin(){}
39 SYS_THROW(chain::invalid_http_request,
"A Request body is required");
47 SYS_THROW(chain::invalid_http_request,
"Invalid transaction id");
51#define CALL_WITH_400(api_name, api_handle, api_namespace, call_name, http_response_code, params_type) \
52{std::string("/v1/" #api_name "/" #call_name), \
53 [api_handle](string, string body, url_response_callback cb) mutable { \
54 api_handle.validate(); \
56 auto params = parse_params<api_namespace::call_name ## _params, params_type>(body);\
57 fc::variant result( api_handle.call_name( std::move(params) ) ); \
58 cb(http_response_code, std::move(result)); \
60 http_plugin::handle_exception(#api_name, #call_name, body, cb); \
64#define CALL_ASYNC_WITH_400(api_name, api_handle, api_namespace, call_name, call_result, http_response_code, params_type) \
65{std::string("/v1/" #api_name "/" #call_name), \
66 [api_handle](string, string body, url_response_callback cb) mutable { \
67 api_handle.validate(); \
69 auto params = parse_params<api_namespace::call_name ## _params, params_type>(body);\
70 api_handle.call_name( std::move(params),\
71 [cb, body](const std::variant<fc::exception_ptr, call_result>& result){\
72 if (std::holds_alternative<fc::exception_ptr>(result)) {\
74 std::get<fc::exception_ptr>(result)->dynamic_rethrow_exception();\
76 http_plugin::handle_exception(#api_name, #call_name, body, cb);\
79 cb(http_response_code, std::visit(async_result_visitor(), result));\
83 http_plugin::handle_exception(#api_name, #call_name, body, cb); \
88#define CHAIN_RO_CALL(call_name, http_response_code, params_type) CALL_WITH_400(chain, ro_api, chain_apis::read_only, call_name, http_response_code, params_type)
89#define CHAIN_RW_CALL(call_name, http_response_code, params_type) CALL_WITH_400(chain, rw_api, chain_apis::read_write, call_name, http_response_code, params_type)
90#define CHAIN_RO_CALL_ASYNC(call_name, call_result, http_response_code, params_type) CALL_ASYNC_WITH_400(chain, ro_api, chain_apis::read_only, call_name, call_result, http_response_code, params_type)
91#define CHAIN_RW_CALL_ASYNC(call_name, call_result, http_response_code, params_type) CALL_ASYNC_WITH_400(chain, rw_api, chain_apis::read_write, call_name, call_result, http_response_code, params_type)
93#define CHAIN_RO_CALL_WITH_400(call_name, http_response_code, params_type) CALL_WITH_400(chain, ro_api, chain_apis::read_only, call_name, http_response_code, params_type)
96 ilog(
"starting chain_api_plugin" );
100 auto rw_api = chain.get_read_write_api();
103 ro_api.set_shorten_abi_errors( !_http_plugin.verbose_errors() );
105 _http_plugin.add_api( {
107 _http_plugin.add_api({
137 if (chain.account_queries_enabled()) {
138 _http_plugin.add_async_api({
143 if (chain.transaction_finality_status_enabled()) {
144 _http_plugin.add_async_api({
#define SYS_THROW(exc_type, FORMAT,...)
#define CHAIN_RO_CALL_ASYNC(call_name, call_result, http_response_code, params_type)
#define CHAIN_RW_CALL_ASYNC(call_name, call_result, http_response_code, params_type)
#define CHAIN_RO_CALL_WITH_400(call_name, http_response_code, params_type)
#define CHAIN_RO_CALL(call_name, http_response_code, params_type)
abstract_plugin & get_plugin(const string &name) const
static variant from_string(const string &utf8_str, const parse_type ptype=parse_type::legacy_parser, uint32_t max_depth=DEFAULT_MAX_RECURSION_DEPTH)
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
chain_api_plugin_impl(controller &db)
virtual ~chain_api_plugin()
virtual void set_program_options(options_description &, options_description &) override
void plugin_initialize(const variables_map &)
chain_apis::read_only get_read_only_api() const
chain_apis::read_only::get_transaction_status_params parse_params< chain_apis::read_only::get_transaction_status_params, http_params_types::params_required >(const std::string &body)
#define T(meth, val, expected)
void get_account(const string &accountName, const string &coresym, bool json_format)
sysio::chain_apis::read_only::get_info_results get_info()
void send_transaction(signed_transaction &trx, packed_transaction::compression_type compression=packed_transaction::compression_type::none)
fc::variant push_transaction(signed_transaction &trx, packed_transaction::compression_type compression=packed_transaction::compression_type::none)
static constexpr int medium_high
fc::variant operator()(const T &v) const