4namespace fc {
namespace rpc {
16 FC_ASSERT( args.size() == 3 && args[2].is_array() );
18 if( args[0].is_string() )
21 subargs.push_back( args[0] );
26 api_id = args[0].as_uint64();
31 args[2].get_array() );
36 FC_ASSERT( args.size() == 2 && args[1].is_array() );
39 args[1].get_array() );
45 FC_ASSERT( args.size() == 2 && args[1].is_array() );
48 args[1].get_array() );
86 std::string resp_body;
87 http::reply::status_code resp_status;
89 auto handle_error = [&](
const auto& e)
91 resp_status = http::reply::InternalServerError;
93 wdump((e.to_detail_string()));
98 resp.add_header(
"Content-Type",
"application/json" );
99 std::string req_body( req.body.begin(), req.body.end() );
101 const auto& var_obj = var.get_object();
103 if( var_obj.contains(
"method" ) )
105 auto call = var.
as<fc::rpc::request>();
106 auto handle_error_inner = [&](
const auto& e)
108 resp_body =
fc::json::to_string( fc::rpc::response( *
call.id, error_object{ 1, e.to_detail_string(), fc::variant(e)} ) );
109 resp_status = http::reply::InternalServerError;}
116 resp_status = http::reply::OK;
118 catch (
const std::bad_alloc& )
122 catch (
const boost::interprocess::bad_alloc& )
128 handle_error_inner(e);
130 catch (
const std::exception& e )
137 resp_status = http::reply::BadRequest;
141 catch (
const std::bad_alloc& )
145 catch (
const boost::interprocess::bad_alloc& )
153 catch (
const std::exception& e )
160 resp.set_status( resp_status );
161 resp.set_length( resp_body.length() );
162 resp.write( resp_body.c_str(), resp_body.length() );
164 catch (
const std::bad_alloc& )
168 catch (
const boost::interprocess::bad_alloc& )
176 catch (
const std::exception& e )
variant receive_callback(uint64_t callback_id, const variants &args=variants()) const
void receive_notice(uint64_t callback_id, const variants &args=variants()) const
variant receive_call(api_id_type api_id, const string &method_name, const variants &args=variants()) const
Used to generate a useful error report when an exception is thrown.
std::string to_detail_string(log_level ll=log_level::all) const
static string to_string(const variant &v, const yield_function_t &yield, const output_formatting format=output_formatting::stringify_large_ints_and_doubles)
static variant from_string(const string &utf8_str, const parse_type ptype=parse_type::legacy_parser, uint32_t max_depth=DEFAULT_MAX_RECURSION_DEPTH)
virtual variant send_callback(uint64_t callback_id, variants args=variants()) override
void on_request(const fc::http::request &req, const fc::http::server::response &resp)
virtual variant send_call(api_id_type api_id, string method_name, variants args=variants()) override
fc::rpc::state _rpc_state
virtual void send_notice(uint64_t callback_id, variants args=variants()) override
static std_exception_wrapper from_current_exception(const std::exception &e)
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
uint64_t as_uint64() const
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
std::vector< fc::variant > variants
fc::variant call(const std::string &url, const std::string &path, const T &v)
unsigned __int64 uint64_t